Ticket #31661: 31661.2.patch
File 31661.2.patch, 4.7 KB (added by , 6 years ago) |
---|
-
src/wp-includes/js/quicktags.js
150 150 zeroise( now.getUTCSeconds() ) + 151 151 '+00:00'; 152 152 })(), 153 qt; 153 qt, 154 keyboardSelectionIE = 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', qt.OnTab, false ); 226 } else if ( canvas.attachEvent ) { 227 canvas.attachEvent( 'onkeydown', qt.OnTab ); 228 } 229 223 230 t.getButton = function(id) { 224 231 return t.theButtons[id]; 225 232 }; … … 243 250 }; 244 251 245 252 qt._buttonsInit = function() { 246 var t = this, canvas, name, settings, theButtons, html, inst, ed, id, i, use, 253 var t = this, canvas, name, settings, theButtons, html, inst, ed, id, i, use, closeAllButton, 247 254 defaults = ',strong,em,link,block,del,ins,img,ul,ol,li,code,more,close,'; 248 255 249 256 for ( inst in t.instances ) { … … 299 306 } 300 307 301 308 ed.toolbar.innerHTML = html; 309 310 // Disable the Close All button on init. 311 closeAllButton = document.getElementById( ed.name + '_' + theButtons.close.id ); 312 if ( closeAllButton ) { 313 closeAllButton.setAttribute( 'disabled', 'disabled' ); 314 } 315 302 316 ed.theButtons = theButtons; 303 317 304 318 if ( typeof jQuery !== 'undefined' ) { … … 439 453 }; 440 454 qt.TagButton.prototype = new qt.Button(); 441 455 qt.TagButton.prototype.openTag = function(e, ed) { 442 var t = this; 456 var t = this, 457 closeAllButton = document.getElementById( ed.name + '_' + ed.theButtons.close.id ); 443 458 459 // Enable the Close All button now that we have open tags. 460 if ( closeAllButton ) { 461 closeAllButton.removeAttribute( 'disabled' ); 462 } 463 444 464 if ( ! ed.openTags ) { 445 465 ed.openTags = []; 446 466 } 467 447 468 if ( t.tagEnd ) { 448 469 ed.openTags.push(t.id); 449 470 e.value = '/' + e.value; … … 450 471 } 451 472 }; 452 473 qt.TagButton.prototype.closeTag = function(e, ed) { 453 var t = this, i = t.isOpen(ed); 474 var t = this, i = t.isOpen(ed), 475 closeAllButton = document.getElementById( ed.name + '_' + ed.theButtons.close.id ); 454 476 455 477 if ( i !== false ) { 456 478 ed.openTags.splice(i, 1); 457 479 } 458 480 481 // Disable the Close All button when there are no more open tags. 482 if ( 0 === i && closeAllButton ) { 483 closeAllButton.setAttribute( 'disabled', 'disabled' ); 484 } 485 // Handle focus when the Close All button gets disabled. 486 ed.canvas.focus(); 487 459 488 e.value = t.display; 460 489 }; 461 490 // whether a tag is open or not. Returns false if not open, or current open depth of the tag … … 476 505 477 506 if ( document.selection ) { // IE 478 507 canvas.focus(); 479 sel = document.selection.createRange(); 508 // Check if we already have an IE keyboard selection first. 509 sel = keyboardSelectionIE || document.selection.createRange(); 480 510 if ( sel.text.length > 0 ) { 481 511 if ( !t.tagEnd ) { 482 512 sel.text = sel.text + t.tagStart; … … 494 524 t.closeTag(element, ed); 495 525 } 496 526 } 527 // Reset IE keyboard selection 528 keyboardSelectionIE = false; 497 529 canvas.focus(); 498 } else if ( canvas.selectionStart || canvas.selectionStart === 0 ) { // FF, WebKit, Opera 499 startPos = canvas.selectionStart; 500 endPos = canvas.selectionEnd; 530 } else if ( canvas.selectionStart || canvas.selectionStart === 0 ) { // FF, WebKit, Opera, IE11 531 // Check if there has been a keyboard selection, because IE11 is weird 532 if ( keyboardSelectionIE ) { 533 startPos = keyboardSelectionIE[0]; 534 endPos = keyboardSelectionIE[1]; 535 // Reset it right away, no need for it from here 536 keyboardSelectionIE = false; 537 } else { 538 startPos = canvas.selectionStart; 539 endPos = canvas.selectionEnd; 540 } 501 541 cursorPos = endPos; 502 542 scrollTop = canvas.scrollTop; 503 543 l = v.substring(0, startPos); // left of the selection … … 544 584 } 545 585 }; 546 586 587 // IE keyboard selection: get and store the selection when reverse tabbing. 588 qt.OnTab = function( event ) { 589 var key; 590 591 if ( ( document.selection || document.getSelection() ) && 'keydown' === event.type ) { 592 key = event.keyCode || event.charCode; 593 if ( event.shiftKey && 9 === key ) { 594 // IE11 supports getSelection like other modern browsers, but doesn't seem to return anything for textarea selections 595 // So store start and end of selection instead 596 if ( window.getSelection ) { 597 selection = [this.selectionStart, this.selectionEnd]; 598 } else if ( document.getSelection ) { 599 selection = document.getSelection() + ''; 600 } else if ( document.selection ) { 601 selection = document.selection.createRange().text || ''; 602 } 603 keyboardSelectionIE = selection; 604 } 605 } 606 }; 607 547 608 // removed 548 609 qt.SpellButton = function() {}; 549 610