/* Copyright (c) 2003-2011, CKSource - Frederico Knabben. All rights reserved. For licensing, see LICENSE.html or http://ckeditor.com/license */ if (typeof window.CKEDITOR_BASEPATH === 'undefined') { window.CKEDITOR_BASEPATH = Drupal.settings.ckeditor.editor_path; } (function ($) { Drupal.ckeditor = (typeof(CKEDITOR) != 'undefined'); Drupal.ckeditor_ver = false; Drupal.ckeditorToggle = function(textarea_ids, TextTextarea, TextRTE){ if (!CKEDITOR.env.isCompatible) { return; } for (i=0; i 0) && typeof(ckeditor_obj.input_formats[ckeditor_obj.elements[textarea_id]]) != 'undefined' && ((ckeditor_obj.input_formats[ckeditor_obj.elements[textarea_id]]['ss'] == 1 && typeof(Drupal.settings.ckeditor.autostart) != 'undefined' && typeof(Drupal.settings.ckeditor.autostart[textarea_id]) != 'undefined') || ckeditor_obj.input_formats[ckeditor_obj.elements[textarea_id]]['ss'] == 2)) { $.ajax({ type: 'POST', url: Drupal.settings.ckeditor.xss_url, async: false, data: { text: $('#' + textarea_id).val(), input_format: ckeditor_obj.textarea_default_format[textarea_id], token: Drupal.settings.ckeditor.ajaxToken }, success: function(text){ $("#" + textarea_id).val(text); Drupal.ckeditorInit(textarea_id); } }) } else { Drupal.ckeditorInit(textarea_id); } }; /** * CKEditor destroy function * * @param string textarea_id */ Drupal.ckeditorOff = function(textarea_id) { if (!CKEDITOR.instances || typeof(CKEDITOR.instances[textarea_id]) == 'undefined') { return; } if (!CKEDITOR.env.isCompatible) { return; } if (Drupal.ckeditorInstance && Drupal.ckeditorInstance.name == textarea_id) delete Drupal.ckeditorInstance; $("#" + textarea_id).val(CKEDITOR.instances[textarea_id].getData()); CKEDITOR.instances[textarea_id].destroy(true); $("#" + textarea_id).next(".grippie").css("display", "block"); }; /** * Loading selected CKEditor plugins * * @param object textarea_settings */ Drupal.ckeditorLoadPlugins = function(textarea_settings) { if (typeof(textarea_settings.extraPlugins) == 'undefined') { textarea_settings.extraPlugins = ''; } if (typeof CKEDITOR.plugins != 'undefined') { for (var plugin in textarea_settings['loadPlugins']) { textarea_settings.extraPlugins += (textarea_settings.extraPlugins) ? ',' + textarea_settings['loadPlugins'][plugin]['name'] : textarea_settings['loadPlugins'][plugin]['name']; CKEDITOR.plugins.addExternal(textarea_settings['loadPlugins'][plugin]['name'], textarea_settings['loadPlugins'][plugin]['path']); } } return textarea_settings; }; /** * Returns true if CKEDITOR.version >= version */ Drupal.ckeditorCompareVersion = function (version){ var ckver = CKEDITOR.version; ckver = ckver.match(/(([\d]\.)+[\d]+)/i); version = version.match(/((\d+\.)+[\d]+)/i); ckver = ckver[0].split('.'); version = version[0].split('.'); for (var x in ckver) { if (ckver[x]version[x]) { return true; } } return true; }; Drupal.ckeditorInsertHtml = function(html) { if (!Drupal.ckeditorInstance) return false; if (Drupal.ckeditorInstance.mode == 'wysiwyg') { Drupal.ckeditorInstance.insertHtml(html); return true; } else { alert(Drupal.t('Content can only be inserted into CKEditor in the WYSIWYG mode.')); return false; } }; /** * Ajax support */ if (typeof(Drupal.Ajax) != 'undefined' && typeof(Drupal.Ajax.plugins) != 'undefined') { Drupal.Ajax.plugins.CKEditor = function(hook, args) { if (hook === 'submit' && typeof(CKEDITOR.instances) != 'undefined') { for (var i in CKEDITOR.instances) CKEDITOR.instances[i].updateElement(); } return true; }; } //Support for Panels [#679976] Drupal.ckeditorSubmitAjaxForm = function () { if (typeof(CKEDITOR.instances) != 'undefined' && typeof(CKEDITOR.instances['edit-body']) != 'undefined') { Drupal.ckeditorOff('edit-body'); } }; function attachCKEditor(context) { // make sure the textarea behavior is run first, to get a correctly sized grippie if (Drupal.behaviors.textarea && Drupal.behaviors.textarea.attach) { Drupal.behaviors.textarea.attach(context); } $(context).find("textarea.ckeditor-mod:not(.ckeditor-processed)").each(function () { var ta_id=$(this).attr("id"); if (CKEDITOR.instances && typeof(CKEDITOR.instances[ta_id]) != 'undefined'){ Drupal.ckeditorOff(ta_id); } if ((typeof(Drupal.settings.ckeditor.autostart) != 'undefined') && (typeof(Drupal.settings.ckeditor.autostart[ta_id]) != 'undefined')) { Drupal.ckeditorOn(ta_id); } if (typeof(Drupal.settings.ckeditor.input_formats[Drupal.settings.ckeditor.elements[ta_id]]) != 'undefined') { $('.ckeditor_links').show(); } var sel_format = $("#" + ta_id.substr(0, ta_id.lastIndexOf("-")) + "-format--2"); if (sel_format && sel_format.not('.ckeditor-processed')) { sel_format.addClass('ckeditor-processed').change(function() { Drupal.settings.ckeditor.elements[ta_id] = $(this).val(); if (CKEDITOR.instances && typeof(CKEDITOR.instances[ta_id]) != 'undefined') { $('#'+ta_id).val(CKEDITOR.instances[ta_id].getData()); } Drupal.ckeditorOff(ta_id); if (typeof(Drupal.settings.ckeditor.input_formats[$(this).val()]) != 'undefined'){ if ($('#'+ta_id).hasClass('ckeditor-processed')) { Drupal.ckeditorOn(ta_id, false); } else { Drupal.ckeditorOn(ta_id); } $('#switch_'+ta_id).show(); } else { $('#switch_'+ta_id).hide(); } }); } }); } /** * Drupal behaviors */ Drupal.behaviors.ckeditor = { attach: function (context) { // If CKEDITOR is undefined and script is loaded from CDN, wait up to 15 seconds until it loads [#2244817] if ((typeof(CKEDITOR) == 'undefined') && Drupal.settings.ckeditor.editor_path.match(/^(http(s)?:)?\/\//i)) { if (typeof(Drupal.settings.ckeditor.loadAttempts) == 'undefined') { Drupal.settings.ckeditor.loadAttempts = 50; } if (Drupal.settings.ckeditor.loadAttempts > 0) { Drupal.settings.ckeditor.loadAttempts--; window.setTimeout(function() { Drupal.behaviors.ckeditor.attach(context); }, 300); } return; } if ((typeof(CKEDITOR) == 'undefined') || !CKEDITOR.env.isCompatible) { return; } attachCKEditor(context); }, detach: function(context, settings, trigger){ $(context).find("textarea.ckeditor-mod.ckeditor-processed").each(function () { var ta_id=$(this).attr("id"); if (CKEDITOR.instances[ta_id]) $('#'+ta_id).val(CKEDITOR.instances[ta_id].getData()); if(trigger != 'serialize') { Drupal.ckeditorOff(ta_id); $(this).removeClass('ckeditor-processed'); } }); } }; // Support CTools detach event. $(document).bind('CToolsDetachBehaviors', function(event, context) { Drupal.behaviors.ckeditor.detach(context, {}, 'unload'); }); })(jQuery); /** * IMCE support */ var ckeditor_imceSendTo = function (file, win){ var cfunc = win.location.href.split('&'); for (var x in cfunc) { if (cfunc[x].match(/^CKEditorFuncNum=\d+$/)) { cfunc = cfunc[x].split('='); break; } } CKEDITOR.tools.callFunction(cfunc[1], file.url); win.close(); }