Ticket #31661: 31661.debug.patch
| File 31661.debug.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 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 … … 474 503 qt.TagButton.prototype.callback = function(element, canvas, ed) { 475 504 var t = this, startPos, endPos, cursorPos, scrollTop, v = canvas.value, l, r, i, sel, endTag = v ? t.tagEnd : ''; 476 505 506 // debug 507 if ( document.selection ) { 508 sel = keyboardSelectionIE || document.selection.createRange(); 509 window.console.log( 'Your browser supports document.selection and at this point the selected text is: ' + sel.text ); 510 } 511 if ( canvas.selectionStart || canvas.selectionStart === 0 ) { 512 var selText1 = (canvas.value).substring(canvas.selectionStart,canvas.selectionEnd); 513 window.console.log( 'Your browser supports selectionStart and selectionEnd and at this point the selected text starts at ' + canvas.selectionStart + ' and ends at ' + canvas.selectionEnd + ' the selected text is: ' + selText1); 514 } 515 if ( window.getSelection ) { 516 var selectionRange = window.getSelection(), 517 selText2 = selectionRange.toString(); 518 window.console.log( 'Your browser supports window.getSelection() and at this point the selected text is: ' + selText2 ); 519 } 520 477 521 if ( document.selection ) { // IE 478 522 canvas.focus(); 479 sel = document.selection.createRange(); 523 // Check if we already have an IE keyboard selection first. 524 sel = keyboardSelectionIE || document.selection.createRange(); 480 525 if ( sel.text.length > 0 ) { 481 526 if ( !t.tagEnd ) { 482 527 sel.text = sel.text + t.tagStart; … … 494 539 t.closeTag(element, ed); 495 540 } 496 541 } 542 // Reset IE keyboard selection 543 keyboardSelectionIE = false; 497 544 canvas.focus(); 498 545 } else if ( canvas.selectionStart || canvas.selectionStart === 0 ) { // FF, WebKit, Opera 499 546 startPos = canvas.selectionStart; … … 544 591 } 545 592 }; 546 593 594 // IE keyboard selection: get and store the selection when reverse tabbing. 595 qt.OnTab = function( event ) { 596 var target = event.target || event.srcElement, 597 key = event.keyCode, 598 ed = qt.getInstance( target.id ), 599 canvas = document.getElementById(target.id); 600 601 if ( document.selection && 'keydown' === event.type ) { 602 if ( event.shiftKey && 9 === key ) { 603 keyboardSelectionIE = document.selection.createRange(); 604 } 605 } 606 607 // debug 608 if ( event.shiftKey && 9 === key ) { 609 if ( document.selection ) { 610 sel = keyboardSelectionIE || document.selection.createRange(); 611 window.console.log( 'Your browser supports document.selection and at this point the selected text is: ' + sel.text ); 612 } 613 if ( canvas.selectionStart || canvas.selectionStart === 0 ) { 614 var selText1 = (canvas.value).substring(canvas.selectionStart,canvas.selectionEnd); 615 window.console.log( 'Your browser supports selectionStart and selectionEnd and at this point the selected text starts at ' + canvas.selectionStart + ' and ends at ' + canvas.selectionEnd + ' the selected text is: ' + selText1); 616 } 617 if ( window.getSelection ) { 618 var selectionRange = window.getSelection(), 619 selText2 = selectionRange.toString(); 620 window.console.log( 'Your browser supports window.getSelection() and at this point the selected text is: ' + selText2 ); 621 } 622 } 623 624 }; 625 547 626 // removed 548 627 qt.SpellButton = function() {}; 549 628