| [ Index ] |
PHP Cross Reference of Drupal 6 (yi-drupal) |
[Summary view] [Print] [Text view]
1 /* 2 Copyright (c) 2003-2011, CKSource - Frederico Knabben. All rights reserved. 3 For licensing, see LICENSE.html or http://ckeditor.com/license 4 */ 5 Drupal.ckeditor = (typeof(CKEDITOR) != 'undefined'); 6 // this object will store teaser information 7 Drupal.ckeditorTeaser = { 8 lookup: {}, 9 lookupSetup: false, 10 cache: {} 11 }; 12 13 Drupal.ckeditorToggle = function(textarea_id, TextTextarea, TextRTE, xss_check){ 14 if (!CKEDITOR.env.isCompatible) { 15 return; 16 } 17 if (typeof(CKEDITOR.instances) != 'undefined' && typeof(CKEDITOR.instances[textarea_id]) != 'undefined') { 18 Drupal.ckeditorOff(textarea_id); 19 $('#switch_' + textarea_id).text(TextRTE); 20 } 21 else { 22 $("#" + textarea_id).val(Drupal.ckeditorLinebreakConvert(textarea_id, $("#" + textarea_id).val())); 23 Drupal.ckeditorOn(textarea_id); 24 $('#switch_' + textarea_id).text(TextTextarea); 25 } 26 }; 27 28 /** 29 * CKEditor starting function 30 * 31 * @param string textarea_id 32 */ 33 Drupal.ckeditorInit = function(textarea_id) { 34 $("#" + textarea_id).next(".grippie").css("display", "none"); 35 $("#" + textarea_id).addClass("ckeditor-processed"); 36 37 var textarea_settings = false; 38 Drupal.settings.ckeditor.settings[textarea_id].toolbar = eval(Drupal.settings.ckeditor.settings[textarea_id].toolbar); 39 textarea_settings = Drupal.settings.ckeditor.settings[textarea_id]; 40 textarea_settings['on'] = 41 { 42 configLoaded : function(ev) 43 { 44 ev.editor.addCss(ev.editor.config.extraCss); 45 }, 46 instanceReady : function(ev) 47 { 48 var body = $(ev.editor.document.$.body); 49 // Don't enter line breaks after paragraph so we can be friendly to drupal's line break filter. 50 ev.editor.dataProcessor.writer.setRules('p', { 51 breakAfterOpen: false 52 }); 53 if (typeof(textarea_settings.custom_formatting) != 'undefined') { 54 var dtd = CKEDITOR.dtd; 55 for ( var e in CKEDITOR.tools.extend( {}, dtd.$block, dtd.$listItem, dtd.$tableContent ) ) { 56 ev.editor.dataProcessor.writer.setRules( e, textarea_settings.custom_formatting); 57 } 58 ev.editor.dataProcessor.writer.setRules( 'pre', 59 { 60 indent: textarea_settings.output_pre_indent 61 }); 62 } 63 64 if (ev.editor.config.bodyClass) 65 body.addClass(ev.editor.config.bodyClass); 66 if (ev.editor.config.bodyId) 67 body.attr('id', ev.editor.config.bodyId); 68 if (typeof(Drupal.smileysAttach) != 'undefined') 69 ev.editor.dataProcessor.writer.indentationChars = ' '; 70 }, 71 focus : function(ev) 72 { 73 Drupal.ckeditorInstance = ev.editor; 74 Drupal.ckeditorActiveId = ev.editor.name; 75 } 76 }; 77 78 if (typeof textarea_settings['js_conf'] != 'undefined'){ 79 for (var add_conf in textarea_settings['js_conf']){ 80 textarea_settings[add_conf] = eval(textarea_settings['js_conf'][add_conf]); 81 } 82 } 83 84 textarea_settings.extraPlugins = ''; 85 if (typeof CKEDITOR.plugins != 'undefined'){ 86 for (var plugin in textarea_settings['loadPlugins']){ 87 textarea_settings.extraPlugins += (textarea_settings.extraPlugins) ? ',' + textarea_settings['loadPlugins'][plugin]['name'] : textarea_settings['loadPlugins'][plugin]['name']; 88 CKEDITOR.plugins.addExternal(textarea_settings['loadPlugins'][plugin]['name'], textarea_settings['loadPlugins'][plugin]['path']); 89 } 90 } 91 92 Drupal.ckeditorInstance = CKEDITOR.replace(textarea_id, textarea_settings); 93 }; 94 95 Drupal.ckeditorOn = function(textarea_id) { 96 if ((typeof(Drupal.settings.ckeditor.load_timeout) == 'undefined') && (typeof(CKEDITOR.instances[textarea_id]) != 'undefined')) { 97 return; 98 } 99 if (typeof(Drupal.settings.ckeditor.settings[textarea_id]) == 'undefined') { 100 return; 101 } 102 if (!CKEDITOR.env.isCompatible) { 103 return; 104 } 105 var teaser = Drupal.ckeditorTeaserInfo(textarea_id); 106 if (teaser) { 107 var ch_checked = teaser.checkbox.attr('checked'); 108 var tv = teaser.textarea.val(); 109 if (!teaser.textarea.attr("disabled")) { 110 $("#" + textarea_id).val(tv + '\n<!--break-->\n' + $("#" + textarea_id).val()); 111 teaser.textarea.val(''); 112 } 113 114 // [#653498] 115 if (teaser.button.attr('value') != Drupal.t('Split summary at cursor')) { 116 try { 117 teaser.button.click(); 118 } 119 catch (e) { 120 teaser.button.val(Drupal.t('Split summary at cursor')); 121 } 122 } 123 124 teaser.buttonContainer.hide(); 125 teaser.textareaContainer.hide(); 126 teaser.checkboxContainer.show(); 127 teaser.checkbox.attr('checked', ch_checked); 128 } 129 130 if (( $("#" + textarea_id).length > 0 && $("#" + textarea_id).val().length > 0) && ($("#" + textarea_id).attr('class').indexOf("filterxss1") != -1 || $("#" + textarea_id).attr('class').indexOf("filterxss2") != -1)) { 131 if (typeof Drupal.settings.ckeditor.settings[textarea_id].input_format == 'undefined') { 132 Drupal.settings.ckeditor.settings[textarea_id].input_format = Drupal.settings.ckeditor.default_input_format; 133 } 134 else if (typeof Drupal.settings.ckeditor.settings[textarea_id].input_format == 'object') { 135 Drupal.settings.ckeditor.settings[textarea_id].input_format = Drupal.settings.ckeditor.settings[textarea_id].input_format.pop(); 136 } 137 $.post(Drupal.settings.basePath + 'index.php?q=ckeditor/xss', { 138 'text': $('#' + textarea_id).val(), 139 'token': Drupal.settings.ckeditor.ajaxToken, 140 'textarea_id': textarea_id, 141 'query': Drupal.settings.ckeditor.query, 142 'theme': Drupal.settings.ckeditor.theme, 143 'input_format': Drupal.settings.ckeditor.settings[textarea_id].input_format 144 }, function(text){ 145 $("#" + textarea_id).val(text); 146 Drupal.ckeditorInit(textarea_id); 147 }); 148 } 149 else { 150 Drupal.ckeditorInit(textarea_id); 151 } 152 153 }; 154 155 /** 156 * CKEditor destroy function 157 * 158 * @param string textarea_id 159 */ 160 Drupal.ckeditorOff = function(textarea_id) { 161 if (typeof(CKEDITOR.instances[textarea_id]) == 'undefined') { 162 return; 163 } 164 if (!CKEDITOR.env.isCompatible) { 165 return; 166 } 167 if (Drupal.ckeditorInstance && Drupal.ckeditorInstance.name == textarea_id) 168 delete Drupal.ckeditorInstance; 169 170 var data = CKEDITOR.instances[textarea_id].getData(); 171 CKEDITOR.instances[textarea_id].destroy(); 172 var teaser = Drupal.ckeditorTeaserInfo(textarea_id); 173 if (teaser) { 174 var brcode = /<!--break-->/; 175 data = data.split(brcode); 176 if (data.length > 1) { 177 teaser.textareaContainer.show(); 178 teaser.textarea.attr('disabled', ''); 179 if (teaser.button.attr('value') != Drupal.t('Join summary')) { 180 try { 181 teaser.button.click(); 182 } 183 catch (e) { 184 teaser.button.val(Drupal.t('Join summary')); 185 } 186 } 187 teaser.textarea.val(data[0]); 188 $("#" + textarea_id).val(data[1]); 189 } 190 else { 191 $("#" + textarea_id).val(data[0]); 192 teaser.textarea.attr('disabled', 'disabled'); 193 teaser.checkboxContainer.hide(); 194 if (teaser.button.attr('value') != Drupal.t('Split summary at cursor')) { 195 try { 196 teaser.button.click(); 197 } 198 catch (e) { 199 teaser.button.val(Drupal.t('Split summary at cursor')); 200 } 201 } 202 } 203 teaser.buttonContainer.show(); 204 } 205 206 $("#" + textarea_id).next(".grippie").css("display", "block"); 207 $("#" + textarea_id).removeClass("ckeditor-processed"); 208 }; 209 210 /** 211 * CKEditor popup mode function 212 */ 213 function ckeditorOpenPopup(jsID, textareaID, width){ 214 popupUrl = Drupal.settings.ckeditor.module_path + '/includes/ckeditor.popup.html?var=' + jsID + '&el=' + textareaID; 215 var percentPos = width.indexOf('%'); 216 if (percentPos != -1) { 217 width = width.substr(0, percentPos); 218 width = width / 100 * screen.width; 219 } 220 window.open(popupUrl, null, 'width=' + width + ',toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=1,dependent=yes'); 221 return false; 222 }; 223 224 /** 225 * Returns true if CKEDITOR.version >= version 226 */ 227 Drupal.ckeditorCompareVersion = function (version){ 228 var ckver = CKEDITOR.version; 229 ckver = ckver.match(/(([\d]\.)+[\d]+)/i); 230 version = version.match(/((\d+\.)+[\d]+)/i); 231 ckver = ckver[0].split('.'); 232 version = version[0].split('.'); 233 for (var x in ckver) { 234 if (ckver[x]<version[x]) { 235 return false; 236 } 237 else if (ckver[x]>version[x]) { 238 return true; 239 } 240 } 241 242 return true; 243 }; 244 245 /** 246 * This function retrieves information about a possible teaser field associated 247 * with the mentioned field. 248 * 249 * @param taid 250 * string HTML id of the main text area 251 */ 252 Drupal.ckeditorTeaserInfo = function(taid) { 253 // if the result is cached, return it 254 if (Drupal.ckeditorTeaser.cache[taid]) { 255 return Drupal.ckeditorTeaser.cache[taid]; 256 } 257 // build a lookup table 258 if (!Drupal.ckeditorTeaser.lookupSetup) { 259 Drupal.ckeditorTeaser.lookupSetup = true; 260 for (var x in Drupal.settings.teaser) { 261 Drupal.ckeditorTeaser.lookup[Drupal.settings.teaser[x]] = x; 262 } 263 } 264 // find the elements 265 if (Drupal.ckeditorTeaser.lookup[taid]) { 266 var obj; 267 if (window.opener && window.ckeditor_was_opened_in_popup_window) { 268 obj = { 269 textarea: window.opener.$('#' + Drupal.ckeditorTeaser.lookup[taid]), 270 checkbox: window.opener.$('#' + Drupal.settings.teaserCheckbox[Drupal.ckeditorTeaser.lookup[taid]]) 271 }; 272 } else { 273 obj = { 274 textarea: $('#' + Drupal.ckeditorTeaser.lookup[taid]), 275 checkbox: $('#' + Drupal.settings.teaserCheckbox[Drupal.ckeditorTeaser.lookup[taid]]) 276 }; 277 } 278 obj.textareaContainer = obj.textarea.parent(); 279 obj.checkboxContainer = obj.checkbox.parent(); 280 obj.button = $('input.teaser-button', obj.checkbox.parents('div.teaser-checkbox').get(0)); 281 obj.buttonContainer = obj.button.parent(); 282 Drupal.ckeditorTeaser.cache[taid] = obj; 283 } 284 else { 285 Drupal.ckeditorTeaser.cache[taid] = null; 286 } 287 288 return Drupal.ckeditorTeaser.cache[taid]; 289 }; 290 291 Drupal.ckeditorInsertHtml = function(html) { 292 if (!Drupal.ckeditorInstance) 293 return false; 294 295 if (Drupal.ckeditorInstance.mode == 'wysiwyg') { 296 Drupal.ckeditorInstance.insertHtml(html); 297 return true; 298 } 299 else { 300 alert(Drupal.t('Content can only be inserted into CKEditor in the WYSIWYG mode.')); 301 return false; 302 } 303 }; 304 305 /** 306 * Converts \n to <br /> 307 * It in no way tries to compete with Line break converter filter 308 */ 309 Drupal.ckeditorEnterModeConvert = function(enterMode){ 310 if (enterMode == 1) 311 return {startTag: '<p>', endTag: '</p>'}; 312 if (enterMode == 2) 313 return {startTag: '', endTag: '<br/>'}; 314 if (enterMode == 3) 315 return {startTag: '<div>', endTag: '</div>'}; 316 return {startTag: '', endTag: ''} 317 } 318 319 Drupal.ckeditorLinebreakConvert = function(textarea_id, text) { 320 var enterMode = Drupal.ckeditorEnterModeConvert(Drupal.settings.ckeditor.settings[textarea_id].enterMode); 321 if (!text.match(/<(div|p|br).*\/?>/i) && text) { 322 text = enterMode.startTag + text.replace(/\r\n|\n\r/g, '\n').replace(/\n\n/g, enterMode.endTag+enterMode.startTag).replace(/\n/g, '<br />') + enterMode.endTag; 323 } 324 return text; 325 } 326 327 /** 328 * Ajax support [#741572] 329 */ 330 if (typeof(Drupal.Ajax) != 'undefined' && typeof(Drupal.Ajax.plugins) != 'undefined') { 331 Drupal.Ajax.plugins.CKEditor = function(hook, args) { 332 if (hook === 'submit' && typeof(CKEDITOR.instances) != 'undefined') { 333 for (var i in CKEDITOR.instances) 334 CKEDITOR.instances[i].updateElement(); 335 } 336 return true; 337 }; 338 } 339 340 /** 341 * IMCE support 342 */ 343 function ckeditor_fileUrl(file, win){ 344 var cfunc = win.location.href.split('&'); 345 346 for (var x in cfunc) { 347 if (cfunc[x].match(/^CKEditorFuncNum=\d+$/)) { 348 cfunc = cfunc[x].split('='); 349 break; 350 } 351 } 352 353 CKEDITOR.tools.callFunction(cfunc[1], file.url); 354 win.close(); 355 } 356 357 //Support for Panels [#679976] 358 Drupal.ckeditorSubmitAjaxForm = function () { 359 if (typeof(CKEDITOR.instances) != 'undefined' && typeof(CKEDITOR.instances['edit-body']) != 'undefined') { 360 Drupal.ckeditorOff('edit-body'); 361 } 362 }; 363 364 /** 365 * Drupal behaviors 366 */ 367 var imagefield_data = new Object(); 368 Drupal.behaviors.ckeditor = function (context) { 369 if ((typeof(CKEDITOR) == 'undefined') || !CKEDITOR.env.isCompatible) { 370 return; 371 } 372 373 if (typeof CKEDITOR.instances != 'undefined') 374 { 375 $.each(CKEDITOR.instances, function(index, value){ 376 if ($('#'+index).length == 0) 377 { 378 delete CKEDITOR.instances[index]; 379 } 380 }); 381 } 382 $('.ckeditor_links').show(); 383 // make sure the textarea behavior is run first, to get a correctly sized grippie 384 // the textarea behavior requires the teaser behavior, so load that one as well 385 if (Drupal.behaviors.teaser) { 386 Drupal.behaviors.teaser(context); 387 } 388 if (Drupal.behaviors.textarea) { 389 Drupal.behaviors.textarea(context); 390 } 391 392 //Support for imageField [#1286192] 393 if (Drupal.behaviors.filefieldButtons) { 394 $('input[id$="-add-more"]:submit').each(function(){ 395 $(this).mousedown(function(){ 396 $('.form-item textarea.ckeditor-mod', $(this).parent().prev().html()).each(function(){ 397 if (typeof CKEDITOR.instances[$(this).attr('id')] != 'undefined') { 398 imagefield_data[$(this).attr('id')] = CKEDITOR.instances[$(this).attr('id')].getData(); 399 } 400 Drupal.ckeditorOff($(this).attr('id')); 401 }); 402 }); 403 }); 404 if ($('.form-item textarea', $(context)).length == 1) { 405 var url = document.location.pathname; 406 if (url.indexOf('/') == 0 ) url = url.substr(1); 407 var path = Drupal.settings.basePath; 408 var imagefield_id = $('textarea', $(context)).attr('id'); 409 if (!CKEDITOR.instances[imagefield_id]){ 410 $.ajax({ 411 url: path + 'admin/ckeditor/get_settings', 412 dataType: 'json', 413 data: {'id': imagefield_id, 'url': url, 'token': Drupal.settings.ckeditor.ajaxToken}, 414 type: 'POST', 415 success: function( data ) { 416 Drupal.settings.ckeditor.settings[imagefield_id] = data; 417 if ($(data).length > 0) { 418 Drupal.settings.ckeditor.autostart[imagefield_id] = true; 419 Drupal.ckeditorOn(imagefield_id); 420 } 421 } 422 }); 423 $('input[id$="-filefield-remove"]', $(context)).mousedown(function(){ 424 $('textarea.ckeditor-mod', $(context)).each(function(){ 425 if (CKEDITOR.instances[$(this).attr('id')]){ 426 Drupal.ckeditorOff($(this).attr('id')); 427 imagefield_data[$(this).attr('id')] = ""; 428 } 429 }) 430 }); 431 } 432 } 433 } 434 435 //Added for support [#1288664] Views 436 if ($(context).attr('id') === 'views-ajax-pad'){ 437 $("div.form-buttons input#edit-submit").click(function(){ 438 if (typeof CKEDITOR.instances['edit-header'] != 'undefined' )$('#edit-header').attr('value',CKEDITOR.instances['edit-header'].document.getBody().getHtml()); 439 if (typeof CKEDITOR.instances['edit-footer'] != 'undefined' )$('#edit-footer').attr('value',CKEDITOR.instances['edit-footer'].document.getBody().getHtml()); 440 if (typeof CKEDITOR.instances['edit-empty'] != 'undefined' )$('#edit-empty').attr('value',CKEDITOR.instances['edit-empty'].document.getBody().getHtml()); 441 }); 442 var views_textarea_id = $("textarea", $(context)).attr('id'); 443 if (typeof views_textarea_id != 'undefined' && views_textarea_id != 'edit-options-alter-text'){ 444 path = Drupal.settings.basePath; 445 views_path = $("form", $(context)).attr('action'); 446 if (views_path.indexOf('/') == 0) { 447 views_path = views_path.substr(1) 448 } 449 $.ajax({ 450 url: path + 'admin/ckeditor/get_settings', 451 dataType: 'json', 452 data: {'id': views_textarea_id, 'url': views_path, 'token': Drupal.settings.ckeditor.ajaxToken}, 453 type: 'POST', 454 success: function( data ) { 455 if ($(data).length > 0 && typeof CKEDITOR.instances[views_textarea_id] == 'undefined'){ 456 Drupal.settings.ckeditor.settings[views_textarea_id] = data; 457 Drupal.ckeditorOn(views_textarea_id); 458 } 459 } 460 }); 461 } 462 } 463 464 // Support for Panels [#679976] 465 if ($(context).attr('id') == 'modal-content') { 466 if (CKEDITOR.instances['edit-body'] != 'undefined') { 467 Drupal.ckeditorOff('edit-body'); 468 } 469 $('input#edit-return', context).bind('mouseup', Drupal.ckeditorSubmitAjaxForm); 470 $('.close').bind('mouseup', Drupal.ckeditorSubmitAjaxForm); 471 CKEDITOR.on('dialogDefinition', function (ev) { 472 var dialogDefinition = ev.data.definition; 473 var _onShow = dialogDefinition.onShow; 474 dialogDefinition.onShow = function () { 475 if ( _onShow ) { 476 _onShow.apply( this ); 477 } 478 $('body').unbind('keypress'); 479 }; 480 }); 481 } 482 483 $("textarea.ckeditor-mod:not(.ckeditor-processed)").each(function () { 484 var ta_id=$(this).attr("id"); 485 if ((typeof(Drupal.settings.ckeditor.autostart) != 'undefined') && (typeof(Drupal.settings.ckeditor.autostart[ta_id]) != 'undefined') ) { 486 if(typeof imagefield_data[ta_id] == "string") { 487 $("#"+ta_id).attr('value', imagefield_data[ta_id]); 488 } 489 Drupal.ckeditorOn(ta_id); 490 } 491 }); 492 493 $("form").bind('submit', function() { 494 $(this).find('textarea.ckeditor-processed').each(function() { 495 $(this).val(Drupal.ckeditorLinebreakConvert($(this).attr("id"), $(this).val())); 496 }); 497 }); 498 }; 499 500 if (Drupal.tableDrag) { 501 Drupal.tableDrag.prototype.onDrag = function() { 502 $(this.rowObject.element).find('textarea.ckeditor-processed').each( 503 function() { 504 if (typeof(CKEDITOR.instances) != 'undefined' && typeof(CKEDITOR.instances[$(this).attr('id')]) != 'undefined') { 505 data = CKEDITOR.instances[$(this).attr('id')].document.getBody().getHtml(); 506 $("#"+$(this).attr('id')).attr('value',data); 507 Drupal.ckeditorOff($(this).attr('id')); 508 } 509 } 510 ); 511 }; 512 Drupal.tableDrag.prototype.onDrop = function() { 513 514 $(this.rowObject.element).find('textarea.ckeditor-mod:not(.ckeditor-processed)').each( 515 function() { 516 if ((typeof(Drupal.settings.ckeditor.autostart) != 'undefined') && (typeof(Drupal.settings.ckeditor.autostart[$(this).attr('id')]) != 'undefined')) { 517 Drupal.ckeditorOn($(this).attr('id')); 518 } 519 } 520 ); 521 }; 522 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| Generated: Mon Jul 9 18:01:44 2012 | Cross-referenced by PHPXref 0.7 |