Index: trunk/phase3/skins/common/wikibits.js |
— | — | @@ -373,7 +373,8 @@ |
374 | 374 | |
375 | 375 | // Don't generate buttons for browsers which don't fully |
376 | 376 | // support it. |
377 | | - if (!document.selection && textbox.selectionStart === null) { |
| 377 | + if (!(document.selection && document.selection.createRange) |
| 378 | + && textbox.selectionStart === null) { |
378 | 379 | return false; |
379 | 380 | } |
380 | 381 | |
— | — | @@ -408,7 +409,6 @@ |
409 | 410 | |
410 | 411 | // apply tagOpen/tagClose to selection in textarea, |
411 | 412 | // use sampleText instead of selection if there is none |
412 | | -// copied and adapted from phpBB |
413 | 413 | function insertTags(tagOpen, tagClose, sampleText) { |
414 | 414 | var txtarea; |
415 | 415 | if (document.editform) { |
— | — | @@ -418,62 +418,72 @@ |
419 | 419 | var areas = document.getElementsByTagName('textarea'); |
420 | 420 | txtarea = areas[0]; |
421 | 421 | } |
| 422 | + var selText, isSample = false; |
422 | 423 | |
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 |
429 | 432 | 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); |
435 | 444 | } |
| 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; |
436 | 451 | |
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(); |
440 | 458 | var startPos = txtarea.selectionStart; |
441 | 459 | 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); |
459 | 466 | //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; |
464 | 470 | } 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; |
467 | 473 | } |
468 | | - txtarea.scrollTop = scrollTop; |
| 474 | + //restore textarea scroll position |
| 475 | + txtarea.scrollTop = textScroll; |
| 476 | + } |
469 | 477 | |
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 | + } |
473 | 486 | } |
474 | | - // reposition cursor if possible |
475 | | - if (txtarea.createTextRange) { |
476 | | - txtarea.caretPos = document.selection.createRange().duplicate(); |
477 | | - } |
| 487 | + |
478 | 488 | } |
479 | 489 | |
480 | 490 | |
Index: trunk/phase3/includes/DefaultSettings.php |
— | — | @@ -1201,7 +1201,7 @@ |
1202 | 1202 | * to ensure that client-side caches don't keep obsolete copies of global |
1203 | 1203 | * styles. |
1204 | 1204 | */ |
1205 | | -$wgStyleVersion = '81'; |
| 1205 | +$wgStyleVersion = '82'; |
1206 | 1206 | |
1207 | 1207 | |
1208 | 1208 | # Server-side caching: |
Index: trunk/phase3/RELEASE-NOTES |
— | — | @@ -281,8 +281,11 @@ |
282 | 282 | * (bug 10552) Suppress rollback link in history for single-revision pages |
283 | 283 | * (bug 10538) Gracefully handle invalid input on move success page |
284 | 284 | * 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 |
285 | 289 | |
286 | | - |
287 | 290 | == API changes since 1.10 == |
288 | 291 | |
289 | 292 | Full API documentation is available at http://www.mediawiki.org/wiki/API |