1 // https://civicrm.org/licensing
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
];
9 if (id
&& CKEDITOR
.instances
[id
]) {
10 return CKEDITOR
.instances
[id
];
13 CRM
.wysiwyg
.supportsFileUploads
= true;
14 CRM
.wysiwyg
.create = function(item
) {
16 browseUrl
= CRM
.config
.userFrameworkResourceURL
+ "packages/kcfinder/browse.php?cms=civicrm",
17 uploadUrl
= CRM
.config
.userFrameworkResourceURL
+ "packages/kcfinder/upload.php?cms=civicrm";
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
30 editor
.on('focus', function() {
31 $(item
).trigger('focus');
33 editor
.on('blur', function() {
34 editor
.updateElement();
35 $(item
).trigger("blur");
36 $(item
).trigger("change");
38 editor
.on('insertText', function() {
39 $(item
).trigger("keypress");
41 editor
.on('pasteState', function() {
42 $(item
).trigger("paste");
44 // Hide CiviCRM menubar when editor is fullscreen
45 editor
.on('maximize', function (e
) {
46 $('#civicrm-menu').toggle(e
.data
=== 2);
50 CRM
.wysiwyg
.destroy = function(item
) {
51 var editor
= getInstance(item
);
56 CRM
.wysiwyg
.updateElement = function(item
) {
57 var editor
= getInstance(item
);
59 editor
.updateElement();
62 CRM
.wysiwyg
.getVal = function(item
) {
63 var editor
= getInstance(item
);
65 return editor
.getData();
70 CRM
.wysiwyg
.setVal = function(item
, val
) {
71 var editor
= getInstance(item
);
73 return editor
.setData(val
);
75 return $(item
).val(val
);
78 CRM
.wysiwyg
.insert = function(item
, text
) {
79 var editor
= getInstance(item
);
81 editor
.insertText(text
);
83 CRM
.wysiwyg
._insertIntoTextarea(item
, text
);
86 CRM
.wysiwyg
.focus = function(item
) {
87 var editor
= getInstance(item
);