r61222 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r61221‎ | r61222 | r61223 >
Date:23:20, 18 January 2010
Author:catrope
Status:deferred
Tags:
Comment:
UsabilityInitiative: Implement encapsulateSelection() for IE
Modified paths:
  • /trunk/extensions/UsabilityInitiative/UsabilityInitiative.hooks.php (modified) (history)
  • /trunk/extensions/UsabilityInitiative/js/plugins.combined.js (modified) (history)
  • /trunk/extensions/UsabilityInitiative/js/plugins.combined.min.js (modified) (history)
  • /trunk/extensions/UsabilityInitiative/js/plugins/jquery.wikiEditor.js (modified) (history)

Diff [purge]

Index: trunk/extensions/UsabilityInitiative/UsabilityInitiative.hooks.php
@@ -153,7 +153,7 @@
154154 array(
155155 'src' => 'js/plugins/jquery.wikiEditor.js',
156156 'class' => 'j.wikiEditor',
157 - 'version' => 49
 157+ 'version' => 50
158158 ),
159159 array(
160160 'src' => 'js/plugins/jquery.wikiEditor.highlight.js',
@@ -191,10 +191,10 @@
192192 'version' => 1 ),
193193 ),
194194 'combined' => array(
195 - array( 'src' => 'js/plugins.combined.js', 'version' => 149 ),
 195+ array( 'src' => 'js/plugins.combined.js', 'version' => 150 ),
196196 ),
197197 'minified' => array(
198 - array( 'src' => 'js/plugins.combined.min.js', 'version' => 149 ),
 198+ array( 'src' => 'js/plugins.combined.min.js', 'version' => 150 ),
199199 ),
200200 ),
201201 );
Index: trunk/extensions/UsabilityInitiative/js/plugins/jquery.wikiEditor.js
@@ -474,7 +474,35 @@
475475 context.fn.scrollToTop( lastNode );
476476 }
477477 } else if ( context.$iframe[0].contentWindow.document.selection ) {
478 - // TODO: IE
 478+ // IE
 479+ context.$iframe[0].contentWindow.focus();
 480+ var range = context.$iframe[0].contentWindow.document.selection.createRange();
 481+ if ( options.ownline && range.moveStart ) {
 482+ // Check if we're at the start of a line
 483+ // If not, prepend a newline
 484+ var range2 = document.selection.createRange();
 485+ range2.collapse();
 486+ range2.moveStart( 'character', -1 );
 487+ // FIXME: Which check is correct?
 488+ if ( range2.text != "\r" && range2.text != "\n" && range2.text != "" ) {
 489+ pre = "\n" + pre;
 490+ }
 491+
 492+ // Check if we're at the end of a line
 493+ // If not, append a newline
 494+ var range3 = document.selection.createRange();
 495+ range3.collapse( false );
 496+ range3.moveEnd( 'character', 1 );
 497+ if ( range3.text != "\r" && range3.text != "\n" && range3.text != "" ) {
 498+ post += "\n";
 499+ }
 500+ }
 501+ // TODO: Maybe find a more elegant way of doing this like the Firefox code above?
 502+ range.pasteHTML( ( pre + selText + post )
 503+ .replace( /\</g, '&lt;' )
 504+ .replace( />/g, '&gt;' )
 505+ .replace( /\r?\n/g, '<br />' )
 506+ );
479507 }
480508 // Trigger the encapsulateSelection event (this might need to get named something else/done differently)
481509 context.$content.trigger(
Index: trunk/extensions/UsabilityInitiative/js/plugins.combined.js
@@ -6836,7 +6836,35 @@
68376837 context.fn.scrollToTop( lastNode );
68386838 }
68396839 } else if ( context.$iframe[0].contentWindow.document.selection ) {
6840 - // TODO: IE
 6840+ // IE
 6841+ context.$iframe[0].contentWindow.focus();
 6842+ var range = context.$iframe[0].contentWindow.document.selection.createRange();
 6843+ if ( options.ownline && range.moveStart ) {
 6844+ // Check if we're at the start of a line
 6845+ // If not, prepend a newline
 6846+ var range2 = document.selection.createRange();
 6847+ range2.collapse();
 6848+ range2.moveStart( 'character', -1 );
 6849+ // FIXME: Which check is correct?
 6850+ if ( range2.text != "\r" && range2.text != "\n" && range2.text != "" ) {
 6851+ pre = "\n" + pre;
 6852+ }
 6853+
 6854+ // Check if we're at the end of a line
 6855+ // If not, append a newline
 6856+ var range3 = document.selection.createRange();
 6857+ range3.collapse( false );
 6858+ range3.moveEnd( 'character', 1 );
 6859+ if ( range3.text != "\r" && range3.text != "\n" && range3.text != "" ) {
 6860+ post += "\n";
 6861+ }
 6862+ }
 6863+ // TODO: Maybe find a more elegant way of doing this like the Firefox code above?
 6864+ range.pasteHTML( ( pre + selText + post )
 6865+ .replace( /\</g, '&lt;' )
 6866+ .replace( />/g, '&gt;' )
 6867+ .replace( /\r?\n/g, '<br />' )
 6868+ );
68416869 }
68426870 // Trigger the encapsulateSelection event (this might need to get named something else/done differently)
68436871 context.$content.trigger(
Index: trunk/extensions/UsabilityInitiative/js/plugins.combined.min.js
@@ -449,7 +449,9 @@
450450 if(context.$iframe[0].contentWindow.getSelection){var range=context.$iframe[0].contentWindow.getSelection().getRangeAt(0);if(options.ownline){if(range.startOffset!=0){pre="\n"+options.pre;}
451451 if(range.endContainer==range.commonAncestorContainer){post+="\n";}}
452452 var insertText=pre+selText+post;var insertLines=insertText.split("\n");range.extractContents();var lastNode;for(var i=insertLines.length-1;i>=0;i--){range.insertNode(document.createTextNode(insertLines[i]));if(i>0){lastNode=range.insertNode(document.createElement('br'));}}
453 -if(lastNode){context.fn.scrollToTop(lastNode);}}else if(context.$iframe[0].contentWindow.document.selection){}
 453+if(lastNode){context.fn.scrollToTop(lastNode);}}else if(context.$iframe[0].contentWindow.document.selection){context.$iframe[0].contentWindow.focus();var range=context.$iframe[0].contentWindow.document.selection.createRange();if(options.ownline&&range.moveStart){var range2=document.selection.createRange();range2.collapse();range2.moveStart('character',-1);if(range2.text!="\r"&&range2.text!="\n"&&range2.text!=""){pre="\n"+pre;}
 454+var range3=document.selection.createRange();range3.collapse(false);range3.moveEnd('character',1);if(range3.text!="\r"&&range3.text!="\n"&&range3.text!=""){post+="\n";}}
 455+range.pasteHTML((pre+selText+post).replace(/\</g,'&lt;').replace(/>/g,'&gt;').replace(/\r?\n/g,'<br />'));}
