CRM-16354 update ckeditor
authorTyrell Cook <tyrell@aghstrategies.com>
Sat, 25 Apr 2015 23:37:37 +0000 (19:37 -0400)
committerTyrell Cook <tyrell@aghstrategies.com>
Sat, 25 Apr 2015 23:37:37 +0000 (19:37 -0400)
CRM/Core/Form.php
CRM/Core/Resources.php
js/Common.js
js/wysiwyg/crm.ckeditor.js [new file with mode: 0644]
js/wysiwyg/crm.textarea.js [new file with mode: 0644]
templates/CRM/common/l10n.js.tpl
templates/CRM/common/wysiwyg.tpl

index a5d2550283d3a18fcb79fbeead44ea23a8a4d5c7..01a7029658d7086442ced5af5852805416421538 100644 (file)
@@ -271,6 +271,14 @@ class CRM_Core_Form extends HTML_QuickForm_Page {
     $type, $name, $label = '',
     $attributes = '', $required = FALSE, $extra = NULL
   ) {
+    if ($type == 'wysiwyg') {
+      if ($attributes === '') {
+        $attributes = array();
+      }
+      $attributes = ((array) $attributes) + array('class' => '');
+      $attributes['class'] .= ' crm-wysiwyg';
+      $type = "textarea";
+    }
     if ($type == 'select' && is_array($extra)) {
       // Normalize this property
       if (!empty($extra['multiple'])) {
index a7f2d3561c4530beea623346601d0156176ef00f..513207b44c4cb9e9854ff39f17902a3c1f54bcf2 100644 (file)
@@ -715,6 +715,17 @@ class CRM_Core_Resources {
       "js/Common.js",
       "js/crm.ajax.js",
     );
+    $editorID = CRM_Core_BAO_Setting::getItem(CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME,
+      'editor_id'
+    );
+    $editor = CRM_Utils_Array::value($editorID,
+      CRM_Core_OptionGroup::values('wysiwyg_editor')
+    );
+    $items[] = "js/wysiwyg/crm.textarea.js";
+    if ($editor == "CKEditor") {
+      $items[] = "bower_components/ckeditor/ckeditor.js";
+      $items[] = "js/wysiwyg/crm.ckeditor.js";
+    }
 
     // These scripts are only needed by back-office users
     if (CRM_Core_Permission::check('access CiviCRM')) {
index 8d96d7d7164f393a2fc4b9e2b753719960b165c4..c78354463390a185a940ab2d315c918ac28caba8 100644 (file)
@@ -832,6 +832,9 @@ CRM.strings = CRM.strings || {};
       $('form[data-warn-changes] :input', e.target).each(function() {
         $(this).data('crm-initial-value', $(this).is(':checkbox, :radio') ? $(this).prop('checked') : $(this).val());
       });
+      $('textarea.crm-wysiwyg', e.target).each(function() {
+        CRM.wysiwyg.create(this);
+      })
     })
     .on('dialogopen', function(e) {
       var $el = $(e.target);
diff --git a/js/wysiwyg/crm.ckeditor.js b/js/wysiwyg/crm.ckeditor.js
new file mode 100644 (file)
index 0000000..11b7dcc
--- /dev/null
@@ -0,0 +1,44 @@
+// https://civicrm.org/licensing
+(function($, _) {
+  function getInstance(item) {
+    var name = $(item).attr("name");
+    return CKEDITOR.instances[name];
+  }
+
+  CRM.wysiwyg = {
+    supportsFileUploads: true,
+    create: function(item) {
+      var browseUrl = CRM.config.userFrameworkResourceUrl + "packages/kcfinder/browse.php";
+      var uploadUrl = CRM.config.userFrameworkResourceUrl + "packages/kcfinder/upload.php";
+      var editor = CKEDITOR.replace($(item)[0]);
+      if (editor) {
+        editor.config.filebrowserBrowseUrl = browseUrl+'?cms=civicrm&type=files';
+        editor.config.filebrowserImageBrowseUrl = browseUrl+'?cms=civicrm&type=images';
+        editor.config.filebrowserFlashBrowseUrl = browseUrl+'?cms=civicrm&type=flash';
+        editor.config.filebrowserUploadUrl = uploadUrl+'?cms=civicrm&type=files';
+        editor.config.filebrowserImageUploadUrl = uploadUrl+'?cms=civicrm&type=images';
+        editor.config.filebrowserFlashUploadUrl = uploadUrl+'?cms=civicrm&type=flash';
+      }
+    },
+    destroy: function(item) {
+      var editor = getInstance(item);
+      if (editor) {
+        editor.destroy();
+      }
+    },
+    updateElement: function(item) {
+      var editor = getInstance(item);
+      if (editor) {
+        editor.updateElement();
+      }
+    },
+    val: function(item) {
+      var editor = getInstance(item);
+      if (editor) {
+        return editor.getData();
+      } else {
+        return $(item).val();
+      }
+    },
+  };
+})(CRM.$, CRM._);
diff --git a/js/wysiwyg/crm.textarea.js b/js/wysiwyg/crm.textarea.js
new file mode 100644 (file)
index 0000000..ac84b84
--- /dev/null
@@ -0,0 +1,12 @@
+// https://civicrm.org/licensing
+(function($, _) {
+  CRM.wysiwyg = {
+    supportsFileUploads: false,
+    create: _.noop,
+    destroy: _.noop,
+    updateElement: _.noop,
+    val: function(item) {
+      return $(item).val();
+    },
+  };
+})(CRM.$, CRM._);
index c239bc79e562b1d5e98d15371df9029b1ba0ad53..c024019123ac4b3655d28ef6c1c9ac4be9f422a3 100644 (file)
@@ -33,6 +33,7 @@
   $.datepicker._defaults.dateFormat = CRM.config.dateInputFormat = {$config->dateInputFormat|@json_encode};
   CRM.config.timeIs24Hr = {if $config->timeInputFormat eq 2}true{else}false{/if};
   CRM.config.ajaxPopupsEnabled = {$ajaxPopupsEnabled|@json_encode};
+  CRM.config.userFrameworkResourceUrl = {$config->userFrameworkResourceUrl|@json_encode};
 
   // Merge entityRef settings
   CRM.config.entityRef = $.extend({ldelim}{rdelim}, {$entityRef|@json_encode}, CRM.config.entityRef || {ldelim}{rdelim});
index 50189b6c9aaa28c5bd1b924a4e1a98c22b470b3a..ec43a22f0a78ad90b557f7c41fed02210735f597 100644 (file)
@@ -26,6 +26,8 @@
 
 {* include wysiysg editor files *}
 {if $includeWysiwygEditor}
+
+
     {if $defaultWysiwygEditor eq 1}
         <script>
           {* this version of tinymce requires jquery *}
@@ -34,6 +36,6 @@
         <script type="text/javascript" src="{$config->resourceBase}packages/tinymce/jscripts/tiny_mce/jquery.tinymce.js"></script>
         <script type="text/javascript" src="{$config->resourceBase}packages/tinymce/jscripts/tiny_mce/tiny_mce.js"></script>
     {elseif $defaultWysiwygEditor eq 2}
-        <script type="text/javascript" src="{$config->resourceBase}bower_components/ckeditor/ckeditor.js"></script>
+
     {/if}
 {/if}