math.php 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. <?php
  2. namespace Plugins\Math;
  3. use \Typemill\Plugin;
  4. class Math extends Plugin
  5. {
  6. protected $settings;
  7. public static function getSubscribedEvents()
  8. {
  9. return array(
  10. 'onSettingsLoaded' => 'onSettingsLoaded',
  11. 'onTwigLoaded' => 'onTwigLoaded'
  12. );
  13. }
  14. public function onSettingsLoaded($settings)
  15. {
  16. $this->settings = $settings->getData();
  17. }
  18. public function onTwigLoaded()
  19. {
  20. $mathSettings = $this->settings['settings']['plugins']['math'];
  21. if($mathSettings['tool'] == 'mathjax')
  22. {
  23. /* add external CSS and JavaScript */
  24. $this->addJS('https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.4/latest.js?config=TeX-MML-AM_CHTML');
  25. }
  26. if($mathSettings['tool'] == 'katex')
  27. {
  28. $this->addJS('/math/public/katex.min.js');
  29. $this->addJS('/math/public/auto-render.min.js');
  30. $this->addCSS('/math/public/katex.min.css');
  31. /* initialize autorendering of page only in frontend */
  32. if (strpos($this->getPath(), 'tm/content') === false)
  33. {
  34. $this->addInlineJs('renderMathInElement(document.body);');
  35. }
  36. }
  37. # add math to the blox editor configuration
  38. $this->addEditorJS('/math/public/math.js');
  39. $this->addSvgSymbol('<symbol id="icon-omega" viewBox="0 0 32 32">
  40. <title>omega</title>
  41. <path d="M22 28h8l2-4v8h-12v-6.694c4.097-1.765 7-6.161 7-11.306 0-6.701-4.925-11.946-11-11.946s-11 5.245-11 11.946c0 5.144 2.903 9.541 7 11.306v6.694h-12v-8l2 4h8v-1.018c-5.863-2.077-10-7.106-10-12.982 0-7.732 7.163-14 16-14s16 6.268 16 14c0 5.875-4.137 10.905-10 12.982v1.018z"></path>
  42. </symbol>');
  43. }
  44. }