CRM-16354 - Remove old wysiwyg code
[civicrm-core.git] / js / wysiwyg / crm.ckeditor.js
CommitLineData
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) {
19 editor = CKEDITOR.replace($(item)[0]);
20 }
7c523661 21 if (editor) {
f91b1c0c
CW
22 editor.config.filebrowserBrowseUrl = browseUrl + '&type=files';
23 editor.config.filebrowserImageBrowseUrl = browseUrl + '&type=images';
24 editor.config.filebrowserFlashBrowseUrl = browseUrl + '&type=flash';
25 editor.config.filebrowserUploadUrl = uploadUrl + '&type=files';
26 editor.config.filebrowserImageUploadUrl = uploadUrl + '&type=images';
27 editor.config.filebrowserFlashUploadUrl = uploadUrl + '&type=flash';
13d9bc82
CW
28 editor.on('focus', function() {
29 $(item).trigger('focus');
30 });
c62731c3
TC
31 editor.on('blur', function() {
32 editor.updateElement();
7c523661 33 $(item).trigger("blur");
f91b1c0c 34 $(item).trigger("change");
7c523661 35 });
c62731c3
TC
36 editor.on('insertText', function() {
37 $(item).trigger("keypress");
38 });
39 editor.on('pasteState', function() {
40 $(item).trigger("paste");
41 });
7c523661
TC
42 }
43 };
44 CRM.wysiwyg.destroy = function(item) {
45 var editor = getInstance(item);
46 if (editor) {
47 editor.destroy();
48 }
49 };
50 CRM.wysiwyg.updateElement = function(item) {
51 var editor = getInstance(item);
52 if (editor) {
53 editor.updateElement();
54 }
55 };
c62731c3 56 CRM.wysiwyg.getVal = function(item) {
7c523661
TC
57 var editor = getInstance(item);
58 if (editor) {
59 return editor.getData();
60 } else {
61 return $(item).val();
62 }
63 };
c62731c3
TC
64 CRM.wysiwyg.setVal = function(item, val) {
65 var editor = getInstance(item);
66 if (editor) {
67 return editor.setData(val);
68 } else {
69 return $(item).val(val);
70 }
71 };
72 CRM.wysiwyg.insert = function(item, text) {
7c523661
TC
73 var editor = getInstance(item);
74 if (editor) {
75 editor.insertText(text);
c62731c3 76 } else {
f91b1c0c 77 CRM.wysiwyg._insertIntoTextarea(item, text);
7c523661
TC
78 }
79 };
c62731c3 80 CRM.wysiwyg.focus = function(item) {
7c523661
TC
81 var editor = getInstance(item);
82 if (editor) {
c62731c3 83 editor.focus();
f91b1c0c
CW
84 } else {
85 $(item).focus();
7c523661 86 }
b608cfb1 87 };
c62731c3 88
b608cfb1 89})(CRM.$, CRM._);