Changeset 26212
- Timestamp:
- 11/15/2013 02:25:29 PM (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/js/quicktags.js
r24490 r26212 1 /* global adminpage, wpActiveEditor, quicktagsL10n, wpLink, fullscreen, prompt */ 1 2 /* 2 3 * Quicktags … … 22 23 // http://www.alexking.org/ 23 24 24 var QTags, edButtons = [], edCanvas, 25 var QTags, edCanvas, 26 edButtons = []; 27 28 /* jshint ignore:start */ 25 29 26 30 /** … … 29 33 * Define all former global functions so plugins that hack quicktags.js directly don't cause fatal errors. 30 34 */ 31 edAddTag = function(){},35 var edAddTag = function(){}, 32 36 edCheckOpenTags = function(){}, 33 37 edCloseAllTags = function(){}, … … 66 70 * @see QTags.addButton() 67 71 */ 68 function edButton(id, display, tagStart, tagEnd, access , open) {72 function edButton(id, display, tagStart, tagEnd, access) { 69 73 return QTags.addButton( id, display, tagStart, tagEnd, access, '', -1 ); 70 74 } 75 76 /* jshint ignore:end */ 71 77 72 78 (function(){ 73 79 // private stuff is prefixed with an underscore 74 80 var _domReady = function(func) { 75 var t, i, DOMContentLoaded;76 77 if ( typeof jQuery != 'undefined' ) {81 var t, i, DOMContentLoaded, _tryReady; 82 83 if ( typeof jQuery !== 'undefined' ) { 78 84 jQuery(document).ready(func); 79 85 } else { … … 106 112 window.attachEvent('onload', t.ready); 107 113 108 (function(){114 _tryReady = function() { 109 115 try { 110 document.documentElement.doScroll( "left");116 document.documentElement.doScroll('left'); 111 117 } catch(e) { 112 setTimeout( arguments.callee, 50);118 setTimeout(_tryReady, 50); 113 119 return; 114 120 } 115 121 116 122 t.ready(); 117 })(); 123 }; 124 _tryReady(); 118 125 } 119 126 … … 129 136 var str = number.toString(); 130 137 131 if ( str.length < 2 ) 132 str = "0" + str; 138 if ( str.length < 2 ) { 139 str = '0' + str; 140 } 133 141 134 142 return str; 135 } 143 }; 136 144 137 145 return now.getUTCFullYear() + '-' + … … 146 154 147 155 qt = QTags = function(settings) { 148 if ( typeof(settings) == 'string' )156 if ( typeof(settings) === 'string' ) { 149 157 settings = {id: settings}; 150 else if ( typeof(settings) != 'object' )158 } else if ( typeof(settings) !== 'object' ) { 151 159 return false; 160 } 152 161 153 162 var t = this, … … 157 166 tb, onclick, toolbar_id; 158 167 159 if ( !id || !canvas ) 168 if ( !id || !canvas ) { 160 169 return false; 170 } 161 171 162 172 t.name = name; … … 165 175 t.settings = settings; 166 176 167 if ( id == 'content' && typeof(adminpage) == 'string' && ( adminpage == 'post-new-php' || adminpage== 'post-php' ) ) {177 if ( id === 'content' && typeof(adminpage) === 'string' && ( adminpage === 'post-new-php' || adminpage === 'post-php' ) ) { 168 178 // back compat hack :-( 169 179 edCanvas = canvas; … … 186 196 187 197 // don't call the callback on pressing the accesskey when the button is not visible 188 if ( !visible ) 198 if ( !visible ) { 189 199 return; 200 } 190 201 191 202 // as long as it has the class ed_button, execute the callback … … 195 206 i = target.id.replace(name + '_', ''); 196 207 197 if ( t.theButtons[i] ) 208 if ( t.theButtons[i] ) { 198 209 t.theButtons[i].callback.call(t.theButtons[i], target, canvas, t); 210 } 199 211 } 200 212 }; … … 233 245 234 246 for ( inst in t.instances ) { 235 if ( inst == 0 )247 if ( inst === 0 ) { 236 248 continue; 249 } 237 250 238 251 ed = t.instances[inst]; … … 245 258 246 259 // set buttons 247 if ( settings.buttons ) 260 if ( settings.buttons ) { 248 261 use = ','+settings.buttons+','; 262 } 249 263 250 264 for ( i in edButtons ) { 251 if ( !edButtons[i] ) 265 if ( !edButtons[i] ) { 252 266 continue; 267 } 253 268 254 269 id = edButtons[i].id; 255 if ( use && defaults.indexOf( ','+id+',') != -1 && use.indexOf(','+id+',') == -1 )270 if ( use && defaults.indexOf( ',' + id + ',' ) !== -1 && use.indexOf( ',' + id + ',' ) === -1 ) { 256 271 continue; 257 258 if ( !edButtons[i].instance || edButtons[i].instance == inst ) { 272 } 273 274 if ( !edButtons[i].instance || edButtons[i].instance === inst ) { 259 275 theButtons[id] = edButtons[i]; 260 276 261 if ( edButtons[i].html ) 277 if ( edButtons[i].html ) { 262 278 html += edButtons[i].html(name + '_'); 263 } 264 } 265 266 if ( use && use.indexOf(',fullscreen,') != -1 ) { 267 theButtons['fullscreen'] = new qt.FullscreenButton(); 268 html += theButtons['fullscreen'].html(name + '_'); 269 } 270 271 272 if ( 'rtl' == document.getElementsByTagName('html')[0].dir ) { 273 theButtons['textdirection'] = new qt.TextDirectionButton(); 274 html += theButtons['textdirection'].html(name + '_'); 279 } 280 } 281 } 282 283 if ( use && use.indexOf(',fullscreen,') !== -1 ) { 284 theButtons.fullscreen = new qt.FullscreenButton(); 285 html += theButtons.fullscreen.html(name + '_'); 286 } 287 288 289 if ( 'rtl' === document.getElementsByTagName('html')[0].dir ) { 290 theButtons.textdirection = new qt.TextDirectionButton(); 291 html += theButtons.textdirection.html(name + '_'); 275 292 } 276 293 … … 310 327 var btn; 311 328 312 if ( !id || !display ) 329 if ( !id || !display ) { 313 330 return; 331 } 314 332 315 333 priority = priority || 0; … … 325 343 } 326 344 327 if ( priority == -1 )// back-compat345 if ( priority === -1 ) { // back-compat 328 346 return btn; 347 } 329 348 330 349 if ( priority > 0 ) { 331 while ( typeof(edButtons[priority]) != 'undefined' ) {332 priority++ 350 while ( typeof(edButtons[priority]) !== 'undefined' ) { 351 priority++; 333 352 } 334 353 … … 338 357 } 339 358 340 if ( this.buttonsInitDone ) 359 if ( this.buttonsInitDone ) { 341 360 this._buttonsInit(); // add the button HTML to all instances toolbars if addButton() was called too late 361 } 342 362 }; 343 363 … … 345 365 var sel, startPos, endPos, scrollTop, text, canvas = document.getElementById(wpActiveEditor); 346 366 347 if ( !canvas ) 367 if ( !canvas ) { 348 368 return false; 369 } 349 370 350 371 if ( document.selection ) { //IE … … 353 374 sel.text = content; 354 375 canvas.focus(); 355 } else if ( canvas.selectionStart || canvas.selectionStart == '0' ) { // FF, WebKit, Opera376 } else if ( canvas.selectionStart || canvas.selectionStart === '0' ) { // FF, WebKit, Opera 356 377 text = canvas.value; 357 378 startPos = canvas.selectionStart; … … 420 441 if ( ed.openTags ) { 421 442 while ( ret === false && i < ed.openTags.length ) { 422 ret = ed.openTags[i] == t.id ? i : false;443 ret = ed.openTags[i] === t.id ? i : false; 423 444 i ++; 424 445 } … … 435 456 sel = document.selection.createRange(); 436 457 if ( sel.text.length > 0 ) { 437 if ( !t.tagEnd ) 458 if ( !t.tagEnd ) { 438 459 sel.text = sel.text + t.tagStart; 439 else460 } else { 440 461 sel.text = t.tagStart + sel.text + endTag; 462 } 441 463 } else { 442 464 if ( !t.tagEnd ) { … … 451 473 } 452 474 canvas.focus(); 453 } else if ( canvas.selectionStart || canvas.selectionStart == '0' ) { // FF, WebKit, Opera475 } else if ( canvas.selectionStart || canvas.selectionStart === '0' ) { // FF, WebKit, Opera 454 476 startPos = canvas.selectionStart; 455 477 endPos = canvas.selectionEnd; … … 459 481 r = v.substring(endPos, v.length); // right of the selection 460 482 i = v.substring(startPos, endPos); // inside the selection 461 if ( startPos != endPos ) {483 if ( startPos !== endPos ) { 462 484 if ( !t.tagEnd ) { 463 485 canvas.value = l + i + t.tagStart + r; // insert self closing tags after the selection … … 518 540 element = document.getElementById(ed.name + '_' + button.id); 519 541 520 if ( e ) 542 if ( e ) { 521 543 button.callback.call(button, element, c, ed); 522 else544 } else { 523 545 button.closeTag(element, ed); 546 } 524 547 } 525 548 } … … 541 564 var URL, t = this; 542 565 543 if ( typeof(wpLink) != 'undefined' ) {566 if ( typeof(wpLink) !== 'undefined' ) { 544 567 wpLink.open(); 545 568 return; 546 569 } 547 570 548 if ( ! defaultValue ) 571 if ( ! defaultValue ) { 549 572 defaultValue = 'http://'; 573 } 550 574 551 575 if ( t.isOpen(ed) === false ) { … … 582 606 qt.FullscreenButton.prototype = new qt.Button(); 583 607 qt.FullscreenButton.prototype.callback = function(e, c) { 584 if ( !c.id || typeof(fullscreen) == 'undefined' )608 if ( !c.id || typeof(fullscreen) === 'undefined' ) { 585 609 return; 610 } 586 611 587 612 fullscreen.on(); … … 589 614 590 615 qt.TextDirectionButton = function() { 591 qt.Button.call(this, 'textdirection', quicktagsL10n.textdirection, '', quicktagsL10n.toggleTextdirection) 616 qt.Button.call(this, 'textdirection', quicktagsL10n.textdirection, '', quicktagsL10n.toggleTextdirection); 592 617 }; 593 618 qt.TextDirectionButton.prototype = new qt.Button(); 594 619 qt.TextDirectionButton.prototype.callback = function(e, c) { 595 var isRTL = ( 'rtl' == document.getElementsByTagName('html')[0].dir ),620 var isRTL = ( 'rtl' === document.getElementsByTagName('html')[0].dir ), 596 621 currentDirection = c.style.direction; 597 622 598 if ( ! currentDirection ) 623 if ( ! currentDirection ) { 599 624 currentDirection = ( isRTL ) ? 'rtl' : 'ltr'; 600 601 c.style.direction = ( 'rtl' == currentDirection ) ? 'ltr' : 'rtl'; 625 } 626 627 c.style.direction = ( 'rtl' === currentDirection ) ? 'ltr' : 'rtl'; 602 628 c.focus(); 603 } 629 }; 604 630 605 631 // ensure backward compatibility … … 616 642 edButtons[110] = new qt.TagButton('code','code','<code>','</code>','c'), 617 643 edButtons[120] = new qt.TagButton('more','more','<!--more-->','','t'), 618 edButtons[140] = new qt.CloseButton() 644 edButtons[140] = new qt.CloseButton(); 619 645 620 646 })();
Note: See TracChangeset
for help on using the changeset viewer.