Wysiwyg.php 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. <?php
  2. /**
  3. *
  4. * PHP Pro Bid $Id$ PQlOVT8VN+GJbUzl3YYn3qhpJ9/oJ9MUAf2Q2yGTnqk=
  5. *
  6. * @link http://www.phpprobid.com
  7. * @copyright Copyright (c) 2017 Online Ventures Software & CodeCube SRL
  8. * @license http://www.phpprobid.com/license Commercial License
  9. *
  10. * @version 7.10 [rev.7.10.01]
  11. */
  12. /**
  13. * wysiwyg custom element
  14. *
  15. * uses redactor
  16. */
  17. namespace Ppb\Form\Element;
  18. use Cube\Form\Element\Textarea,
  19. Cube\Controller\Front;
  20. class Wysiwyg extends Textarea
  21. {
  22. const ELEMENT_CLASS = 'wysiwyg';
  23. /**
  24. *
  25. * type of element - override the variable from the parent class
  26. *
  27. * @var string
  28. */
  29. protected $_element = 'wysiwyg';
  30. /**
  31. *
  32. * class constructor
  33. *
  34. * @param string $name
  35. */
  36. public function __construct($name)
  37. {
  38. parent::__construct($name);
  39. $baseUrl = Front::getInstance()->getRequest()->getBaseUrl();
  40. $this->setHeaderCode('<link href="' . $baseUrl . '/js/redactor/redactor.custom.css" media="screen" rel="stylesheet" type="text/css">')
  41. ->setBodyCode('<script type="text/javascript" src="' . $baseUrl . '/js/redactor/redactor.min.js"></script>');
  42. $this->setBodyCode(
  43. "<script type=\"text/javascript\">" . "\n"
  44. . " $('." . self::ELEMENT_CLASS . "').redactor({ " . "\n"
  45. . " convertDivs: false, " . "\n"
  46. . " minHeight: 200 " . "\n"
  47. . " }); " . "\n"
  48. . "</script>");
  49. $this->addAttribute('class', self::ELEMENT_CLASS);
  50. }
  51. }