| [ Index ] |
PHP Cross Reference of Drupal 6 (gatewave) |
[Summary view] [Print] [Text view]
1 // $Id: ckeditor.utils.js,v 1.1.2.14 2010/07/05 14:11:52 wwalc Exp $ 2 Drupal.ckeditor = (typeof(CKEDITOR) != 'undefined'); 3 4 // this object will store teaser information 5 Drupal.ckeditorTeaser = { 6 lookup: {}, 7 lookupSetup: false, 8 cache: {} 9 }; 10 11 Drupal.ckeditorToggle = function(textarea_id, TextTextarea, TextRTE, xss_check){ 12 if (!CKEDITOR.env.isCompatible) { 13 return; 14 } 15 if (typeof(CKEDITOR.instances) != 'undefined' && typeof(CKEDITOR.instances[textarea_id]) != 'undefined') { 16 Drupal.ckeditorOff(textarea_id); 17 $('#switch_' + textarea_id).text(TextRTE); 18 } 19 else { 20 Drupal.ckeditorOn(textarea_id); 21 $('#switch_' + textarea_id).text(TextTextarea); 22 } 23 }; 24 25 /** 26 * CKEditor starting function 27 * 28 * @param string textarea_id 29 */ 30 Drupal.ckeditorOn = function(textarea_id) { 31 if ((typeof(Drupal.settings.ckeditor.load_timeout) == 'undefined') && (typeof(CKEDITOR.instances[textarea_id]) != 'undefined')) { 32 return; 33 } 34 if (typeof(Drupal.settings.ckeditor.settings[textarea_id]) == 'undefined') { 35 return; 36 } 37 if (!CKEDITOR.env.isCompatible) { 38 return; 39 } 40 41 if (teaser = Drupal.ckeditorTeaserInfo(textarea_id)) { 42 var ch_checked = teaser.checkbox.attr('checked'); 43 var tv = teaser.textarea.val(); 44 if (!teaser.textarea.attr("disabled")) { 45 $("#" + textarea_id).val(tv + '\n<!--break-->\n' + $("#" + textarea_id).val()); 46 teaser.textarea.val(''); 47 } 48 49 // [#653498] 50 if (teaser.button.attr('value') != Drupal.t('Split summary at cursor')) { 51 try { 52 teaser.button.click(); 53 } 54 catch (e) { 55 teaser.button.val(Drupal.t('Split summary at cursor')); 56 } 57 } 58 59 teaser.buttonContainer.hide(); 60 teaser.textareaContainer.hide(); 61 teaser.checkboxContainer.show(); 62 teaser.checkbox.attr('checked', ch_checked); 63 } 64 65 if (($("#" + textarea_id).val().length > 0) && ($("#" + textarea_id).attr('class').indexOf("filterxss1") != -1 || $("#" + textarea_id).attr('class').indexOf("filterxss2") != -1)) { 66 $.post(Drupal.settings.basePath + 'index.php?q=ckeditor/xss', { 67 text: $('#' + textarea_id).val(), 68 'filters[]': Drupal.settings.ckeditor.settings[textarea_id].filters 69 }, function(text){ 70 $("#" + textarea_id).val(text); 71 }); 72 } 73 74 $("#" + textarea_id).next(".grippie").css("display", "none"); 75 $("#" + textarea_id).addClass("ckeditor-processed"); 76 77 Drupal.settings.ckeditor.settings[textarea_id]['on'] = 78 { 79 configLoaded : function(ev) 80 { 81 ev.editor.addCss(ev.editor.config.extraCss); 82 }, 83 instanceReady : function(ev) 84 { 85 var body = $(ev.editor.document.$.body); 86 if (typeof(Drupal.settings.ckeditor.settings[textarea_id].custom_formatting) != 'undefined') { 87 var dtd = CKEDITOR.dtd; 88 for ( var e in CKEDITOR.tools.extend( {}, dtd.$block, dtd.$listItem, dtd.$tableContent ) ) { 89 ev.editor.dataProcessor.writer.setRules( e, Drupal.settings.ckeditor.settings[textarea_id].custom_formatting); 90 } 91 ev.editor.dataProcessor.writer.setRules( 'pre', 92 { 93 indent: Drupal.settings.ckeditor.settings[textarea_id].output_pre_indent 94 }); 95 } 96 97 if (ev.editor.config.bodyClass) 98 body.addClass(ev.editor.config.bodyClass); 99 if (ev.editor.config.bodyId) 100 body.attr('id', ev.editor.config.bodyId); 101 if (typeof(Drupal.smileysAttach) != 'undefined') 102 ev.editor.dataProcessor.writer.indentationChars = ' '; 103 }, 104 focus : function(ev) 105 { 106 Drupal.ckeditorInstance = ev.editor; 107 } 108 }; 109 110 Drupal.ckeditorInstance = CKEDITOR.replace(textarea_id, Drupal.settings.ckeditor.settings[textarea_id]); 111 }; 112 113 /** 114 * CKEditor destroy function 115 * 116 * @param string textarea_id 117 */ 118 Drupal.ckeditorOff = function(textarea_id) { 119 if (typeof(CKEDITOR.instances[textarea_id]) == 'undefined') { 120 return; 121 } 122 if (!CKEDITOR.env.isCompatible) { 123 return; 124 } 125 if (Drupal.ckeditorInstance && Drupal.ckeditorInstance.name == textarea_id) 126 delete Drupal.ckeditorInstance; 127 128 var data = CKEDITOR.instances[textarea_id].getData(); 129 CKEDITOR.instances[textarea_id].destroy(); 130 if (teaser = Drupal.ckeditorTeaserInfo(textarea_id)) { 131 var brcode = /<!--break-->/; 132 data = data.split(brcode); 133 if (data.length > 1) { 134 teaser.textareaContainer.show(); 135 teaser.textarea.attr('disabled', ''); 136 if (teaser.button.attr('value') != Drupal.t('Join summary')) { 137 try { 138 teaser.button.click(); 139 } 140 catch (e) { 141 teaser.button.val(Drupal.t('Join summary')); 142 } 143 } 144 teaser.textarea.val(data[0]); 145 $("#" + textarea_id).val(data[1]); 146 } 147 else { 148 $("#" + textarea_id).val(data[0]); 149 teaser.textarea.attr('disabled', 'disabled'); 150 teaser.checkboxContainer.hide(); 151 if (teaser.button.attr('value') != Drupal.t('Split summary at cursor')) { 152 try { 153 teaser.button.click(); 154 } 155 catch (e) { 156 teaser.button.val(Drupal.t('Split summary at cursor')); 157 } 158 } 159 } 160 teaser.buttonContainer.show(); 161 } 162 163 $("#" + textarea_id).next(".grippie").css("display", "block"); 164 $("#" + textarea_id).removeClass("ckeditor-processed"); 165 }; 166 167 /** 168 * CKEditor popup mode function 169 */ 170 function ckeditorOpenPopup(jsID, textareaID, width){ 171 popupUrl = Drupal.settings.ckeditor.module_path + '/includes/ckeditor.popup.html?var=' + jsID + '&el=' + textareaID; 172 173 var percentPos = width.indexOf('%'); 174 if (percentPos != -1) { 175 width = width.substr(0, percentPos); 176 width = width / 100 * screen.width; 177 } 178 window.open(popupUrl, null, 'width=' + width + ',toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=1,dependent=yes'); 179 return false; 180 }; 181 182 /** 183 * Returns true if CKEDITOR.version >= version 184 */ 185 Drupal.ckeditorCompareVersion = function (version){ 186 var ckver = CKEDITOR.version; 187 ckver = ckver.match(/(([\d]\.)+[\d]+)/i); 188 version = version.match(/((\d+\.)+[\d]+)/i); 189 ckver = ckver[0].split('.'); 190 version = version[0].split('.'); 191 for (var x in ckver) { 192 if (ckver[x]<version[x]) { 193 return false; 194 } 195 } 196 return true; 197 }; 198 199 /** 200 * This function retrieves information about a possible teaser field associated 201 * with the mentioned field. 202 * 203 * @param taid 204 * string HTML id of the main text area 205 */ 206 Drupal.ckeditorTeaserInfo = function(taid) { 207 // if the result is cached, return it 208 if (Drupal.ckeditorTeaser.cache[taid]) { 209 return Drupal.ckeditorTeaser.cache[taid]; 210 } 211 212 // build a lookup table 213 if (!Drupal.ckeditorTeaser.lookupSetup) { 214 Drupal.ckeditorTeaser.lookupSetup = true; 215 for (var x in Drupal.settings.teaser) { 216 Drupal.ckeditorTeaser.lookup[Drupal.settings.teaser[x]] = x; 217 } 218 } 219 220 // find the elements 221 if (Drupal.ckeditorTeaser.lookup[taid]) { 222 var obj; 223 if (window.opener && window.ckeditor_was_opened_in_popup_window) { 224 obj = { 225 textarea: window.opener.$('#' + Drupal.ckeditorTeaser.lookup[taid]), 226 checkbox: window.opener.$('#' + Drupal.settings.teaserCheckbox[Drupal.ckeditorTeaser.lookup[taid]]) 227 }; 228 } else { 229 obj = { 230 textarea: $('#' + Drupal.ckeditorTeaser.lookup[taid]), 231 checkbox: $('#' + Drupal.settings.teaserCheckbox[Drupal.ckeditorTeaser.lookup[taid]]) 232 }; 233 } 234 235 obj.textareaContainer = obj.textarea.parent(); 236 obj.checkboxContainer = obj.checkbox.parent(); 237 238 obj.button = $('input.teaser-button', obj.checkbox.parents('div.teaser-checkbox').get(0)); 239 obj.buttonContainer = obj.button.parent(); 240 241 Drupal.ckeditorTeaser.cache[taid] = obj; 242 } 243 else { 244 Drupal.ckeditorTeaser.cache[taid] = null; 245 } 246 247 return Drupal.ckeditorTeaser.cache[taid]; 248 }; 249 250 Drupal.ckeditorInsertHtml = function(html) { 251 if (!Drupal.ckeditorInstance) 252 return false; 253 254 if (Drupal.ckeditorInstance.mode == 'wysiwyg') { 255 Drupal.ckeditorInstance.insertHtml(html); 256 return true; 257 } 258 else { 259 alert(Drupal.t('Content can be only inserted into CKEditor in WYSIWYG mode.')); 260 return false; 261 } 262 }; 263 264 /** 265 * Ajax support [#741572] 266 */ 267 if (typeof(Drupal.Ajax) != 'undefined' && typeof(Drupal.Ajax.plugins) != 'undefined') { 268 Drupal.Ajax.plugins.CKEditor = function(hook, args) { 269 if (hook === 'submit' && typeof(CKEDITOR.instances) != 'undefined') { 270 for (var i in CKEDITOR.instances) 271 CKEDITOR.instances[i].updateElement(); 272 } 273 return true; 274 }; 275 } 276 277 /** 278 * IMCE support 279 */ 280 function ckeditor_fileUrl(file, win){ 281 var cfunc = win.location.href.split('&'); 282 283 for (var x in cfunc) { 284 if (cfunc[x].match(/^CKEditorFuncNum=\d+$/)) { 285 cfunc = cfunc[x].split('='); 286 break; 287 } 288 } 289 290 CKEDITOR.tools.callFunction(cfunc[1], file.url); 291 win.close(); 292 } 293 294 //Support for Panels [#679976] 295 Drupal.ckeditorSubmitAjaxForm = function () { 296 if (typeof(CKEDITOR.instances) != 'undefined' && typeof(CKEDITOR.instances['edit-body']) != 'undefined') { 297 Drupal.ckeditorOff('edit-body'); 298 } 299 }; 300 301 /** 302 * Drupal behaviors 303 */ 304 Drupal.behaviors.ckeditor = function (context) { 305 if ((typeof(CKEDITOR) == 'undefined') || !CKEDITOR.env.isCompatible) { 306 return; 307 } 308 $('.ckeditor_links').show(); 309 // make sure the textarea behavior is run first, to get a correctly sized grippie 310 // the textarea behavior requires the teaser behavior, so load that one as well 311 if (Drupal.behaviors.teaser) { 312 Drupal.behaviors.teaser(context); 313 } 314 if (Drupal.behaviors.textarea) { 315 Drupal.behaviors.textarea(context); 316 } 317 318 // Support for Panels [#679976] 319 if ($(context).attr('id') == 'modal-content') { 320 if (CKEDITOR.instances['edit-body'] != 'undefined') { 321 Drupal.ckeditorOff('edit-body'); 322 } 323 $('input#edit-return', context).bind('mouseup', Drupal.ckeditorSubmitAjaxForm); 324 $('.close').bind('mouseup', Drupal.ckeditorSubmitAjaxForm); 325 CKEDITOR.on('dialogDefinition', function (ev) { 326 var dialogDefinition = ev.data.definition; 327 var _onShow = dialogDefinition.onShow; 328 dialogDefinition.onShow = function () { 329 if ( _onShow ) { 330 _onShow.apply( this ); 331 } 332 $('body').unbind('keypress'); 333 }; 334 }); 335 } 336 337 $("textarea.ckeditor-mod:not(.ckeditor-processed)").each(function () { 338 var ta_id=$(this).attr("id"); 339 if ((typeof(Drupal.settings.ckeditor.autostart) != 'undefined') && (typeof(Drupal.settings.ckeditor.autostart[ta_id]) != 'undefined')) { 340 Drupal.ckeditorOn(ta_id); 341 } 342 }); 343 };
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| Generated: Thu Mar 24 11:18:33 2011 | Cross-referenced by PHPXref 0.7 |