| 1 | // https://civicrm.org/licensing |
| 2 | (function($, _) { |
| 3 | function getInstance(item) { |
| 4 | var name = $(item).attr("name"), |
| 5 | id = $(item).attr("id"); |
| 6 | if (name && CKEDITOR.instances[name]) { |
| 7 | return CKEDITOR.instances[name]; |
| 8 | } |
| 9 | if (id && CKEDITOR.instances[id]) { |
| 10 | return CKEDITOR.instances[id]; |
| 11 | } |
| 12 | } |
| 13 | CRM.wysiwyg.supportsFileUploads = true; |
| 14 | CRM.wysiwyg.create = function(item) { |
| 15 | var editor, |
| 16 | browseUrl = CRM.config.userFrameworkResourceURL + "packages/kcfinder/browse.php?cms=civicrm", |
| 17 | uploadUrl = CRM.config.userFrameworkResourceURL + "packages/kcfinder/upload.php?cms=civicrm"; |
| 18 | if ($(item).length) { |
| 19 | editor = CKEDITOR.replace($(item)[0], { |
| 20 | filebrowserBrowseUrl: browseUrl + '&type=files', |
| 21 | filebrowserImageBrowseUrl: browseUrl + '&type=images', |
| 22 | filebrowserFlashBrowseUrl: browseUrl + '&type=flash', |
| 23 | filebrowserUploadUrl: uploadUrl + '&type=files', |
| 24 | filebrowserImageUploadUrl: uploadUrl + '&type=images', |
| 25 | filebrowserFlashUploadUrl: uploadUrl + '&type=flash', |
| 26 | customConfig: CRM.config.CKEditorCustomConfig |
| 27 | }); |
| 28 | } |
| 29 | if (editor) { |
| 30 | editor.on('focus', function() { |
| 31 | $(item).trigger('focus'); |
| 32 | }); |
| 33 | editor.on('blur', function() { |
| 34 | editor.updateElement(); |
| 35 | $(item).trigger("blur"); |
| 36 | $(item).trigger("change"); |
| 37 | }); |
| 38 | editor.on('insertText', function() { |
| 39 | $(item).trigger("keypress"); |
| 40 | }); |
| 41 | editor.on('pasteState', function() { |
| 42 | $(item).trigger("paste"); |
| 43 | }); |
| 44 | // Hide CiviCRM menubar when editor is fullscreen |
| 45 | editor.on('maximize', function (e) { |
| 46 | $('#civicrm-menu').toggle(e.data === 2); |
| 47 | }); |
| 48 | } |
| 49 | }; |
| 50 | CRM.wysiwyg.destroy = function(item) { |
| 51 | var editor = getInstance(item); |
| 52 | if (editor) { |
| 53 | editor.destroy(); |
| 54 | } |
| 55 | }; |
| 56 | CRM.wysiwyg.updateElement = function(item) { |
| 57 | var editor = getInstance(item); |
| 58 | if (editor) { |
| 59 | editor.updateElement(); |
| 60 | } |
| 61 | }; |
| 62 | CRM.wysiwyg.getVal = function(item) { |
| 63 | var editor = getInstance(item); |
| 64 | if (editor) { |
| 65 | return editor.getData(); |
| 66 | } else { |
| 67 | return $(item).val(); |
| 68 | } |
| 69 | }; |
| 70 | CRM.wysiwyg.setVal = function(item, val) { |
| 71 | var editor = getInstance(item); |
| 72 | if (editor) { |
| 73 | return editor.setData(val); |
| 74 | } else { |
| 75 | return $(item).val(val); |
| 76 | } |
| 77 | }; |
| 78 | CRM.wysiwyg.insert = function(item, text) { |
| 79 | var editor = getInstance(item); |
| 80 | if (editor) { |
| 81 | editor.insertText(text); |
| 82 | } else { |
| 83 | CRM.wysiwyg._insertIntoTextarea(item, text); |
| 84 | } |
| 85 | }; |
| 86 | CRM.wysiwyg.focus = function(item) { |
| 87 | var editor = getInstance(item); |
| 88 | if (editor) { |
| 89 | editor.focus(); |
| 90 | } else { |
| 91 | $(item).focus(); |
| 92 | } |
| 93 | }; |
| 94 | |
| 95 | })(CRM.$, CRM._); |