Commit | Line | Data |
---|---|---|
b608cfb1 TC |
1 | // https://civicrm.org/licensing |
2 | (function($, _) { | |
3 | function getInstance(item) { | |
f91b1c0c CW |
4 | var name = $(item).attr("name"), |
5 | id = $(item).attr("id"); | |
c62731c3 TC |
6 | if (name && CKEDITOR.instances[name]) { |
7 | return CKEDITOR.instances[name]; | |
8 | } | |
9 | if (id && CKEDITOR.instances[id]) { | |
10 | return CKEDITOR.instances[id]; | |
11 | } | |
b608cfb1 | 12 | } |
c90cd6ed | 13 | CRM.wysiwyg.supportsFileUploads = true; |
f91b1c0c CW |
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) { | |
7266e09b CW |
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 | }); | |
f91b1c0c | 28 | } |
7c523661 | 29 | if (editor) { |
13d9bc82 CW |
30 | editor.on('focus', function() { |
31 | $(item).trigger('focus'); | |
32 | }); | |
c62731c3 TC |
33 | editor.on('blur', function() { |
34 | editor.updateElement(); | |
7c523661 | 35 | $(item).trigger("blur"); |
f91b1c0c | 36 | $(item).trigger("change"); |
7c523661 | 37 | }); |
c62731c3 TC |
38 | editor.on('insertText', function() { |
39 | $(item).trigger("keypress"); | |
40 | }); | |
6633d03f | 41 | var debounce = null; |
e4d81a60 | 42 | _.each(['key', 'pasteState'], function(evName) { |
6633d03f TO |
43 | editor.on(evName, function(evt) { |
44 | if (debounce) clearTimeout(debounce); | |
45 | debounce = setTimeout(function() { | |
46 | editor.updateElement(); | |
47 | $(item).trigger("change"); | |
48 | }, 50); | |
49 | }); | |
50 | }); | |
c62731c3 TC |
51 | editor.on('pasteState', function() { |
52 | $(item).trigger("paste"); | |
53 | }); | |
9cc08ac2 CW |
54 | // Hide CiviCRM menubar when editor is fullscreen |
55 | editor.on('maximize', function (e) { | |
56 | $('#civicrm-menu').toggle(e.data === 2); | |
57 | }); | |
7c523661 TC |
58 | } |
59 | }; | |
60 | CRM.wysiwyg.destroy = function(item) { | |
61 | var editor = getInstance(item); | |
62 | if (editor) { | |
63 | editor.destroy(); | |
64 | } | |
65 | }; | |
66 | CRM.wysiwyg.updateElement = function(item) { | |
67 | var editor = getInstance(item); | |
68 | if (editor) { | |
69 | editor.updateElement(); | |
70 | } | |
71 | }; | |
c62731c3 | 72 | CRM.wysiwyg.getVal = function(item) { |
7c523661 TC |
73 | var editor = getInstance(item); |
74 | if (editor) { | |
75 | return editor.getData(); | |
76 | } else { | |
77 | return $(item).val(); | |
78 | } | |
79 | }; | |
c62731c3 TC |
80 | CRM.wysiwyg.setVal = function(item, val) { |
81 | var editor = getInstance(item); | |
82 | if (editor) { | |
83 | return editor.setData(val); | |
84 | } else { | |
85 | return $(item).val(val); | |
86 | } | |
87 | }; | |
88 | CRM.wysiwyg.insert = function(item, text) { | |
7c523661 TC |
89 | var editor = getInstance(item); |
90 | if (editor) { | |
91 | editor.insertText(text); | |
c62731c3 | 92 | } else { |
f91b1c0c | 93 | CRM.wysiwyg._insertIntoTextarea(item, text); |
7c523661 TC |
94 | } |
95 | }; | |
c62731c3 | 96 | CRM.wysiwyg.focus = function(item) { |
7c523661 TC |
97 | var editor = getInstance(item); |
98 | if (editor) { | |
c62731c3 | 99 | editor.focus(); |
f91b1c0c CW |
100 | } else { |
101 | $(item).focus(); | |
7c523661 | 102 | } |
b608cfb1 | 103 | }; |
c62731c3 | 104 | |
b608cfb1 | 105 | })(CRM.$, CRM._); |