r62154 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r62153‎ | r62154 | r62155 >
Date:01:31, 9 February 2010
Author:tparscal
Status:resolved (Comments)
Tags:
Comment:
Updated to use the textSelection plugin when possible.
Modified paths:
  • /trunk/phase3/skins/common/edit.js (modified) (history)

Diff [purge]

Index: trunk/phase3/skins/common/edit.js
@@ -57,11 +57,15 @@
5858 // No toolbar if we can't find any textarea
5959 return false;
6060 }
61 - if ( !( document.selection && document.selection.createRange )
62 - && textboxes[0].selectionStart === null ) {
63 - return false;
 61+ // Only check for selection capability if the textarea is visible - errors will occur otherwise - just because
 62+ // the textarea is not visible, doesn't mean we shouldn't build out the toolbar though - it might have been replaced
 63+ // with some other kind of control
 64+ if ( textboxes[0].style.display != 'none' ) {
 65+ if ( !( document.selection && document.selection.createRange )
 66+ && textboxes[0].selectionStart === null ) {
 67+ return false;
 68+ }
6469 }
65 -
6670 for ( var i = 0; i < mwEditButtons.length; i++ ) {
6771 mwInsertEditButton( toolbar, mwEditButtons[i] );
6872 }
@@ -74,6 +78,12 @@
7579 // apply tagOpen/tagClose to selection in textarea,
7680 // use sampleText instead of selection if there is none
7781 function insertTags( tagOpen, tagClose, sampleText ) {
 82+ if ( typeof $j.fn.textSelection != 'undefined' ) {
 83+ $j( '#wpTextbox1' ).textSelection(
 84+ 'encapsulateSelection', { 'pre': tagOpen, 'peri': sampleText, 'post': tagClose }
 85+ );
 86+ return;
 87+ }
7888 var txtarea;
7989 if ( document.editform ) {
8090 txtarea = currentFocused;

Follow-up revisions

RevisionCommit summaryAuthorDate
r62186Fix up r62154: don't throw a JS error when $j is undefined, and bump $wgStyle...catrope16:58, 9 February 2010
r62190wmf-deployment: Merge r62154, r62186 from trunk (makes charinsert, old toolba...catrope19:27, 9 February 2010

Comments

#Comment by Catrope (talk | contribs)   14:05, 9 February 2010
+	if ( textboxes[0].style.display != 'none' ) {
+		if ( !( document.selection && document.selection.createRange )
+			&& textboxes[0].selectionStart === null ) {
+			return false;
+		}

Use && instead of nesting if statements like this. && is lazy-evaluated in JavaScript.

+	if ( typeof $j.fn.textSelection != 'undefined' ) {

Does this still work without JS errors if $j is undefined?

#Comment by Catrope (talk | contribs)   14:06, 9 February 2010

This also needs bumping $wgStyleVersion

#Comment by Catrope (talk | contribs)   19:19, 9 February 2010

Addressed both issues in r62186.

Status & tagging log