CRM-16354 add base wyswyig interface
authorTyrell Cook <tyrell@aghstrategies.com>
Sun, 26 Apr 2015 20:28:43 +0000 (16:28 -0400)
committerTyrell Cook <tyrell@aghstrategies.com>
Sun, 26 Apr 2015 20:28:43 +0000 (16:28 -0400)
CRM/Core/Resources.php
js/Common.js
js/wysiwyg/crm.ckeditor.js
js/wysiwyg/crm.textarea.js [deleted file]
js/wysiwyg/crm.wysiwyg.js [new file with mode: 0644]
templates/CRM/common/l10n.js.tpl
templates/CRM/common/wysiwyg.tpl

index 513207b44c4cb9e9854ff39f17902a3c1f54bcf2..7af9603017b565b626c326e9d278aeab5316d7f9 100644 (file)
@@ -715,13 +715,14 @@ class CRM_Core_Resources {
       "js/Common.js",
       "js/crm.ajax.js",
     );
+    // add wysiwyg editor
     $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";
+    $items[] = "js/wysiwyg/crm.wysiwyg.js";
     if ($editor == "CKEditor") {
       $items[] = "bower_components/ckeditor/ckeditor.js";
       $items[] = "js/wysiwyg/crm.ckeditor.js";
index c78354463390a185a940ab2d315c918ac28caba8..a8595fee49a919a0800c9ac03e71130575321e2c 100644 (file)
@@ -833,7 +833,11 @@ CRM.strings = CRM.strings || {};
         $(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);
+        if ($(this).hasClass("collapsed")) {
+          CRM.wysiwyg.createPlain(this);
+        } else {
+          CRM.wysiwyg.create(this);
+        }
       })
     })
     .on('dialogopen', function(e) {
index 11b7dcc9aa109bcf796e8863096e565192cde9b3..f7f86ad431a9b1bf521b45627aaf25e5dc544eb0 100644 (file)
@@ -5,40 +5,54 @@
     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.wysiwyg['supportsFileUploads'] =  true;
+  CRM.wysiwyg.create =  function(item) {
+    //var browseUrl = CRM.config.userFrameworkResourceUrl + "packages/kcfinder/browse.php";
+    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';
+      editor.on('blur', function(){
+        $(item).trigger("blur");
+      });
+    }
+  };
+  CRM.wysiwyg.destroy = function(item) {
+    var editor = getInstance(item);
+    if (editor) {
+      editor.destroy();
+    }
+  };
+  CRM.wysiwyg.updateElement = function(item) {
+    var editor = getInstance(item);
+    if (editor) {
+      editor.updateElement();
+    }
+  };
+  CRM.wysiwyg.val = function(item) {
+    var editor = getInstance(item);
+    if (editor) {
+      return editor.getData();
+    } else {
+      return $(item).val();
+    }
+  };
+  CRM.wysiwyg.insertText = function(item, text) {
+    var editor = getInstance(item);
+    if (editor) {
+      editor.insertText(text);
+    }
+  };
+  CRM.wysiwyg.insertHTML = function(item, html) {
+    var editor = getInstance(item);
+    if (editor) {
+      editor.insertText(html);
+    }
   };
 })(CRM.$, CRM._);
diff --git a/js/wysiwyg/crm.textarea.js b/js/wysiwyg/crm.textarea.js
deleted file mode 100644 (file)
index ac84b84..0000000
+++ /dev/null
@@ -1,12 +0,0 @@
-// https://civicrm.org/licensing
-(function($, _) {
-  CRM.wysiwyg = {
-    supportsFileUploads: false,
-    create: _.noop,
-    destroy: _.noop,
-    updateElement: _.noop,
-    val: function(item) {
-      return $(item).val();
-    },
-  };
-})(CRM.$, CRM._);
diff --git a/js/wysiwyg/crm.wysiwyg.js b/js/wysiwyg/crm.wysiwyg.js
new file mode 100644 (file)
index 0000000..b729e44
--- /dev/null
@@ -0,0 +1,34 @@
+// https://civicrm.org/licensing
+(function($, _) {
+  function openWysiwyg(item) {
+    $(item).show();
+    $(item).next('.replace-plain').hide();
+    CRM.wysiwyg.create(item);
+    $(item).on( 'blur', function( e ) {
+      CRM.wysiwyg.updateElement(item);
+      CRM.wysiwyg.destroy(item);
+      $(item).hide().next('.replace-plain').show().html($(item).val());
+    });
+  };
+  CRM.wysiwyg = {};
+  CRM.wysiwyg['supportsFileUploads'] =  false;
+  CRM.wysiwyg.create = _.noop;
+  CRM.wysiwyg.destroy = _.noop;
+  CRM.wysiwyg.updateElement = _.noop;
+  CRM.wysiwyg.val = function(item) {
+    return $(item).val();
+  };
+  CRM.wysiwyg.insertText = _.noop;
+  CRM.wysiwyg.insertHTML = _.noop;
+  CRM.wysiwyg.createPlain = function(item) {
+    $(item)
+      .hide()
+      .after('<div class="replace-plain" tabindex="0" title="Click to edit"></div>');
+    $(item).next('.replace-plain').click(function(){
+      openWysiwyg(item);
+    });
+    $(item).next('.replace-plain').keypress(function(){
+      openWysiwyg(item);
+    });
+  };
+})(CRM.$, CRM._);
index c024019123ac4b3655d28ef6c1c9ac4be9f422a3..2e94e58227ba259041994e9593106a74cec4981a 100644 (file)
@@ -33,7 +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};
+  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 ec43a22f0a78ad90b557f7c41fed02210735f597..51d32368f714fe01c5401c83a14f240bd56721b7 100644 (file)
@@ -26,8 +26,6 @@
 
 {* include wysiysg editor files *}
 {if $includeWysiwygEditor}
-
-
     {if $defaultWysiwygEditor eq 1}
         <script>
           {* this version of tinymce requires jquery *}
@@ -35,7 +33,5 @@
         </script>
         <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}
-
     {/if}
 {/if}