454456 context.$content.trigger('encapsulateSelection',[pre,options.peri,post,options.ownline,options.replace]);return context.$textarea;},'getCaretPosition':function(options){},'setSelection':function(options){var sc=options.startContainer,ec=options.endContainer;sc=sc.jquery?sc[0]:sc;ec=ec.jquery?ec[0]:ec;if(context.$iframe[0].contentWindow.getSelection){var sel=context.$iframe[0].contentWindow.getSelection();while(sc.firstChild&&sc.nodeName!='#text'){sc=sc.firstChild;}
455457 while(ec.firstChild&&ec.nodeName!='#text'){ec=ec.firstChild;}
456458 var range=document.createRange();range.setStart(sc,options.start);range.setEnd(ec,options.end);sel.removeAllRanges();sel.addRange(range);context.$iframe[0].contentWindow.focus();}else if(context.$iframe[0].contentWindow.document.body.createTextRange){var range=context.$iframe[0].contentWindow.document.body.createTextRange();range.moveToElementText(sc);range.moveStart('character',options.start);var range2=context.$iframe[0].contentWindow.document.body.createTextRange();range2.moveToElementText(ec);range2.collapse();range2.moveEnd('character',options.end);range.setEndPoint('EndToEnd',range2);range.select();}},'scrollToCaretPosition':function(options){},'scrollToTop':function($element,force){var html=context.$content.closest('html'),body=context.$content.closest('body'),parent=$('html');var y=$element.offset().top-context.$content.offset().top;y=parent.scrollTop()>0?y+html.scrollTop()-parent.scrollTop():y;if(force||y<html.scrollTop()||y>html.scrollTop()+context.$iframe.height()){html.scrollTop(y);}

Status & tagging log