r24042 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r24041‎ | r24042 | r24043 >
Date:17:39, 12 July 2007
Author:brion
Status:old
Tags:
Comment:
* (bug 10526) Fix toolbar/insertTags behavior for IE 6/7 and Opera (8+)
Now matches the selection behavior on Mozilla / Safari.
Patch by Alex Smotrov.
* Don't show non-functional toolbar buttons on Opera 7 anymore

Tested and confirmed expected behavior:
* Firefox 2.0 / Mac
* Opera 9.20 / Mac
* Opera 8.0 / Mac
* Opera 7.5 / Mac (no toolbar)
* Opera 6 / Mac (no toolbar)
* Safari 2.0 / Mac
* Safari 3.0.2 / Win XP
* IE 7.0 / Win XP
* IE 6.0 / Win XP

Tested with oddities:
* iCab 3 / Mac (toolbar displays but nonfunctional; seems to have HTML parsing errors unrelated to the JS work)
Modified paths:
  • /trunk/phase3/RELEASE-NOTES (modified) (history)
  • /trunk/phase3/includes/DefaultSettings.php (modified) (history)
  • /trunk/phase3/skins/common/wikibits.js (modified) (history)

Diff [purge]

Index: trunk/phase3/skins/common/wikibits.js
@@ -373,7 +373,8 @@
374374
375375 // Don't generate buttons for browsers which don't fully
376376 // support it.
377 - if (!document.selection && textbox.selectionStart === null) {
 377+ if (!(document.selection && document.selection.createRange)
 378+ && textbox.selectionStart === null) {
378379 return false;
379380 }
380381
@@ -408,7 +409,6 @@
409410
410411 // apply tagOpen/tagClose to selection in textarea,
411412 // use sampleText instead of selection if there is none
412 -// copied and adapted from phpBB
413413 function insertTags(tagOpen, tagClose, sampleText) {
414414 var txtarea;
415415 if (document.editform) {
@@ -418,62 +418,72 @@
419419 var areas = document.getElementsByTagName('textarea');
420420 txtarea = areas[0];
421421 }
 422+ var selText, isSample = false;
422423
423 - // IE
424 - if (document.selection && !is_gecko) {
425 - var theSelection = document.selection.createRange().text;
426 - if (!theSelection) {
427 - theSelection=sampleText;
428 - }
 424+ if (document.selection && document.selection.createRange) { // IE/Opera
 425+
 426+ //save window scroll position
 427+ if (document.documentElement && document.documentElement.scrollTop)
 428+ var winScroll = document.documentElement.scrollTop
 429+ else if (document.body)
 430+ var winScroll = document.body.scrollTop;
 431+ //get current selection
429432 txtarea.focus();
430 - if (theSelection.charAt(theSelection.length - 1) == " ") { // exclude ending space char, if any
431 - theSelection = theSelection.substring(0, theSelection.length - 1);
432 - document.selection.createRange().text = tagOpen + theSelection + tagClose + " ";
433 - } else {
434 - document.selection.createRange().text = tagOpen + theSelection + tagClose;
 433+ var range = document.selection.createRange();
 434+ selText = range.text;
 435+ //insert tags
 436+ checkSelectedText();
 437+ range.text = tagOpen + selText + tagClose;
 438+ //mark sample text as selected
 439+ if (isSample && range.moveStart) {
 440+ if (window.opera)
 441+ tagClose = tagClose.replace(/\n/g,'');
 442+ range.moveStart('character', - tagClose.length - selText.length);
 443+ range.moveEnd('character', - tagClose.length);
435444 }
 445+ range.select();
 446+ //restore window scroll position
 447+ if (document.documentElement && document.documentElement.scrollTop)
 448+ document.documentElement.scrollTop = winScroll
 449+ else if (document.body)
 450+ document.body.scrollTop = winScroll;
436451
437 - // Mozilla
438 - } else if(txtarea.selectionStart || txtarea.selectionStart == '0') {
439 - var replaced = false;
 452+ } else if (txtarea.selectionStart || txtarea.selectionStart == '0') { // Mozilla
 453+
 454+ //save textarea scroll position
 455+ var textScroll = txtarea.scrollTop;
 456+ //get current selection
 457+ txtarea.focus();
440458 var startPos = txtarea.selectionStart;
441459 var endPos = txtarea.selectionEnd;
442 - if (endPos-startPos) {
443 - replaced = true;
444 - }
445 - var scrollTop = txtarea.scrollTop;
446 - var myText = (txtarea.value).substring(startPos, endPos);
447 - if (!myText) {
448 - myText=sampleText;
449 - }
450 - var subst;
451 - if (myText.charAt(myText.length - 1) == " ") { // exclude ending space char, if any
452 - subst = tagOpen + myText.substring(0, (myText.length - 1)) + tagClose + " ";
453 - } else {
454 - subst = tagOpen + myText + tagClose;
455 - }
456 - txtarea.value = txtarea.value.substring(0, startPos) + subst +
457 - txtarea.value.substring(endPos, txtarea.value.length);
458 - txtarea.focus();
 460+ selText = txtarea.value.substring(startPos, endPos);
 461+ //insert tags
 462+ checkSelectedText();
 463+ txtarea.value = txtarea.value.substring(0, startPos)
 464+ + tagOpen + selText + tagClose
 465+ + txtarea.value.substring(endPos, txtarea.value.length);
459466 //set new selection
460 - if (replaced) {
461 - var cPos = startPos+(tagOpen.length+myText.length+tagClose.length);
462 - txtarea.selectionStart = cPos;
463 - txtarea.selectionEnd = cPos;
 467+ if (isSample) {
 468+ txtarea.selectionStart = startPos + tagOpen.length;
 469+ txtarea.selectionEnd = startPos + tagOpen.length + selText.length;
464470 } else {
465 - txtarea.selectionStart = startPos+tagOpen.length;
466 - txtarea.selectionEnd = startPos+tagOpen.length+myText.length;
 471+ txtarea.selectionStart = startPos + tagOpen.length + selText.length + tagClose.length;
 472+ txtarea.selectionEnd = txtarea.selectionStart;
467473 }
468 - txtarea.scrollTop = scrollTop;
 474+ //restore textarea scroll position
 475+ txtarea.scrollTop = textScroll;
 476+ }
469477
470 - // All other browsers get no toolbar.
471 - // There was previously support for a crippled "help"
472 - // bar, but that caused more problems than it solved.
 478+ function checkSelectedText(){
 479+ if (!selText) {
 480+ selText = sampleText;
 481+ isSample = true;
 482+ } else if (selText.charAt(selText.length - 1) == ' ') { //exclude ending space char
 483+ selText = selText.substring(0, selText.length - 1);
 484+ tagClose += ' '
 485+ }
473486 }
474 - // reposition cursor if possible
475 - if (txtarea.createTextRange) {
476 - txtarea.caretPos = document.selection.createRange().duplicate();
477 - }
 487+
478488 }
479489
480490
Index: trunk/phase3/includes/DefaultSettings.php
@@ -1201,7 +1201,7 @@
12021202 * to ensure that client-side caches don't keep obsolete copies of global
12031203 * styles.
12041204 */
1205 -$wgStyleVersion = '81';
 1205+$wgStyleVersion = '82';
12061206
12071207
12081208 # Server-side caching:
Index: trunk/phase3/RELEASE-NOTES
@@ -281,8 +281,11 @@
282282 * (bug 10552) Suppress rollback link in history for single-revision pages
283283 * (bug 10538) Gracefully handle invalid input on move success page
284284 * Fix for Esperanto double-x-encoding in move success page
 285+* (bug 10526) Fix toolbar/insertTags behavior for IE 6/7 and Opera (8+)
 286+ Now matches the selection behavior on Mozilla / Safari.
 287+ Patch by Alex Smotrov.
 288+* Don't show non-functional toolbar buttons on Opera 7 anymore
285289
286 -
287290 == API changes since 1.10 ==
288291
289292 Full API documentation is available at http://www.mediawiki.org/wiki/API

Follow-up revisions

RevisionCommit summaryAuthorDate
r24096Merged revisions 23910-24094 via svnmerge from...david22:38, 14 July 2007

Status & tagging log