| [ Index ] |
PHP Cross Reference of WordPress Trunk (Updated Daily) |
[Summary view] [Print] [Text view]
1 /* 2 * Quicktags 3 * 4 * This is the HTML editor in WordPress. It can be attached to any textarea and will 5 * append a toolbar above it. This script is self-contained (does not require external libraries). 6 * 7 * Run quicktags(settings) to initialize it, where settings is an object containing up to 3 properties: 8 * settings = { 9 * id : 'my_id', the HTML ID of the textarea, required 10 * buttons: '' Comma separated list of the names of the default buttons to show. Optional. 11 * Current list of default button names: 'strong,em,link,block,del,ins,img,ul,ol,li,code,more,close'; 12 * } 13 * 14 * The settings can also be a string quicktags_id. 15 * 16 * quicktags_id string The ID of the textarea that will be the editor canvas 17 * buttons string Comma separated list of the default buttons names that will be shown in that instance. 18 * 19 * @output wp-includes/js/quicktags.js 20 */ 21 22 // New edit toolbar used with permission 23 // by Alex King 24 // http://www.alexking.org/ 25 26 /* global adminpage, wpActiveEditor, quicktagsL10n, wpLink, prompt, edButtons */ 27 28 window.edButtons = []; 29 30 /* jshint ignore:start */ 31 32 /** 33 * Back-compat 34 * 35 * Define all former global functions so plugins that hack quicktags.js directly don't cause fatal errors. 36 */ 37 window.edAddTag = function(){}; 38 window.edCheckOpenTags = function(){}; 39 window.edCloseAllTags = function(){}; 40 window.edInsertImage = function(){}; 41 window.edInsertLink = function(){}; 42 window.edInsertTag = function(){}; 43 window.edLink = function(){}; 44 window.edQuickLink = function(){}; 45 window.edRemoveTag = function(){}; 46 window.edShowButton = function(){}; 47 window.edShowLinks = function(){}; 48 window.edSpell = function(){}; 49 window.edToolbar = function(){}; 50 51 /* jshint ignore:end */ 52 53 (function(){ 54 // Private stuff is prefixed with an underscore. 55 var _domReady = function(func) { 56 var t, i, DOMContentLoaded, _tryReady; 57 58 if ( typeof jQuery !== 'undefined' ) { 59 jQuery( func ); 60 } else { 61 t = _domReady; 62 t.funcs = []; 63 64 t.ready = function() { 65 if ( ! t.isReady ) { 66 t.isReady = true; 67 for ( i = 0; i < t.funcs.length; i++ ) { 68 t.funcs[i](); 69 } 70 } 71 }; 72 73 if ( t.isReady ) { 74 func(); 75 } else { 76 t.funcs.push(func); 77 } 78 79 if ( ! t.eventAttached ) { 80 if ( document.addEventListener ) { 81 DOMContentLoaded = function(){document.removeEventListener('DOMContentLoaded', DOMContentLoaded, false);t.ready();}; 82 document.addEventListener('DOMContentLoaded', DOMContentLoaded, false); 83 window.addEventListener('load', t.ready, false); 84 } else if ( document.attachEvent ) { 85 DOMContentLoaded = function(){if (document.readyState === 'complete'){ document.detachEvent('onreadystatechange', DOMContentLoaded);t.ready();}}; 86 document.attachEvent('onreadystatechange', DOMContentLoaded); 87 window.attachEvent('onload', t.ready); 88 89 _tryReady = function() { 90 try { 91 document.documentElement.doScroll('left'); 92 } catch(e) { 93 setTimeout(_tryReady, 50); 94 return; 95 } 96 97 t.ready(); 98 }; 99 _tryReady(); 100 } 101 102 t.eventAttached = true; 103 } 104 } 105 }, 106 107 _datetime = (function() { 108 var now = new Date(), zeroise; 109 110 zeroise = function(number) { 111 var str = number.toString(); 112 113 if ( str.length < 2 ) { 114 str = '0' + str; 115 } 116 117 return str; 118 }; 119 120 return now.getUTCFullYear() + '-' + 121 zeroise( now.getUTCMonth() + 1 ) + '-' + 122 zeroise( now.getUTCDate() ) + 'T' + 123 zeroise( now.getUTCHours() ) + ':' + 124 zeroise( now.getUTCMinutes() ) + ':' + 125 zeroise( now.getUTCSeconds() ) + 126 '+00:00'; 127 })(); 128 129 var qt = window.QTags = function(settings) { 130 if ( typeof(settings) === 'string' ) { 131 settings = {id: settings}; 132 } else if ( typeof(settings) !== 'object' ) { 133 return false; 134 } 135 136 var t = this, 137 id = settings.id, 138 canvas = document.getElementById(id), 139 name = 'qt_' + id, 140 tb, onclick, toolbar_id, wrap, setActiveEditor; 141 142 if ( !id || !canvas ) { 143 return false; 144 } 145 146 t.name = name; 147 t.id = id; 148 t.canvas = canvas; 149 t.settings = settings; 150 151 if ( id === 'content' && typeof(adminpage) === 'string' && ( adminpage === 'post-new-php' || adminpage === 'post-php' ) ) { 152 // Back compat hack :-( 153 window.edCanvas = canvas; 154 toolbar_id = 'ed_toolbar'; 155 } else { 156 toolbar_id = name + '_toolbar'; 157 } 158 159 tb = document.getElementById( toolbar_id ); 160 161 if ( ! tb ) { 162 tb = document.createElement('div'); 163 tb.id = toolbar_id; 164 tb.className = 'quicktags-toolbar'; 165 } 166 167 canvas.parentNode.insertBefore(tb, canvas); 168 t.toolbar = tb; 169 170 // Listen for click events. 171 onclick = function(e) { 172 e = e || window.event; 173 var target = e.target || e.srcElement, visible = target.clientWidth || target.offsetWidth, i; 174 175 // Don't call the callback on pressing the accesskey when the button is not visible. 176 if ( !visible ) { 177 return; 178 } 179 180 // As long as it has the class ed_button, execute the callback. 181 if ( / ed_button /.test(' ' + target.className + ' ') ) { 182 // We have to reassign canvas here. 183 t.canvas = canvas = document.getElementById(id); 184 i = target.id.replace(name + '_', ''); 185 186 if ( t.theButtons[i] ) { 187 t.theButtons[i].callback.call(t.theButtons[i], target, canvas, t); 188 } 189 } 190 }; 191 192 setActiveEditor = function() { 193 window.wpActiveEditor = id; 194 }; 195 196 wrap = document.getElementById( 'wp-' + id + '-wrap' ); 197 198 if ( tb.addEventListener ) { 199 tb.addEventListener( 'click', onclick, false ); 200 201 if ( wrap ) { 202 wrap.addEventListener( 'click', setActiveEditor, false ); 203 } 204 } else if ( tb.attachEvent ) { 205 tb.attachEvent( 'onclick', onclick ); 206 207 if ( wrap ) { 208 wrap.attachEvent( 'onclick', setActiveEditor ); 209 } 210 } 211 212 t.getButton = function(id) { 213 return t.theButtons[id]; 214 }; 215 216 t.getButtonElement = function(id) { 217 return document.getElementById(name + '_' + id); 218 }; 219 220 t.init = function() { 221 _domReady( function(){ qt._buttonsInit( id ); } ); 222 }; 223 224 t.remove = function() { 225 delete qt.instances[id]; 226 227 if ( tb && tb.parentNode ) { 228 tb.parentNode.removeChild( tb ); 229 } 230 }; 231 232 qt.instances[id] = t; 233 t.init(); 234 }; 235 236 /** 237 * Escapes HTML special characters in a string. 238 * 239 * @param {string} text The string to escape. 240 * @return {string} The escaped string. 241 */ 242 function _escape( text ) { 243 text = text || ''; 244 text = text.replace( /&([^#])(?![a-z1-4]{1,8};)/gi, '&$1' ); 245 return text.replace( /</g, '<' ).replace( />/g, '>' ).replace( /"/g, '"' ).replace( /'/g, ''' ); 246 } 247 248 qt.instances = {}; 249 250 qt.getInstance = function(id) { 251 return qt.instances[id]; 252 }; 253 254 qt._buttonsInit = function( id ) { 255 var t = this; 256 257 /** 258 * Initializes the Quicktags buttons for a specific instance. 259 * 260 * @param {string} instanceId The ID of the Quicktags instance to initialize buttons for. 261 */ 262 function _init( instanceId ) { 263 var canvas, name, settings, theButtons, html, ed, id, i, use, 264 defaults = ',strong,em,link,block,del,ins,img,ul,ol,li,code,more,close,'; 265 266 ed = t.instances[instanceId]; 267 canvas = ed.canvas; 268 name = ed.name; 269 settings = ed.settings; 270 html = ''; 271 theButtons = {}; 272 use = ''; 273 274 // Set buttons. 275 if ( settings.buttons ) { 276 use = ','+settings.buttons+','; 277 } 278 279 for ( i in edButtons ) { 280 if ( ! edButtons[i] ) { 281 continue; 282 } 283 284 id = edButtons[i].id; 285 if ( use && defaults.indexOf( ',' + id + ',' ) !== -1 && use.indexOf( ',' + id + ',' ) === -1 ) { 286 continue; 287 } 288 289 if ( ! edButtons[i].instance || edButtons[i].instance === instanceId ) { 290 theButtons[id] = edButtons[i]; 291 292 if ( edButtons[i].html ) { 293 html += edButtons[i].html( name + '_' ); 294 } 295 } 296 } 297 298 if ( use && use.indexOf(',dfw,') !== -1 ) { 299 theButtons.dfw = new qt.DFWButton(); 300 html += theButtons.dfw.html( name + '_' ); 301 } 302 303 if ( 'rtl' === document.getElementsByTagName( 'html' )[0].dir ) { 304 theButtons.textdirection = new qt.TextDirectionButton(); 305 html += theButtons.textdirection.html( name + '_' ); 306 } 307 308 ed.toolbar.innerHTML = html; 309 ed.theButtons = theButtons; 310 311 if ( typeof jQuery !== 'undefined' ) { 312 jQuery( document ).triggerHandler( 'quicktags-init', [ ed ] ); 313 } 314 } 315 316 if ( id ) { 317 _init( id ); 318 } else { 319 for ( id in t.instances ) { 320 _init( id ); 321 } 322 } 323 324 t.buttonsInitDone = true; 325 }; 326 327 /** 328 * Main API function for adding a button to Quicktags 329 * 330 * Adds qt.Button or qt.TagButton depending on the args. The first three args are always required. 331 * To be able to add button(s) to Quicktags, your script should be enqueued as dependent 332 * on "quicktags" and outputted in the footer. If you are echoing JS directly from PHP, 333 * use add_action( 'admin_print_footer_scripts', 'output_my_js', 100 ) or add_action( 'wp_footer', 'output_my_js', 100 ) 334 * 335 * Minimum required to add a button that calls an external function: 336 * QTags.addButton( 'my_id', 'my button', my_callback ); 337 * function my_callback() { alert('yeah!'); } 338 * 339 * Minimum required to add a button that inserts a tag: 340 * QTags.addButton( 'my_id', 'my button', '<span>', '</span>' ); 341 * QTags.addButton( 'my_id2', 'my button', '<br />' ); 342 * 343 * @param {string} id Required. Button HTML ID 344 * @param {string} display Required. Button's value="..." 345 * @param {string|Function} arg1 Required. Either a starting tag to be inserted like "<span>" or a callback that is executed when the button is clicked. 346 * @param {string} arg2 Optional. Ending tag like "</span>" 347 * @param {string} [access_key] Deprecated Not used 348 * @param {string} [title] Optional. Button's title="..." 349 * @param {number} [priority] Optional. Number representing the desired position of the button in the toolbar. 1 - 9 = first, 11 - 19 = second, 21 - 29 = third, etc. 350 * @param {string} [instance] Optional. Limit the button to a specific instance of Quicktags, add to all instances if not present. 351 * @param {Object} [attr] Optional. Used to pass additional attributes. Currently supports `ariaLabel` and `ariaLabelClose` (for "close tag" state) 352 * @return {void|Object} Returns the button object if priority is -1, otherwise returns void. 353 */ 354 qt.addButton = function( id, display, arg1, arg2, access_key, title, priority, instance, attr ) { 355 var btn; 356 357 if ( !id || !display ) { 358 return; 359 } 360 361 priority = priority || 0; 362 arg2 = arg2 || ''; 363 attr = attr || {}; 364 365 if ( typeof(arg1) === 'function' ) { 366 btn = new qt.Button( id, display, access_key, title, instance, attr ); 367 btn.callback = arg1; 368 } else if ( typeof(arg1) === 'string' ) { 369 btn = new qt.TagButton( id, display, arg1, arg2, access_key, title, instance, attr ); 370 } else { 371 return; 372 } 373 374 if ( priority === -1 ) { // Back-compat. 375 return btn; 376 } 377 378 if ( priority > 0 ) { 379 while ( typeof(edButtons[priority]) !== 'undefined' ) { 380 priority++; 381 } 382 383 edButtons[priority] = btn; 384 } else { 385 edButtons[edButtons.length] = btn; 386 } 387 388 if ( this.buttonsInitDone ) { 389 this._buttonsInit(); // Add the button HTML to all instances toolbars if addButton() was called too late. 390 } 391 }; 392 393 qt.insertContent = function(content) { 394 var sel, startPos, endPos, scrollTop, text, canvas = document.getElementById(wpActiveEditor), event; 395 396 if ( !canvas ) { 397 return false; 398 } 399 400 if ( document.selection ) { // IE. 401 canvas.focus(); 402 sel = document.selection.createRange(); 403 sel.text = content; 404 canvas.focus(); 405 } else if ( canvas.selectionStart || canvas.selectionStart === 0 ) { // FF, WebKit, Opera. 406 text = canvas.value; 407 startPos = canvas.selectionStart; 408 endPos = canvas.selectionEnd; 409 scrollTop = canvas.scrollTop; 410 411 canvas.value = text.substring(0, startPos) + content + text.substring(endPos, text.length); 412 413 canvas.selectionStart = startPos + content.length; 414 canvas.selectionEnd = startPos + content.length; 415 canvas.scrollTop = scrollTop; 416 canvas.focus(); 417 } else { 418 canvas.value += content; 419 canvas.focus(); 420 } 421 422 if ( document.createEvent ) { 423 event = document.createEvent( 'HTMLEvents' ); 424 event.initEvent( 'change', false, true ); 425 canvas.dispatchEvent( event ); 426 } else if ( canvas.fireEvent ) { 427 canvas.fireEvent( 'onchange' ); 428 } 429 430 return true; 431 }; 432 433 // A plain, dumb button. 434 qt.Button = function( id, display, access, title, instance, attr ) { 435 this.id = id; 436 this.display = display; 437 this.access = ''; 438 this.title = title || ''; 439 this.instance = instance || ''; 440 this.attr = attr || {}; 441 }; 442 qt.Button.prototype.html = function(idPrefix) { 443 var active, on, wp, 444 title = this.title ? ' title="' + _escape( this.title ) + '"' : '', 445 ariaLabel = this.attr && this.attr.ariaLabel ? ' aria-label="' + _escape( this.attr.ariaLabel ) + '"' : '', 446 val = this.display ? ' value="' + _escape( this.display ) + '"' : '', 447 id = this.id ? ' id="' + _escape( idPrefix + this.id ) + '"' : '', 448 dfw = ( wp = window.wp ) && wp.editor && wp.editor.dfw; 449 450 if ( this.id === 'fullscreen' ) { 451 return '<button type="button"' + id + ' class="ed_button qt-dfw qt-fullscreen"' + title + ariaLabel + '></button>'; 452 } else if ( this.id === 'dfw' ) { 453 active = dfw && dfw.isActive() ? '' : ' disabled="disabled"'; 454 on = dfw && dfw.isOn() ? ' active' : ''; 455 456 return '<button type="button"' + id + ' class="ed_button qt-dfw' + on + '"' + title + ariaLabel + active + '></button>'; 457 } 458 459 return '<input type="button"' + id + ' class="ed_button button button-small"' + title + ariaLabel + val + ' />'; 460 }; 461 qt.Button.prototype.callback = function(){}; 462 463 // A button that inserts HTML tag. 464 qt.TagButton = function( id, display, tagStart, tagEnd, access, title, instance, attr ) { 465 var t = this; 466 qt.Button.call( t, id, display, access, title, instance, attr ); 467 t.tagStart = tagStart; 468 t.tagEnd = tagEnd; 469 }; 470 qt.TagButton.prototype = new qt.Button(); 471 qt.TagButton.prototype.openTag = function( element, ed ) { 472 if ( ! ed.openTags ) { 473 ed.openTags = []; 474 } 475 476 if ( this.tagEnd ) { 477 ed.openTags.push( this.id ); 478 element.value = '/' + element.value; 479 480 if ( this.attr.ariaLabelClose ) { 481 element.setAttribute( 'aria-label', this.attr.ariaLabelClose ); 482 } 483 } 484 }; 485 qt.TagButton.prototype.closeTag = function( element, ed ) { 486 var i = this.isOpen(ed); 487 488 if ( i !== false ) { 489 ed.openTags.splice( i, 1 ); 490 } 491 492 element.value = this.display; 493 494 if ( this.attr.ariaLabel ) { 495 element.setAttribute( 'aria-label', this.attr.ariaLabel ); 496 } 497 }; 498 // Whether a tag is open or not. Returns false if not open, or current open depth of the tag. 499 qt.TagButton.prototype.isOpen = function (ed) { 500 var t = this, i = 0, ret = false; 501 if ( ed.openTags ) { 502 while ( ret === false && i < ed.openTags.length ) { 503 ret = ed.openTags[i] === t.id ? i : false; 504 i ++; 505 } 506 } else { 507 ret = false; 508 } 509 return ret; 510 }; 511 qt.TagButton.prototype.callback = function(element, canvas, ed) { 512 var t = this, startPos, endPos, cursorPos, scrollTop, v = canvas.value, l, r, i, sel, endTag = v ? t.tagEnd : '', event; 513 514 if ( document.selection ) { // IE. 515 canvas.focus(); 516 sel = document.selection.createRange(); 517 if ( sel.text.length > 0 ) { 518 if ( !t.tagEnd ) { 519 sel.text = sel.text + t.tagStart; 520 } else { 521 sel.text = t.tagStart + sel.text + endTag; 522 } 523 } else { 524 if ( !t.tagEnd ) { 525 sel.text = t.tagStart; 526 } else if ( t.isOpen(ed) === false ) { 527 sel.text = t.tagStart; 528 t.openTag(element, ed); 529 } else { 530 sel.text = endTag; 531 t.closeTag(element, ed); 532 } 533 } 534 canvas.focus(); 535 } else if ( canvas.selectionStart || canvas.selectionStart === 0 ) { // FF, WebKit, Opera. 536 startPos = canvas.selectionStart; 537 endPos = canvas.selectionEnd; 538 539 if ( startPos < endPos && v.charAt( endPos - 1 ) === '\n' ) { 540 endPos -= 1; 541 } 542 543 cursorPos = endPos; 544 scrollTop = canvas.scrollTop; 545 l = v.substring(0, startPos); // Left of the selection. 546 r = v.substring(endPos, v.length); // Right of the selection. 547 i = v.substring(startPos, endPos); // Inside the selection. 548 if ( startPos !== endPos ) { 549 if ( !t.tagEnd ) { 550 canvas.value = l + i + t.tagStart + r; // Insert self-closing tags after the selection. 551 cursorPos += t.tagStart.length; 552 } else { 553 canvas.value = l + t.tagStart + i + endTag + r; 554 cursorPos += t.tagStart.length + endTag.length; 555 } 556 } else { 557 if ( !t.tagEnd ) { 558 canvas.value = l + t.tagStart + r; 559 cursorPos = startPos + t.tagStart.length; 560 } else if ( t.isOpen(ed) === false ) { 561 canvas.value = l + t.tagStart + r; 562 t.openTag(element, ed); 563 cursorPos = startPos + t.tagStart.length; 564 } else { 565 canvas.value = l + endTag + r; 566 cursorPos = startPos + endTag.length; 567 t.closeTag(element, ed); 568 } 569 } 570 571 canvas.selectionStart = cursorPos; 572 canvas.selectionEnd = cursorPos; 573 canvas.scrollTop = scrollTop; 574 canvas.focus(); 575 } else { // Other browsers? 576 if ( !endTag ) { 577 canvas.value += t.tagStart; 578 } else if ( t.isOpen(ed) !== false ) { 579 canvas.value += t.tagStart; 580 t.openTag(element, ed); 581 } else { 582 canvas.value += endTag; 583 t.closeTag(element, ed); 584 } 585 canvas.focus(); 586 } 587 588 if ( document.createEvent ) { 589 event = document.createEvent( 'HTMLEvents' ); 590 event.initEvent( 'change', false, true ); 591 canvas.dispatchEvent( event ); 592 } else if ( canvas.fireEvent ) { 593 canvas.fireEvent( 'onchange' ); 594 } 595 }; 596 597 // Removed. 598 qt.SpellButton = function() {}; 599 600 // The close tags button. 601 qt.CloseButton = function() { 602 qt.Button.call( this, 'close', quicktagsL10n.closeTags, '', quicktagsL10n.closeAllOpenTags ); 603 }; 604 605 qt.CloseButton.prototype = new qt.Button(); 606 607 qt._close = function(e, c, ed) { 608 var button, element, tbo = ed.openTags; 609 610 if ( tbo ) { 611 while ( tbo.length > 0 ) { 612 button = ed.getButton(tbo[tbo.length - 1]); 613 element = document.getElementById(ed.name + '_' + button.id); 614 615 if ( e ) { 616 button.callback.call(button, element, c, ed); 617 } else { 618 button.closeTag(element, ed); 619 } 620 } 621 } 622 }; 623 624 qt.CloseButton.prototype.callback = qt._close; 625 626 qt.closeAllTags = function( editor_id ) { 627 var ed = this.getInstance( editor_id ); 628 629 if ( ed ) { 630 qt._close( '', ed.canvas, ed ); 631 } 632 }; 633 634 // The link button. 635 qt.LinkButton = function() { 636 var attr = { 637 ariaLabel: quicktagsL10n.link 638 }; 639 640 qt.TagButton.call( this, 'link', 'link', '', '</a>', '', '', '', attr ); 641 }; 642 qt.LinkButton.prototype = new qt.TagButton(); 643 qt.LinkButton.prototype.callback = function(e, c, ed, defaultValue) { 644 var URL, t = this; 645 646 if ( typeof wpLink !== 'undefined' ) { 647 wpLink.open( ed.id ); 648 return; 649 } 650 651 if ( ! defaultValue ) { 652 defaultValue = 'http://'; 653 } 654 655 if ( t.isOpen(ed) === false ) { 656 URL = prompt( quicktagsL10n.enterURL, defaultValue ); 657 if ( URL ) { 658 t.tagStart = '<a href="' + URL + '">'; 659 qt.TagButton.prototype.callback.call(t, e, c, ed); 660 } 661 } else { 662 qt.TagButton.prototype.callback.call(t, e, c, ed); 663 } 664 }; 665 666 // The img button. 667 qt.ImgButton = function() { 668 var attr = { 669 ariaLabel: quicktagsL10n.image 670 }; 671 672 qt.TagButton.call( this, 'img', 'img', '', '', '', '', '', attr ); 673 }; 674 qt.ImgButton.prototype = new qt.TagButton(); 675 qt.ImgButton.prototype.callback = function(e, c, ed, defaultValue) { 676 if ( ! defaultValue ) { 677 defaultValue = 'http://'; 678 } 679 var src = prompt(quicktagsL10n.enterImageURL, defaultValue), alt; 680 if ( src ) { 681 alt = prompt(quicktagsL10n.enterImageDescription, ''); 682 this.tagStart = '<img src="' + src + '" alt="' + alt + '" />'; 683 qt.TagButton.prototype.callback.call(this, e, c, ed); 684 } 685 }; 686 687 qt.DFWButton = function() { 688 qt.Button.call( this, 'dfw', '', 'f', quicktagsL10n.dfw ); 689 }; 690 qt.DFWButton.prototype = new qt.Button(); 691 qt.DFWButton.prototype.callback = function() { 692 var wp; 693 694 if ( ! ( wp = window.wp ) || ! wp.editor || ! wp.editor.dfw ) { 695 return; 696 } 697 698 window.wp.editor.dfw.toggle(); 699 }; 700 701 qt.TextDirectionButton = function() { 702 qt.Button.call( this, 'textdirection', quicktagsL10n.textdirection, '', quicktagsL10n.toggleTextdirection ); 703 }; 704 qt.TextDirectionButton.prototype = new qt.Button(); 705 qt.TextDirectionButton.prototype.callback = function(e, c) { 706 var isRTL = ( 'rtl' === document.getElementsByTagName('html')[0].dir ), 707 currentDirection = c.style.direction; 708 709 if ( ! currentDirection ) { 710 currentDirection = ( isRTL ) ? 'rtl' : 'ltr'; 711 } 712 713 c.style.direction = ( 'rtl' === currentDirection ) ? 'ltr' : 'rtl'; 714 c.focus(); 715 }; 716 717 // Ensure backward compatibility. 718 edButtons[10] = new qt.TagButton( 'strong', 'b', '<strong>', '</strong>', '', '', '', { ariaLabel: quicktagsL10n.strong, ariaLabelClose: quicktagsL10n.strongClose } ); 719 edButtons[20] = new qt.TagButton( 'em', 'i', '<em>', '</em>', '', '', '', { ariaLabel: quicktagsL10n.em, ariaLabelClose: quicktagsL10n.emClose } ); 720 edButtons[30] = new qt.LinkButton(); // Special case. 721 edButtons[40] = new qt.TagButton( 'block', 'b-quote', '\n\n<blockquote>', '</blockquote>\n\n', '', '', '', { ariaLabel: quicktagsL10n.blockquote, ariaLabelClose: quicktagsL10n.blockquoteClose } ); 722 edButtons[50] = new qt.TagButton( 'del', 'del', '<del datetime="' + _datetime + '">', '</del>', '', '', '', { ariaLabel: quicktagsL10n.del, ariaLabelClose: quicktagsL10n.delClose } ); 723 edButtons[60] = new qt.TagButton( 'ins', 'ins', '<ins datetime="' + _datetime + '">', '</ins>', '', '', '', { ariaLabel: quicktagsL10n.ins, ariaLabelClose: quicktagsL10n.insClose } ); 724 edButtons[70] = new qt.ImgButton(); // Special case. 725 edButtons[80] = new qt.TagButton( 'ul', 'ul', '<ul>\n', '</ul>\n\n', '', '', '', { ariaLabel: quicktagsL10n.ul, ariaLabelClose: quicktagsL10n.ulClose } ); 726 edButtons[90] = new qt.TagButton( 'ol', 'ol', '<ol>\n', '</ol>\n\n', '', '', '', { ariaLabel: quicktagsL10n.ol, ariaLabelClose: quicktagsL10n.olClose } ); 727 edButtons[100] = new qt.TagButton( 'li', 'li', '\t<li>', '</li>\n', '', '', '', { ariaLabel: quicktagsL10n.li, ariaLabelClose: quicktagsL10n.liClose } ); 728 edButtons[110] = new qt.TagButton( 'code', 'code', '<code>', '</code>', '', '', '', { ariaLabel: quicktagsL10n.code, ariaLabelClose: quicktagsL10n.codeClose } ); 729 edButtons[120] = new qt.TagButton( 'more', 'more', '<!--more-->\n\n', '', '', '', '', { ariaLabel: quicktagsL10n.more } ); 730 edButtons[140] = new qt.CloseButton(); 731 732 })(); 733 734 /** 735 * Initialize new instance of the Quicktags editor 736 * 737 * @param {Object} settings The settings for the Quicktags editor. 738 * @return {Object} The Quicktags editor instance. 739 */ 740 window.quicktags = function(settings) { 741 return new window.QTags(settings); 742 }; 743 744 /** 745 * Inserts content at the caret in the active editor (textarea). 746 * 747 * Added for back compatibility 748 * @param {string} bah The ID of the textarea. 749 * @param {string} txt The content to insert. 750 * @see QTags.insertContent() 751 * @return {boolean} True if the content was inserted, false otherwise. 752 */ 753 window.edInsertContent = function(bah, txt) { 754 return window.QTags.insertContent(txt); 755 }; 756 757 /** 758 * Adds a button to all instances of the editor. 759 * 760 * Added for back compatibility, use QTags.addButton() as it gives more flexibility like type of button, button placement, etc. 761 * @param {string} id The ID of the button. 762 * @param {string} display The display text of the button. 763 * @param {string} tagStart The starting tag. 764 * @param {string} tagEnd The ending tag. 765 * @param {string} access The access key for the button. 766 * @see QTags.addButton() 767 * @return {void|Object} Returns the button object if priority is -1, otherwise returns void. 768 */ 769 window.edButton = function(id, display, tagStart, tagEnd, access) { 770 return window.QTags.addButton( id, display, tagStart, tagEnd, access, '', -1 ); 771 };
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| Generated : Wed Sep 16 08:20:31 2026 | Cross-referenced by PHPXref |