// https://civicrm.org/licensing
(function($, _) {
+
function getInstance(item) {
var name = $(item).attr("name"),
id = $(item).attr("id");
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');
});
editor.on('insertText', function() {
$(item).trigger("keypress");
});
- var debounce = null;
_.each(['key', 'pasteState'], function(evName) {
editor.on(evName, function(evt) {
if (debounce) clearTimeout(debounce);
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) {
return $(item).val();
}
};
+
CRM.wysiwyg.setVal = function(item, val) {
var editor = getInstance(item);
if (editor) {
return $(item).val(val);
}
};
+
CRM.wysiwyg.insert = function(item, text) {
var editor = getInstance(item);
if (editor) {
CRM.wysiwyg._insertIntoTextarea(item, text);
}
};
+
CRM.wysiwyg.focus = function(item) {
var editor = getInstance(item);
if (editor) {