BxBaseEditorCLEditor.php 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. <?php defined('BX_DOL') or die('hack attempt');
  2. /**
  3. * Copyright (c) BoonEx Pty Limited - http://www.boonex.com/
  4. * CC-BY License - http://creativecommons.org/licenses/by/3.0/
  5. *
  6. * @defgroup DolphinCore Dolphin Core
  7. * @{
  8. */
  9. bx_import('BxDolEditor');
  10. /**
  11. * CLEditor editor representation.
  12. * @see BxDolEditor
  13. */
  14. class BxBaseEditorCLEditor extends BxDolEditor {
  15. /**
  16. * Common initialization params
  17. */
  18. protected static $CONF_COMMON = "
  19. jQuery('{bx_var_selector}').cleditor({
  20. {bx_var_custom_init}
  21. docCSSFile: '{bx_var_css_path}',
  22. bodyStyle: 'cursor:text',
  23. width: '100%'
  24. });
  25. ";
  26. /**
  27. * Standard view initialization params
  28. */
  29. protected static $CONF_STANDARD = "
  30. height: 250,
  31. controls: 'bold italic underline removeformat | style | bullets numbering | outdent indent | alignleft center alignright | undo redo | rule image link unlink | pastetext | source',
  32. ";
  33. /**
  34. * Minimal view initialization params
  35. */
  36. protected static $CONF_MINI = "
  37. height: 150,
  38. controls: 'bold italic underline removeformat | bullets numbering | alignleft center alignright | link unlink image',
  39. ";
  40. /**
  41. * Full view initialization params
  42. */
  43. protected static $CONF_FULL = "
  44. height: 300,
  45. controls: 'bold italic underline removeformat | subscript superscript | style | bullets numbering | outdent indent | alignleft center alignright justify | undo redo | rule image link unlink | pastetext | print source',
  46. ";
  47. protected $_oTemplate;
  48. protected $_bJsCssAdded = false;
  49. public function __construct ($aObject, $oTemplate) {
  50. parent::__construct ($aObject);
  51. if ($oTemplate)
  52. $this->_oTemplate = $oTemplate;
  53. else
  54. $this->_oTemplate = BxDolTemplate::getInstance();
  55. }
  56. /**
  57. * Attach editor to HTML element, in most cases - textarea.
  58. * @param $sSelector - jQuery selector to attach editor to.
  59. * @param $iViewMode - editor view mode: BX_EDITOR_STANDARD, BX_EDITOR_MINI, BX_EDITOR_FULL
  60. * @param $bDynamicMode - is AJAX mode or not, the HTML with editor area is loaded synamically.
  61. */
  62. public function attachEditor ($sSelector, $iViewMode = BX_EDITOR_STANDARD, $bDynamicMode = false) {
  63. // set visual mode
  64. switch ($iViewMode) {
  65. case BX_EDITOR_MINI:
  66. $sToolsItems = self::$CONF_MINI;
  67. break;
  68. case BX_EDITOR_FULL:
  69. $sToolsItems = self::$CONF_FULL;
  70. break;
  71. case BX_EDITOR_STANDARD:
  72. default:
  73. $sToolsItems = self::$CONF_STANDARD;
  74. }
  75. // initialize editor
  76. $sInitEditor = $this->_replaceMarkers(self::$CONF_COMMON, array(
  77. 'bx_var_custom_init' => $sToolsItems,
  78. 'bx_var_selector' => bx_js_string($sSelector, BX_ESCAPE_STR_APOS),
  79. 'bx_var_css_path' => bx_js_string($this->_oTemplate->getCssUrl('editor.css'), BX_ESCAPE_STR_APOS),
  80. ));
  81. if ($bDynamicMode) {
  82. $sScript = $this->_oTemplate->addCss(BX_DOL_URL_PLUGINS . 'cleditor/jquery.cleditor.css', true);
  83. $sScript .= "<script>
  84. if ('undefined' == typeof(jQuery(document).cleditor)) {
  85. $.getScript('" . bx_js_string(BX_DOL_URL_PLUGINS . 'cleditor/jquery.cleditor.min.js', BX_ESCAPE_STR_APOS) . "', function(data, textStatus, jqxhr) {
  86. $sInitEditor
  87. });
  88. } else {
  89. setTimeout(function () {
  90. $sInitEditor
  91. }, 100);
  92. }
  93. </script>";
  94. } else {
  95. $sScript = "<script>
  96. $(document).ready(function () {
  97. $sInitEditor
  98. });
  99. </script>";
  100. }
  101. return $this->_addJsCss($bDynamicMode) . $sScript;
  102. }
  103. /**
  104. * Add css/js files which are needed for editor display and functionality.
  105. */
  106. protected function _addJsCss($bDynamicMode = false, $sInitEditor = '') {
  107. if ($bDynamicMode)
  108. return '';
  109. if ($this->_bJsCssAdded)
  110. return '';
  111. $this->_oTemplate->addCss(BX_DOL_URL_PLUGINS . 'cleditor/jquery.cleditor.css');
  112. $this->_oTemplate->addJs(BX_DOL_URL_PLUGINS . 'cleditor/jquery.cleditor.min.js');
  113. $this->_bJsCssAdded = true;
  114. return '';
  115. }
  116. }
  117. /** @} */