]> scripts.mit.edu Git - autoinstalls/wordpress.git/blob - wp-includes/js/quicktags.js
Wordpress 4.6-scripts
[autoinstalls/wordpress.git] / wp-includes / js / quicktags.js
1 /* global adminpage, wpActiveEditor, quicktagsL10n, wpLink, prompt */
2 /*
3  * Quicktags
4  *
5  * This is the HTML editor in WordPress. It can be attached to any textarea and will
6  * append a toolbar above it. This script is self-contained (does not require external libraries).
7  *
8  * Run quicktags(settings) to initialize it, where settings is an object containing up to 3 properties:
9  * settings = {
10  *   id : 'my_id',          the HTML ID of the textarea, required
11  *   buttons: ''            Comma separated list of the names of the default buttons to show. Optional.
12  *                          Current list of default button names: 'strong,em,link,block,del,ins,img,ul,ol,li,code,more,close';
13  * }
14  *
15  * The settings can also be a string quicktags_id.
16  *
17  * quicktags_id string The ID of the textarea that will be the editor canvas
18  * buttons string Comma separated list of the default buttons names that will be shown in that instance.
19  */
20
21 // new edit toolbar used with permission
22 // by Alex King
23 // http://www.alexking.org/
24
25 var QTags, edCanvas,
26         edButtons = [];
27
28 /* jshint ignore:start */
29
30 /**
31  * Back-compat
32  *
33  * Define all former global functions so plugins that hack quicktags.js directly don't cause fatal errors.
34  */
35 var edAddTag = function(){},
36 edCheckOpenTags = function(){},
37 edCloseAllTags = function(){},
38 edInsertImage = function(){},
39 edInsertLink = function(){},
40 edInsertTag = function(){},
41 edLink = function(){},
42 edQuickLink = function(){},
43 edRemoveTag = function(){},
44 edShowButton = function(){},
45 edShowLinks = function(){},
46 edSpell = function(){},
47 edToolbar = function(){};
48
49 /**
50  * Initialize new instance of the Quicktags editor
51  */
52 function quicktags(settings) {
53         return new QTags(settings);
54 }
55
56 /**
57  * Inserts content at the caret in the active editor (textarea)
58  *
59  * Added for back compatibility
60  * @see QTags.insertContent()
61  */
62 function edInsertContent(bah, txt) {
63         return QTags.insertContent(txt);
64 }
65
66 /**
67  * Adds a button to all instances of the editor
68  *
69  * Added for back compatibility, use QTags.addButton() as it gives more flexibility like type of button, button placement, etc.
70  * @see QTags.addButton()
71  */
72 function edButton(id, display, tagStart, tagEnd, access) {
73         return QTags.addButton( id, display, tagStart, tagEnd, access, '', -1 );
74 }
75
76 /* jshint ignore:end */
77
78 (function(){
79         // private stuff is prefixed with an underscore
80         var _domReady = function(func) {
81                 var t, i, DOMContentLoaded, _tryReady;
82
83                 if ( typeof jQuery !== 'undefined' ) {
84                         jQuery(document).ready(func);
85                 } else {
86                         t = _domReady;
87                         t.funcs = [];
88
89                         t.ready = function() {
90                                 if ( ! t.isReady ) {
91                                         t.isReady = true;
92                                         for ( i = 0; i < t.funcs.length; i++ ) {
93                                                 t.funcs[i]();
94                                         }
95                                 }
96                         };
97
98                         if ( t.isReady ) {
99                                 func();
100                         } else {
101                                 t.funcs.push(func);
102                         }
103
104                         if ( ! t.eventAttached ) {
105                                 if ( document.addEventListener ) {
106                                         DOMContentLoaded = function(){document.removeEventListener('DOMContentLoaded', DOMContentLoaded, false);t.ready();};
107                                         document.addEventListener('DOMContentLoaded', DOMContentLoaded, false);
108                                         window.addEventListener('load', t.ready, false);
109                                 } else if ( document.attachEvent ) {
110                                         DOMContentLoaded = function(){if (document.readyState === 'complete'){ document.detachEvent('onreadystatechange', DOMContentLoaded);t.ready();}};
111                                         document.attachEvent('onreadystatechange', DOMContentLoaded);
112                                         window.attachEvent('onload', t.ready);
113
114                                         _tryReady = function() {
115                                                 try {
116                                                         document.documentElement.doScroll('left');
117                                                 } catch(e) {
118                                                         setTimeout(_tryReady, 50);
119                                                         return;
120                                                 }
121
122                                                 t.ready();
123                                         };
124                                         _tryReady();
125                                 }
126
127                                 t.eventAttached = true;
128                         }
129                 }
130         },
131
132         _datetime = (function() {
133                 var now = new Date(), zeroise;
134
135                 zeroise = function(number) {
136                         var str = number.toString();
137
138                         if ( str.length < 2 ) {
139                                 str = '0' + str;
140                         }
141
142                         return str;
143                 };
144
145                 return now.getUTCFullYear() + '-' +
146                         zeroise( now.getUTCMonth() + 1 ) + '-' +
147                         zeroise( now.getUTCDate() ) + 'T' +
148                         zeroise( now.getUTCHours() ) + ':' +
149                         zeroise( now.getUTCMinutes() ) + ':' +
150                         zeroise( now.getUTCSeconds() ) +
151                         '+00:00';
152         })(),
153         qt;
154
155         qt = QTags = function(settings) {
156                 if ( typeof(settings) === 'string' ) {
157                         settings = {id: settings};
158                 } else if ( typeof(settings) !== 'object' ) {
159                         return false;
160                 }
161
162                 var t = this,
163                         id = settings.id,
164                         canvas = document.getElementById(id),
165                         name = 'qt_' + id,
166                         tb, onclick, toolbar_id, wrap, setActiveEditor;
167
168                 if ( !id || !canvas ) {
169                         return false;
170                 }
171
172                 t.name = name;
173                 t.id = id;
174                 t.canvas = canvas;
175                 t.settings = settings;
176
177                 if ( id === 'content' && typeof(adminpage) === 'string' && ( adminpage === 'post-new-php' || adminpage === 'post-php' ) ) {
178                         // back compat hack :-(
179                         edCanvas = canvas;
180                         toolbar_id = 'ed_toolbar';
181                 } else {
182                         toolbar_id = name + '_toolbar';
183                 }
184
185                 tb = document.getElementById( toolbar_id );
186
187                 if ( ! tb ) {
188                         tb = document.createElement('div');
189                         tb.id = toolbar_id;
190                         tb.className = 'quicktags-toolbar';
191                 }
192
193                 canvas.parentNode.insertBefore(tb, canvas);
194                 t.toolbar = tb;
195
196                 // listen for click events
197                 onclick = function(e) {
198                         e = e || window.event;
199                         var target = e.target || e.srcElement, visible = target.clientWidth || target.offsetWidth, i;
200
201                         // don't call the callback on pressing the accesskey when the button is not visible
202                         if ( !visible ) {
203                                 return;
204                         }
205
206                         // as long as it has the class ed_button, execute the callback
207                         if ( / ed_button /.test(' ' + target.className + ' ') ) {
208                                 // we have to reassign canvas here
209                                 t.canvas = canvas = document.getElementById(id);
210                                 i = target.id.replace(name + '_', '');
211
212                                 if ( t.theButtons[i] ) {
213                                         t.theButtons[i].callback.call(t.theButtons[i], target, canvas, t);
214                                 }
215                         }
216                 };
217
218                 setActiveEditor = function() {
219                         window.wpActiveEditor = id;
220                 };
221
222                 wrap = document.getElementById( 'wp-' + id + '-wrap' );
223
224                 if ( tb.addEventListener ) {
225                         tb.addEventListener( 'click', onclick, false );
226                         
227                         if ( wrap ) {
228                                 wrap.addEventListener( 'click', setActiveEditor, false );
229                         }
230                 } else if ( tb.attachEvent ) {
231                         tb.attachEvent( 'onclick', onclick );
232
233                         if ( wrap ) {
234                                 wrap.attachEvent( 'onclick', setActiveEditor );
235                         }
236                 }
237
238                 t.getButton = function(id) {
239                         return t.theButtons[id];
240                 };
241
242                 t.getButtonElement = function(id) {
243                         return document.getElementById(name + '_' + id);
244                 };
245
246                 qt.instances[id] = t;
247
248                 if ( ! qt.instances['0'] ) {
249                         qt.instances['0'] = qt.instances[id];
250                         _domReady( function(){ qt._buttonsInit(); } );
251                 }
252         };
253
254         function _escape( text ) {
255                 text = text || '';
256                 text = text.replace( /&([^#])(?![a-z1-4]{1,8};)/gi, '&#038;$1' );
257                 return text.replace( /</g, '&lt;' ).replace( />/g, '&gt;' ).replace( /"/g, '&quot;' ).replace( /'/g, '&#039;' );
258         }
259
260         qt.instances = {};
261
262         qt.getInstance = function(id) {
263                 return qt.instances[id];
264         };
265
266         qt._buttonsInit = function() {
267                 var t = this, canvas, name, settings, theButtons, html, inst, ed, id, i, use,
268                         defaults = ',strong,em,link,block,del,ins,img,ul,ol,li,code,more,close,';
269
270                 for ( inst in t.instances ) {
271                         if ( '0' === inst ) {
272                                 continue;
273                         }
274
275                         ed = t.instances[inst];
276                         canvas = ed.canvas;
277                         name = ed.name;
278                         settings = ed.settings;
279                         html = '';
280                         theButtons = {};
281                         use = '';
282
283                         // set buttons
284                         if ( settings.buttons ) {
285                                 use = ','+settings.buttons+',';
286                         }
287
288                         for ( i in edButtons ) {
289                                 if ( !edButtons[i] ) {
290                                         continue;
291                                 }
292
293                                 id = edButtons[i].id;
294                                 if ( use && defaults.indexOf( ',' + id + ',' ) !== -1 && use.indexOf( ',' + id + ',' ) === -1 ) {
295                                         continue;
296                                 }
297
298                                 if ( !edButtons[i].instance || edButtons[i].instance === inst ) {
299                                         theButtons[id] = edButtons[i];
300
301                                         if ( edButtons[i].html ) {
302                                                 html += edButtons[i].html(name + '_');
303                                         }
304                                 }
305                         }
306
307                         if ( use && use.indexOf(',dfw,') !== -1 ) {
308                                 theButtons.dfw = new qt.DFWButton();
309                                 html += theButtons.dfw.html( name + '_' );
310                         }
311
312                         if ( 'rtl' === document.getElementsByTagName('html')[0].dir ) {
313                                 theButtons.textdirection = new qt.TextDirectionButton();
314                                 html += theButtons.textdirection.html(name + '_');
315                         }
316
317                         ed.toolbar.innerHTML = html;
318                         ed.theButtons = theButtons;
319
320                         if ( typeof jQuery !== 'undefined' ) {
321                                 jQuery( document ).triggerHandler( 'quicktags-init', [ ed ] );
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 int 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 attr object Optional. Used to pass additional attributes. Currently supports `ariaLabel` and `ariaLabelClose` (for "close tag" state)
352          * @return mixed null or the button object that is needed for back-compat.
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);
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                 return true;
422         };
423
424         // a plain, dumb button
425         qt.Button = function( id, display, access, title, instance, attr ) {
426                 this.id = id;
427                 this.display = display;
428                 this.access = '';
429                 this.title = title || '';
430                 this.instance = instance || '';
431                 this.attr = attr || {};
432         };
433         qt.Button.prototype.html = function(idPrefix) {
434                 var active, on, wp,
435                         title = this.title ? ' title="' + _escape( this.title ) + '"' : '',
436                         ariaLabel = this.attr && this.attr.ariaLabel ? ' aria-label="' + _escape( this.attr.ariaLabel ) + '"' : '',
437                         val = this.display ? ' value="' + _escape( this.display ) + '"' : '',
438                         id = this.id ? ' id="' + _escape( idPrefix + this.id ) + '"' : '',
439                         dfw = ( wp = window.wp ) && wp.editor && wp.editor.dfw;
440
441                 if ( this.id === 'fullscreen' ) {
442                         return '<button type="button"' + id + ' class="ed_button qt-dfw qt-fullscreen"' + title + ariaLabel + '></button>';
443                 } else if ( this.id === 'dfw' ) {
444                         active = dfw && dfw.isActive() ? '' : ' disabled="disabled"';
445                         on = dfw && dfw.isOn() ? ' active' : '';
446
447                         return '<button type="button"' + id + ' class="ed_button qt-dfw' + on + '"' + title + ariaLabel + active + '></button>';
448                 }
449
450                 return '<input type="button"' + id + ' class="ed_button button button-small"' + title + ariaLabel + val + ' />';
451         };
452         qt.Button.prototype.callback = function(){};
453
454         // a button that inserts HTML tag
455         qt.TagButton = function( id, display, tagStart, tagEnd, access, title, instance, attr ) {
456                 var t = this;
457                 qt.Button.call( t, id, display, access, title, instance, attr );
458                 t.tagStart = tagStart;
459                 t.tagEnd = tagEnd;
460         };
461         qt.TagButton.prototype = new qt.Button();
462         qt.TagButton.prototype.openTag = function( element, ed ) {
463                 if ( ! ed.openTags ) {
464                         ed.openTags = [];
465                 }
466
467                 if ( this.tagEnd ) {
468                         ed.openTags.push( this.id );
469                         element.value = '/' + element.value;
470
471                         if ( this.attr.ariaLabelClose ) {
472                                 element.setAttribute( 'aria-label', this.attr.ariaLabelClose );
473                         }
474                 }
475         };
476         qt.TagButton.prototype.closeTag = function( element, ed ) {
477                 var i = this.isOpen(ed);
478
479                 if ( i !== false ) {
480                         ed.openTags.splice( i, 1 );
481                 }
482
483                 element.value = this.display;
484
485                 if ( this.attr.ariaLabel ) {
486                         element.setAttribute( 'aria-label', this.attr.ariaLabel );
487                 }
488         };
489         // whether a tag is open or not. Returns false if not open, or current open depth of the tag
490         qt.TagButton.prototype.isOpen = function (ed) {
491                 var t = this, i = 0, ret = false;
492                 if ( ed.openTags ) {
493                         while ( ret === false && i < ed.openTags.length ) {
494                                 ret = ed.openTags[i] === t.id ? i : false;
495                                 i ++;
496                         }
497                 } else {
498                         ret = false;
499                 }
500                 return ret;
501         };
502         qt.TagButton.prototype.callback = function(element, canvas, ed) {
503                 var t = this, startPos, endPos, cursorPos, scrollTop, v = canvas.value, l, r, i, sel, endTag = v ? t.tagEnd : '';
504
505                 if ( document.selection ) { // IE
506                         canvas.focus();
507                         sel = document.selection.createRange();
508                         if ( sel.text.length > 0 ) {
509                                 if ( !t.tagEnd ) {
510                                         sel.text = sel.text + t.tagStart;
511                                 } else {
512                                         sel.text = t.tagStart + sel.text + endTag;
513                                 }
514                         } else {
515                                 if ( !t.tagEnd ) {
516                                         sel.text = t.tagStart;
517                                 } else if ( t.isOpen(ed) === false ) {
518                                         sel.text = t.tagStart;
519                                         t.openTag(element, ed);
520                                 } else {
521                                         sel.text = endTag;
522                                         t.closeTag(element, ed);
523                                 }
524                         }
525                         canvas.focus();
526                 } else if ( canvas.selectionStart || canvas.selectionStart === 0 ) { // FF, WebKit, Opera
527                         startPos = canvas.selectionStart;
528                         endPos = canvas.selectionEnd;
529
530                         if ( startPos < endPos && v.charAt( endPos - 1 ) === '\n' ) {
531                                 endPos -= 1;
532                         }
533
534                         cursorPos = endPos;
535                         scrollTop = canvas.scrollTop;
536                         l = v.substring(0, startPos); // left of the selection
537                         r = v.substring(endPos, v.length); // right of the selection
538                         i = v.substring(startPos, endPos); // inside the selection
539                         if ( startPos !== endPos ) {
540                                 if ( !t.tagEnd ) {
541                                         canvas.value = l + i + t.tagStart + r; // insert self closing tags after the selection
542                                         cursorPos += t.tagStart.length;
543                                 } else {
544                                         canvas.value = l + t.tagStart + i + endTag + r;
545                                         cursorPos += t.tagStart.length + endTag.length;
546                                 }
547                         } else {
548                                 if ( !t.tagEnd ) {
549                                         canvas.value = l + t.tagStart + r;
550                                         cursorPos = startPos + t.tagStart.length;
551                                 } else if ( t.isOpen(ed) === false ) {
552                                         canvas.value = l + t.tagStart + r;
553                                         t.openTag(element, ed);
554                                         cursorPos = startPos + t.tagStart.length;
555                                 } else {
556                                         canvas.value = l + endTag + r;
557                                         cursorPos = startPos + endTag.length;
558                                         t.closeTag(element, ed);
559                                 }
560                         }
561
562                         canvas.selectionStart = cursorPos;
563                         canvas.selectionEnd = cursorPos;
564                         canvas.scrollTop = scrollTop;
565                         canvas.focus();
566                 } else { // other browsers?
567                         if ( !endTag ) {
568                                 canvas.value += t.tagStart;
569                         } else if ( t.isOpen(ed) !== false ) {
570                                 canvas.value += t.tagStart;
571                                 t.openTag(element, ed);
572                         } else {
573                                 canvas.value += endTag;
574                                 t.closeTag(element, ed);
575                         }
576                         canvas.focus();
577                 }
578         };
579
580         // removed
581         qt.SpellButton = function() {};
582
583         // the close tags button
584         qt.CloseButton = function() {
585                 qt.Button.call( this, 'close', quicktagsL10n.closeTags, '', quicktagsL10n.closeAllOpenTags );
586         };
587
588         qt.CloseButton.prototype = new qt.Button();
589
590         qt._close = function(e, c, ed) {
591                 var button, element, tbo = ed.openTags;
592
593                 if ( tbo ) {
594                         while ( tbo.length > 0 ) {
595                                 button = ed.getButton(tbo[tbo.length - 1]);
596                                 element = document.getElementById(ed.name + '_' + button.id);
597
598                                 if ( e ) {
599                                         button.callback.call(button, element, c, ed);
600                                 } else {
601                                         button.closeTag(element, ed);
602                                 }
603                         }
604                 }
605         };
606
607         qt.CloseButton.prototype.callback = qt._close;
608
609         qt.closeAllTags = function(editor_id) {
610                 var ed = this.getInstance(editor_id);
611                 qt._close('', ed.canvas, ed);
612         };
613
614         // the link button
615         qt.LinkButton = function() {
616                 var attr = {
617                         ariaLabel: quicktagsL10n.link
618                 };
619
620                 qt.TagButton.call( this, 'link', 'link', '', '</a>', '', '', '', attr );
621         };
622         qt.LinkButton.prototype = new qt.TagButton();
623         qt.LinkButton.prototype.callback = function(e, c, ed, defaultValue) {
624                 var URL, t = this;
625
626                 if ( typeof wpLink !== 'undefined' ) {
627                         wpLink.open( ed.id );
628                         return;
629                 }
630
631                 if ( ! defaultValue ) {
632                         defaultValue = 'http://';
633                 }
634
635                 if ( t.isOpen(ed) === false ) {
636                         URL = prompt( quicktagsL10n.enterURL, defaultValue );
637                         if ( URL ) {
638                                 t.tagStart = '<a href="' + URL + '">';
639                                 qt.TagButton.prototype.callback.call(t, e, c, ed);
640                         }
641                 } else {
642                         qt.TagButton.prototype.callback.call(t, e, c, ed);
643                 }
644         };
645
646         // the img button
647         qt.ImgButton = function() {
648                 var attr = {
649                         ariaLabel: quicktagsL10n.image
650                 };
651
652                 qt.TagButton.call( this, 'img', 'img', '', '', '', '', '', attr );
653         };
654         qt.ImgButton.prototype = new qt.TagButton();
655         qt.ImgButton.prototype.callback = function(e, c, ed, defaultValue) {
656                 if ( ! defaultValue ) {
657                         defaultValue = 'http://';
658                 }
659                 var src = prompt(quicktagsL10n.enterImageURL, defaultValue), alt;
660                 if ( src ) {
661                         alt = prompt(quicktagsL10n.enterImageDescription, '');
662                         this.tagStart = '<img src="' + src + '" alt="' + alt + '" />';
663                         qt.TagButton.prototype.callback.call(this, e, c, ed);
664                 }
665         };
666
667         qt.DFWButton = function() {
668                 qt.Button.call( this, 'dfw', '', 'f', quicktagsL10n.dfw );
669         };
670         qt.DFWButton.prototype = new qt.Button();
671         qt.DFWButton.prototype.callback = function() {
672                 var wp;
673
674                 if ( ! ( wp = window.wp ) || ! wp.editor || ! wp.editor.dfw ) {
675                         return;
676                 }
677
678                 window.wp.editor.dfw.toggle();
679         };
680
681         qt.TextDirectionButton = function() {
682                 qt.Button.call( this, 'textdirection', quicktagsL10n.textdirection, '', quicktagsL10n.toggleTextdirection );
683         };
684         qt.TextDirectionButton.prototype = new qt.Button();
685         qt.TextDirectionButton.prototype.callback = function(e, c) {
686                 var isRTL = ( 'rtl' === document.getElementsByTagName('html')[0].dir ),
687                         currentDirection = c.style.direction;
688
689                 if ( ! currentDirection ) {
690                         currentDirection = ( isRTL ) ? 'rtl' : 'ltr';
691                 }
692
693                 c.style.direction = ( 'rtl' === currentDirection ) ? 'ltr' : 'rtl';
694                 c.focus();
695         };
696
697         // ensure backward compatibility
698         edButtons[10]  = new qt.TagButton( 'strong', 'b', '<strong>', '</strong>', '', '', '', { ariaLabel: quicktagsL10n.strong, ariaLabelClose: quicktagsL10n.strongClose } );
699         edButtons[20]  = new qt.TagButton( 'em', 'i', '<em>', '</em>', '', '', '', { ariaLabel: quicktagsL10n.em, ariaLabelClose: quicktagsL10n.emClose } );
700         edButtons[30]  = new qt.LinkButton(); // special case
701         edButtons[40]  = new qt.TagButton( 'block', 'b-quote', '\n\n<blockquote>', '</blockquote>\n\n', '', '', '', { ariaLabel: quicktagsL10n.blockquote, ariaLabelClose: quicktagsL10n.blockquoteClose } );
702         edButtons[50]  = new qt.TagButton( 'del', 'del', '<del datetime="' + _datetime + '">', '</del>', '', '', '', { ariaLabel: quicktagsL10n.del, ariaLabelClose: quicktagsL10n.delClose } );
703         edButtons[60]  = new qt.TagButton( 'ins', 'ins', '<ins datetime="' + _datetime + '">', '</ins>', '', '', '', { ariaLabel: quicktagsL10n.ins, ariaLabelClose: quicktagsL10n.insClose } );
704         edButtons[70]  = new qt.ImgButton(); // special case
705         edButtons[80]  = new qt.TagButton( 'ul', 'ul', '<ul>\n', '</ul>\n\n', '', '', '', { ariaLabel: quicktagsL10n.ul, ariaLabelClose: quicktagsL10n.ulClose } );
706         edButtons[90]  = new qt.TagButton( 'ol', 'ol', '<ol>\n', '</ol>\n\n', '', '', '', { ariaLabel: quicktagsL10n.ol, ariaLabelClose: quicktagsL10n.olClose } );
707         edButtons[100] = new qt.TagButton( 'li', 'li', '\t<li>', '</li>\n', '', '', '', { ariaLabel: quicktagsL10n.li, ariaLabelClose: quicktagsL10n.liClose } );
708         edButtons[110] = new qt.TagButton( 'code', 'code', '<code>', '</code>', '', '', '', { ariaLabel: quicktagsL10n.code, ariaLabelClose: quicktagsL10n.codeClose } );
709         edButtons[120] = new qt.TagButton( 'more', 'more', '<!--more-->\n\n', '', '', '', '', { ariaLabel: quicktagsL10n.more } );
710         edButtons[140] = new qt.CloseButton();
711
712 })();