// $Id: ckeditor.utils.js,v 1.1.2.14 2010/07/05 14:11:52 wwalc Exp $ Drupal.ckeditor = (typeof(CKEDITOR) != 'undefined'); // this object will store teaser information Drupal.ckeditorTeaser = { lookup: {}, lookupSetup: false, cache: {} }; Drupal.ckeditorToggle = function(textarea_id, TextTextarea, TextRTE, xss_check){ if (!CKEDITOR.env.isCompatible) { return; } if (typeof(CKEDITOR.instances) != 'undefined' && typeof(CKEDITOR.instances[textarea_id]) != 'undefined') { Drupal.ckeditorOff(textarea_id); $('#switch_' + textarea_id).text(TextRTE); } else { Drupal.ckeditorOn(textarea_id); $('#switch_' + textarea_id).text(TextTextarea); } }; /** * CKEditor starting function * * @param string textarea_id */ Drupal.ckeditorOn = function(textarea_id) { if ((typeof(Drupal.settings.ckeditor.load_timeout) == 'undefined') && (typeof(CKEDITOR.instances[textarea_id]) != 'undefined')) { return; } if (typeof(Drupal.settings.ckeditor.settings[textarea_id]) == 'undefined') { return; } if (!CKEDITOR.env.isCompatible) { return; } if (teaser = Drupal.ckeditorTeaserInfo(textarea_id)) { var ch_checked = teaser.checkbox.attr('checked'); var tv = teaser.textarea.val(); if (!teaser.textarea.attr("disabled")) { $("#" + textarea_id).val(tv + '\n\n' + $("#" + textarea_id).val()); teaser.textarea.val(''); } // [#653498] if (teaser.button.attr('value') != Drupal.t('Split summary at cursor')) { try { teaser.button.click(); } catch (e) { teaser.button.val(Drupal.t('Split summary at cursor')); } } teaser.buttonContainer.hide(); teaser.textareaContainer.hide(); teaser.checkboxContainer.show(); teaser.checkbox.attr('checked', ch_checked); } if (($("#" + textarea_id).val().length > 0) && ($("#" + textarea_id).attr('class').indexOf("filterxss1") != -1 || $("#" + textarea_id).attr('class').indexOf("filterxss2") != -1)) { $.post(Drupal.settings.basePath + 'index.php?q=ckeditor/xss', { text: $('#' + textarea_id).val(), 'filters[]': Drupal.settings.ckeditor.settings[textarea_id].filters }, function(text){ $("#" + textarea_id).val(text); }); } $("#" + textarea_id).next(".grippie").css("display", "none"); $("#" + textarea_id).addClass("ckeditor-processed"); Drupal.settings.ckeditor.settings[textarea_id]['on'] = { configLoaded : function(ev) { ev.editor.addCss(ev.editor.config.extraCss); }, instanceReady : function(ev) { var body = $(ev.editor.document.$.body); if (typeof(Drupal.settings.ckeditor.settings[textarea_id].custom_formatting) != 'undefined') { var dtd = CKEDITOR.dtd; for ( var e in CKEDITOR.tools.extend( {}, dtd.$block, dtd.$listItem, dtd.$tableContent ) ) { ev.editor.dataProcessor.writer.setRules( e, Drupal.settings.ckeditor.settings[textarea_id].custom_formatting); } ev.editor.dataProcessor.writer.setRules( 'pre', { indent: Drupal.settings.ckeditor.settings[textarea_id].output_pre_indent }); } if (ev.editor.config.bodyClass) body.addClass(ev.editor.config.bodyClass); if (ev.editor.config.bodyId) body.attr('id', ev.editor.config.bodyId); if (typeof(Drupal.smileysAttach) != 'undefined') ev.editor.dataProcessor.writer.indentationChars = ' '; }, focus : function(ev) { Drupal.ckeditorInstance = ev.editor; } }; Drupal.ckeditorInstance = CKEDITOR.replace(textarea_id, Drupal.settings.ckeditor.settings[textarea_id]); }; /** * CKEditor destroy function * * @param string textarea_id */ Drupal.ckeditorOff = function(textarea_id) { if (typeof(CKEDITOR.instances[textarea_id]) == 'undefined') { return; } if (!CKEDITOR.env.isCompatible) { return; } if (Drupal.ckeditorInstance && Drupal.ckeditorInstance.name == textarea_id) delete Drupal.ckeditorInstance; var data = CKEDITOR.instances[textarea_id].getData(); CKEDITOR.instances[textarea_id].destroy(); if (teaser = Drupal.ckeditorTeaserInfo(textarea_id)) { var brcode = //; data = data.split(brcode); if (data.length > 1) { teaser.textareaContainer.show(); teaser.textarea.attr('disabled', ''); if (teaser.button.attr('value') != Drupal.t('Join summary')) { try { teaser.button.click(); } catch (e) { teaser.button.val(Drupal.t('Join summary')); } } teaser.textarea.val(data[0]); $("#" + textarea_id).val(data[1]); } else { $("#" + textarea_id).val(data[0]); teaser.textarea.attr('disabled', 'disabled'); teaser.checkboxContainer.hide(); if (teaser.button.attr('value') != Drupal.t('Split summary at cursor')) { try { teaser.button.click(); } catch (e) { teaser.button.val(Drupal.t('Split summary at cursor')); } } } teaser.buttonContainer.show(); } $("#" + textarea_id).next(".grippie").css("display", "block"); $("#" + textarea_id).removeClass("ckeditor-processed"); }; /** * CKEditor popup mode function */ function ckeditorOpenPopup(jsID, textareaID, width){ popupUrl = Drupal.settings.ckeditor.module_path + '/includes/ckeditor.popup.html?var=' + jsID + '&el=' + textareaID; var percentPos = width.indexOf('%'); if (percentPos != -1) { width = width.substr(0, percentPos); width = width / 100 * screen.width; } window.open(popupUrl, null, 'width=' + width + ',toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=1,dependent=yes'); return false; }; /** * 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]