Ticket #31661: 31661.3.patch
| File 31661.3.patch, 5.7 KB (added by , 11 years ago) |
|---|
-
src/wp-includes/js/quicktags.js
150 150 zeroise( now.getUTCSeconds() ) + 151 151 '+00:00'; 152 152 })(), 153 qt; 153 qt, 154 keyboardSelection = false; 154 155 155 156 qt = QTags = function(settings) { 156 157 if ( typeof(settings) === 'string' ) { … … 220 221 tb.attachEvent('onclick', onclick); 221 222 } 222 223 224 if ( canvas.addEventListener ) { 225 canvas.addEventListener( 'keydown', function(event) { 226 qt.OnTab(event, this); 227 }, false ); 228 } else if ( canvas.attachEvent ) { 229 canvas.attachEvent( 'onkeydown', function(event) { 230 qt.OnTab(event, this); 231 } ); 232 } 233 223 234 t.getButton = function(id) { 224 235 return t.theButtons[id]; 225 236 }; … … 243 254 }; 244 255 245 256 qt._buttonsInit = function() { 246 var t = this, canvas, name, settings, theButtons, html, inst, ed, id, i, use, 257 var t = this, canvas, name, settings, theButtons, html, inst, ed, id, i, use, closeAllButton, 247 258 defaults = ',strong,em,link,block,del,ins,img,ul,ol,li,code,more,close,'; 248 259 249 260 for ( inst in t.instances ) { … … 294 305 } 295 306 296 307 ed.toolbar.innerHTML = html; 308 309 // Disable the Close All button on init. 310 closeAllButton = document.getElementById( ed.name + '_' + theButtons.close.id ); 311 if ( closeAllButton ) { 312 closeAllButton.setAttribute( 'disabled', 'disabled' ); 313 } 314 297 315 ed.theButtons = theButtons; 298 316 299 317 if ( typeof jQuery !== 'undefined' ) { … … 434 452 }; 435 453 qt.TagButton.prototype = new qt.Button(); 436 454 qt.TagButton.prototype.openTag = function(e, ed) { 437 var t = this; 455 var t = this, 456 closeAllButton = document.getElementById( ed.name + '_' + ed.theButtons.close.id ); 438 457 458 // Enable the Close All button now that we have open tags. 459 if ( closeAllButton ) { 460 closeAllButton.removeAttribute( 'disabled' ); 461 } 462 439 463 if ( ! ed.openTags ) { 440 464 ed.openTags = []; 441 465 } 466 442 467 if ( t.tagEnd ) { 443 468 ed.openTags.push(t.id); 444 469 e.value = '/' + e.value; … … 445 470 } 446 471 }; 447 472 qt.TagButton.prototype.closeTag = function(e, ed) { 448 var t = this, i = t.isOpen(ed); 473 var t = this, i = t.isOpen(ed), 474 closeAllButton = document.getElementById( ed.name + '_' + ed.theButtons.close.id ); 449 475 450 476 if ( i !== false ) { 451 477 ed.openTags.splice(i, 1); 452 478 } 453 479 480 // Disable the Close All button when there are no more open tags. 481 if ( 0 === i && closeAllButton ) { 482 closeAllButton.setAttribute( 'disabled', 'disabled' ); 483 } 484 // Handle focus when the Close All button gets disabled. 485 ed.canvas.focus(); 486 454 487 e.value = t.display; 455 488 }; 456 489 // whether a tag is open or not. Returns false if not open, or current open depth of the tag … … 469 502 qt.TagButton.prototype.callback = function(element, canvas, ed) { 470 503 var t = this, startPos, endPos, cursorPos, scrollTop, v = canvas.value, l, r, i, sel, endTag = v ? t.tagEnd : ''; 471 504 472 if ( document.selection ) { // IE 473 canvas.focus(); 474 sel = document.selection.createRange(); 475 if ( sel.text.length > 0 ) { 476 if ( !t.tagEnd ) { 477 sel.text = sel.text + t.tagStart; 478 } else { 479 sel.text = t.tagStart + sel.text + endTag; 480 } 481 } else { 482 if ( !t.tagEnd ) { 483 sel.text = t.tagStart; 484 } else if ( t.isOpen(ed) === false ) { 485 sel.text = t.tagStart; 486 t.openTag(element, ed); 487 } else { 488 sel.text = endTag; 489 t.closeTag(element, ed); 490 } 505 if ( canvas.selectionStart || canvas.selectionStart === 0 ) { // FF, WebKit, Opera, IE9+ 506 507 // Check if there has been a keyboard selection 508 // reverse tabbing doesn't always make canvas.selectionStart available 509 if ( keyboardSelection ) { 510 startPos = keyboardSelection[0]; 511 endPos = keyboardSelection[1]; 512 // Reset it right away, no need for it from here 513 keyboardSelection = false; 514 } else { 515 startPos = canvas.selectionStart; 516 endPos = canvas.selectionEnd; 491 517 } 492 canvas.focus(); 493 } else if ( canvas.selectionStart || canvas.selectionStart === 0 ) { // FF, WebKit, Opera 494 startPos = canvas.selectionStart; 495 endPos = canvas.selectionEnd; 518 496 519 cursorPos = endPos; 497 520 scrollTop = canvas.scrollTop; 498 521 l = v.substring(0, startPos); // left of the selection … … 525 548 canvas.selectionEnd = cursorPos; 526 549 canvas.scrollTop = scrollTop; 527 550 canvas.focus(); 551 } else if ( document.selection ) { // IE8 552 canvas.focus(); 553 // Check if we already have an IE keyboard selection first. 554 sel = keyboardSelection || document.selection.createRange(); 555 556 if ( sel.text.length > 0 ) { 557 if ( !t.tagEnd ) { 558 sel.text = sel.text + t.tagStart; 559 } else { 560 sel.text = t.tagStart + sel.text + endTag; 561 } 562 } else { 563 if ( !t.tagEnd ) { 564 sel.text = t.tagStart; 565 } else if ( t.isOpen(ed) === false ) { 566 sel.text = t.tagStart; 567 t.openTag(element, ed); 568 } else { 569 sel.text = endTag; 570 t.closeTag(element, ed); 571 } 572 } 573 // Reset IE keyboard selection 574 keyboardSelection = false; 575 canvas.focus(); 528 576 } else { // other browsers? 529 577 if ( !endTag ) { 530 578 canvas.value += t.tagStart; … … 539 587 } 540 588 }; 541 589 590 // IE keyboard selection: get and store the selection when reverse tabbing. 591 qt.OnTab = function( event, canvas ) { 592 var key; 593 594 if ( ( document.selection || document.getSelection() ) && 'keydown' === event.type ) { 595 key = event.keyCode || event.charCode; 596 if ( event.shiftKey && 9 === key ) { 597 598 if ( canvas.selectionStart || canvas.selectionStart === 0 ) { 599 keyboardSelection = [canvas.selectionStart, canvas.selectionEnd]; 600 } else if ( document.selection ) { 601 keyboardSelection = document.selection.createRange(); 602 } 603 604 } 605 } 606 }; 607 542 608 // removed 543 609 qt.SpellButton = function() {}; 544 610