From: Coleman Watts Date: Sun, 18 Oct 2015 19:25:51 +0000 (-0400) Subject: crm.ckeditor.js code cleanup X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=183473a2d19a739738b63edf2e193ba3df7f8eba;p=civicrm-core.git crm.ckeditor.js code cleanup --- diff --git a/js/wysiwyg/crm.ckeditor.js b/js/wysiwyg/crm.ckeditor.js index 6d6c333763..ff0126693d 100644 --- a/js/wysiwyg/crm.ckeditor.js +++ b/js/wysiwyg/crm.ckeditor.js @@ -1,5 +1,6 @@ // https://civicrm.org/licensing (function($, _) { + function getInstance(item) { var name = $(item).attr("name"), id = $(item).attr("id"); @@ -10,29 +11,16 @@ return CKEDITOR.instances[id]; } } + CRM.wysiwyg.supportsFileUploads = true; + CRM.wysiwyg.create = function(item) { - var editor, - deferred = $.Deferred(), - browseUrl = CRM.config.userFrameworkResourceURL + "packages/kcfinder/browse.php?cms=civicrm", - uploadUrl = CRM.config.userFrameworkResourceURL + "packages/kcfinder/upload.php?cms=civicrm"; - if ($(item).length) { - editor = CKEDITOR.replace($(item)[0], { - filebrowserBrowseUrl: browseUrl + '&type=files', - filebrowserImageBrowseUrl: browseUrl + '&type=images', - filebrowserFlashBrowseUrl: browseUrl + '&type=flash', - filebrowserUploadUrl: uploadUrl + '&type=files', - filebrowserImageUploadUrl: uploadUrl + '&type=images', - filebrowserFlashUploadUrl: uploadUrl + '&type=flash', - customConfig: CRM.config.CKEditorCustomConfig, - on: { - instanceReady: function() { - deferred.resolve(); - } - } - }); - } - if (editor) { + var deferred = $.Deferred(); + + function onReady() { + var debounce, + editor = this; + editor.on('focus', function() { $(item).trigger('focus'); }); @@ -44,7 +32,6 @@ editor.on('insertText', function() { $(item).trigger("keypress"); }); - var debounce = null; _.each(['key', 'pasteState'], function(evName) { editor.on(evName, function(evt) { if (debounce) clearTimeout(debounce); @@ -61,23 +48,50 @@ editor.on('maximize', function (e) { $('#civicrm-menu').toggle(e.data === 2); }); + deferred.resolve(); + } + + function initialize() { + var + browseUrl = CRM.config.userFrameworkResourceURL + "packages/kcfinder/browse.php?cms=civicrm", + uploadUrl = CRM.config.userFrameworkResourceURL + "packages/kcfinder/upload.php?cms=civicrm"; + + CKEDITOR.replace($(item)[0], { + filebrowserBrowseUrl: browseUrl + '&type=files', + filebrowserImageBrowseUrl: browseUrl + '&type=images', + filebrowserFlashBrowseUrl: browseUrl + '&type=flash', + filebrowserUploadUrl: uploadUrl + '&type=files', + filebrowserImageUploadUrl: uploadUrl + '&type=images', + filebrowserFlashUploadUrl: uploadUrl + '&type=flash', + customConfig: CRM.config.CKEditorCustomConfig, + on: { + instanceReady: onReady + } + }); + } + + if ($(item).length) { + initialize(); } else { deferred.reject(); } return deferred; }; + 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.getVal = function(item) { var editor = getInstance(item); if (editor) { @@ -86,6 +100,7 @@ return $(item).val(); } }; + CRM.wysiwyg.setVal = function(item, val) { var editor = getInstance(item); if (editor) { @@ -94,6 +109,7 @@ return $(item).val(val); } }; + CRM.wysiwyg.insert = function(item, text) { var editor = getInstance(item); if (editor) { @@ -102,6 +118,7 @@ CRM.wysiwyg._insertIntoTextarea(item, text); } }; + CRM.wysiwyg.focus = function(item) { var editor = getInstance(item); if (editor) {