http://www.mediawiki.org/wiki/Special:Code/MediaWiki/61114

Revision: 61114
Author:   tparscal
Date:     2010-01-15 23:45:41 +0000 (Fri, 15 Jan 2010)

Log Message:
-----------
Finally fixed line break handling for getContents. jQuery's .html() function 
strips whitespace, and so does IE on anything other than a pre tag - so you 
must use $( '<pre>' + whitespace_sensitive_text_and_html + '</pre>' ); to get 
whitespace sensitive text into the dom without stripping.

Modified Paths:
--------------
    trunk/extensions/UsabilityInitiative/UsabilityInitiative.hooks.php
    trunk/extensions/UsabilityInitiative/js/plugins/jquery.textSelection.js
    trunk/extensions/UsabilityInitiative/js/plugins/jquery.wikiEditor.js
    trunk/extensions/UsabilityInitiative/js/plugins.combined.js
    trunk/extensions/UsabilityInitiative/js/plugins.combined.min.js

Modified: trunk/extensions/UsabilityInitiative/UsabilityInitiative.hooks.php
===================================================================
--- trunk/extensions/UsabilityInitiative/UsabilityInitiative.hooks.php  
2010-01-15 23:45:40 UTC (rev 61113)
+++ trunk/extensions/UsabilityInitiative/UsabilityInitiative.hooks.php  
2010-01-15 23:45:41 UTC (rev 61114)
@@ -83,8 +83,8 @@
                                array( 'src' => 'js/plugins/jquery.inherit.js', 
'version' => 3 ),
                                array( 'src' => 
'js/plugins/jquery.namespaceSelect.js', 'version' => 1 ),
                                array( 'src' => 
'js/plugins/jquery.suggestions.js', 'version' => 7 ),
-                               array( 'src' => 
'js/plugins/jquery.textSelection.js', 'version' => 22 ),
-                               array( 'src' => 
'js/plugins/jquery.wikiEditor.js', 'version' => 46 ),
+                               array( 'src' => 
'js/plugins/jquery.textSelection.js', 'version' => 23 ),
+                               array( 'src' => 
'js/plugins/jquery.wikiEditor.js', 'version' => 47 ),
                                array( 'src' => 
'js/plugins/jquery.wikiEditor.highlight.js', 'version' => 12 ),
                                array( 'src' => 
'js/plugins/jquery.wikiEditor.toolbar.js', 'version' => 41 ),
                                array( 'src' => 
'js/plugins/jquery.wikiEditor.dialogs.js', 'version' => 10 ),
@@ -94,10 +94,10 @@
                                array( 'src' => 
'js/plugins/jquery.wikiEditor.publish.js', 'version' => 1 ),
                        ),
                        'combined' => array(
-                               array( 'src' => 'js/plugins.combined.js', 
'version' => 144 ),
+                               array( 'src' => 'js/plugins.combined.js', 
'version' => 145 ),
                        ),
                        'minified' => array(
-                               array( 'src' => 'js/plugins.combined.min.js', 
'version' => 144 ),
+                               array( 'src' => 'js/plugins.combined.min.js', 
'version' => 145 ),
                        ),
                ),
        );

Modified: 
trunk/extensions/UsabilityInitiative/js/plugins/jquery.textSelection.js
===================================================================
--- trunk/extensions/UsabilityInitiative/js/plugins/jquery.textSelection.js     
2010-01-15 23:45:40 UTC (rev 61113)
+++ trunk/extensions/UsabilityInitiative/js/plugins/jquery.textSelection.js     
2010-01-15 23:45:41 UTC (rev 61114)
@@ -10,11 +10,6 @@
 getContents: function() {
        return this.val();
 },
-
-setContents: function( options ) {
-       return this.val( options.contents );
-},
-
 /**
  * Get the currently selected text in this textarea. Will focus the textarea
  * in some browsers (IE/Opera)

Modified: trunk/extensions/UsabilityInitiative/js/plugins/jquery.wikiEditor.js
===================================================================
--- trunk/extensions/UsabilityInitiative/js/plugins/jquery.wikiEditor.js        
2010-01-15 23:45:40 UTC (rev 61113)
+++ trunk/extensions/UsabilityInitiative/js/plugins/jquery.wikiEditor.js        
2010-01-15 23:45:41 UTC (rev 61114)
@@ -384,28 +384,15 @@
                 * Gets the complete contents of the iframe (in plain text, not 
HTML)
                 */
                'getContents': function() {
-                       // FIXME: Evil ua-sniffing action!
-                       if ( $.browser.name == 'msie' ) {
-                               return context.$content.text();
-                       }
                        // We use .html() instead of .text() so HTML entities 
are handled right - setting the HTML of the textarea
                        // doesn't work on all browsers, use a dummy <div> 
instead
-                       var $dummyDiv = $( '<div />' ).html( 
context.$content.html().replace( /\<br[^\>]*\>/g, "\n" ) );
                        // Get rid of the noincludes when getting text
-                       $dummyDiv.find( ".wikiEditor-noinclude" ).each( 
function() { $( this ).remove(); } );
-                       return $dummyDiv.text();
                        
+                       var $pre = $( '<pre>' + 
context.$content.html().replace( /\<br[^\>]*\>/gi, "\n" ) + '</pre>' );
+                       $pre.find( ".wikiEditor-noinclude" ).each( function() { 
$( this ).remove(); } );
+                       return $pre.text();
                },
                /**
-                * Sets the complete contents of the iframe (in plain text, not 
HTML; HTML passed will be converted to entities)
-                * FIXME: Passing in options like this is sort of akward - it 
appears to be a way to make this compatible with
-                * the textSelection plugin - is this needed?
-                */
-               'setContents': function( options ) {
-                       context.$content.text( options.contents );
-                       return context.$textarea;
-               },
-               /**
                 * Gets the currently selected text in the content
                 * DO NOT CALL THESE DIRECTLY, use .textSelection( 
'functionname', options ) instead
                 */

Modified: trunk/extensions/UsabilityInitiative/js/plugins.combined.js
===================================================================
--- trunk/extensions/UsabilityInitiative/js/plugins.combined.js 2010-01-15 
23:45:40 UTC (rev 61113)
+++ trunk/extensions/UsabilityInitiative/js/plugins.combined.js 2010-01-15 
23:45:41 UTC (rev 61114)
@@ -5997,11 +5997,6 @@
 getContents: function() {
        return this.val();
 },
-
-setContents: function( options ) {
-       return this.val( options.contents );
-},
-
 /**
  * Get the currently selected text in this textarea. Will focus the textarea
  * in some browsers (IE/Opera)
@@ -6751,28 +6746,15 @@
                 * Gets the complete contents of the iframe (in plain text, not 
HTML)
                 */
                'getContents': function() {
-                       // FIXME: Evil ua-sniffing action!
-                       if ( $.browser.name == 'msie' ) {
-                               return context.$content.text();
-                       }
                        // We use .html() instead of .text() so HTML entities 
are handled right - setting the HTML of the textarea
                        // doesn't work on all browsers, use a dummy <div> 
instead
-                       var $dummyDiv = $( '<div />' ).html( 
context.$content.html().replace( /\<br[^\>]*\>/g, "\n" ) );
                        // Get rid of the noincludes when getting text
-                       $dummyDiv.find( ".wikiEditor-noinclude" ).each( 
function() { $( this ).remove(); } );
-                       return $dummyDiv.text();
                        
+                       var $pre = $( '<pre>' + 
context.$content.html().replace( /\<br[^\>]*\>/gi, "\n" ) + '</pre>' );
+                       $pre.find( ".wikiEditor-noinclude" ).each( function() { 
$( this ).remove(); } );
+                       return $pre.text();
                },
                /**
-                * Sets the complete contents of the iframe (in plain text, not 
HTML; HTML passed will be converted to entities)
-                * FIXME: Passing in options like this is sort of akward - it 
appears to be a way to make this compatible with
-                * the textSelection plugin - is this needed?
-                */
-               'setContents': function( options ) {
-                       context.$content.text( options.contents );
-                       return context.$textarea;
-               },
-               /**
                 * Gets the currently selected text in the content
                 * DO NOT CALL THESE DIRECTLY, use .textSelection( 
'functionname', options ) instead
                 */

Modified: trunk/extensions/UsabilityInitiative/js/plugins.combined.min.js
===================================================================
--- trunk/extensions/UsabilityInitiative/js/plugins.combined.min.js     
2010-01-15 23:45:40 UTC (rev 61113)
+++ trunk/extensions/UsabilityInitiative/js/plugins.combined.min.js     
2010-01-15 23:45:41 UTC (rev 61114)
@@ -396,7 +396,7 @@
 context.data.$container.hide();if(typeof 
context.config.special.select=='function'){context.config.special.select.call($special,context.data.$textbox);}
 
context.data.$textbox.focus();})).appendTo($('body'));$(this).attr('autocomplete','off').keydown(function(e){context.data.keypressed=(e.keyCode==undefined)?e.which:e.keyCode;context.data.keypressedCount=0;switch(context.data.keypressed){case
 40:e.preventDefault();e.stopImmediatePropagation();break;case 38:case 27:case 
13:if(context.data.$container.is(':visible')){e.preventDefault();e.stopImmediatePropagation();}}}).keypress(function(e){context.data.keypressedCount++;$.suggestions.keypress(e,context,context.data.keypressed);}).keyup(function(e){if(context.data.keypressedCount==0){$.suggestions.keypress(e,context,context.data.keypressed);}}).blur(function(){if(context.data.mouseDownOn.size()>0){return;}
 context.data.$container.hide();$.suggestions.cancel(context);});}
-$(this).data('suggestions-context',context);});return 
returnValue!==null?returnValue:$(this);};})(jQuery);(function($){$.fn.textSelection=function(command,options){var
 fn={getContents:function(){return 
this.val();},setContents:function(options){return 
this.val(options.contents);},getSelection:function(){var e=this.get(0);var 
retval='';if($(e).is(':hidden')){}else 
if(document.selection&&document.selection.createRange){e.focus();var 
range=document.selection.createRange();retval=range.text;}else 
if(e.selectionStart||e.selectionStart=='0'){retval=e.value.substring(e.selectionStart,e.selectionEnd);}
+$(this).data('suggestions-context',context);});return 
returnValue!==null?returnValue:$(this);};})(jQuery);(function($){$.fn.textSelection=function(command,options){var
 fn={getContents:function(){return this.val();},getSelection:function(){var 
e=this.get(0);var retval='';if($(e).is(':hidden')){}else 
if(document.selection&&document.selection.createRange){e.focus();var 
range=document.selection.createRange();retval=range.text;}else 
if(e.selectionStart||e.selectionStart=='0'){retval=e.value.substring(e.selectionStart,e.selectionEnd);}
 return retval;},encapsulateSelection:function(options){return 
this.each(function(){function 
checkSelectedText(){if(!selText){selText=options.peri;isSample=true;}else 
if(options.replace){selText=options.peri;}else 
if(selText.charAt(selText.length-1)==' 
'){selText=selText.substring(0,selText.length-1);options.post+=' ';}}
 var selText=$(this).textSelection('getSelection');var 
isSample=false;if(this.style.display=='none'){}else 
if(this.selectionStart||this.selectionStart=='0'){$(this).focus();var 
startPos=this.selectionStart;var 
endPos=this.selectionEnd;checkSelectedText();if(options.ownline){if(startPos!=0&&this.value.charAt(startPos-1)!="\n"){options.pre="\n"+options.pre;}
 if(this.value.charAt(endPos)!="\n"){options.post+="\n";}}
@@ -443,8 +443,7 @@
 for(module in context.modules){if(module in $.wikiEditor.modules&&'evt'in 
$.wikiEditor.modules[module]&&name in 
$.wikiEditor.modules[module].evt){$.wikiEditor.modules[module].evt[name](context,event);}}},'addButton':function(options){context.$controls.show();context.$buttons.show();return
 $('<button 
/>').text($.wikiEditor.autoMsg(options,'caption')).click(options.action).appendTo(context.$buttons);},'addView':function(options){function
 addTab(options){context.$controls.show();context.$tabs.show();return 
$('<div></div>').attr('rel','wikiEditor-ui-view-'+options.name).addClass(context.view==options.name?'current':null).append($('<a></a>').attr('href','#').click(function(event){context.$ui.find('.wikiEditor-ui-view').hide();context.$ui.find('.'+$(this).parent().attr('rel')).show();context.$tabs.find('div').removeClass('current');$(this).parent().addClass('current');$(this).blur();if('init'in
 options&&typeof options.init=='function'){options.init(context);}
 event.preventDefault();return 
false;}).text($.wikiEditor.autoMsg(options,'title'))).appendTo(context.$tabs);}
 
if(!context.$tabs.children().size()){addTab({'name':'wikitext','titleMsg':'wikieditor-wikitext-tab'});}
-addTab(options);return $('<div></div>').addClass('wikiEditor-ui-view 
wikiEditor-ui-view-'+options.name).hide().appendTo(context.$ui);},'getContents':function(){if($.browser.name=='msie'){return
 context.$content.text();}
-var $dummyDiv=$('<div 
/>').html(context.$content.html().replace(/\<br[^\>]*\>/g,"\n"));$dummyDiv.find(".wikiEditor-noinclude").each(function(){$(this).remove();});return
 
$dummyDiv.text();},'setContents':function(options){context.$content.text(options.contents);return
 context.$textarea;},'getSelection':function(){var 
retval;if(context.$iframe[0].contentWindow.getSelection){retval=context.$iframe[0].contentWindow.getSelection();}else
 
if(context.$iframe[0].contentWindow.document.selection){retval=context.$iframe[0].contentWindow.document.selection.createRange();}
+addTab(options);return $('<div></div>').addClass('wikiEditor-ui-view 
wikiEditor-ui-view-'+options.name).hide().appendTo(context.$ui);},'getContents':function(){var
 
$pre=$('<pre>'+context.$content.html().replace(/\<br[^\>]*\>/gi,"\n")+'</pre>');$pre.find(".wikiEditor-noinclude").each(function(){$(this).remove();});return
 $pre.text();},'getSelection':function(){var 
retval;if(context.$iframe[0].contentWindow.getSelection){retval=context.$iframe[0].contentWindow.getSelection();}else
 
if(context.$iframe[0].contentWindow.document.selection){retval=context.$iframe[0].contentWindow.document.selection.createRange();}
 if(retval.text){retval=retval.text;}else 
if(retval.toString){retval=retval.toString();}
 return retval;},'encapsulateSelection':function(options){var 
selText=$(this).textSelection('getSelection');var selectAfter=false;var 
pre=options.pre,post=options.post;if(!selText){selText=options.peri;selectAfter=true;}else
 if(options.replace){selText=options.peri;}else 
if(selText.charAt(selText.length-1)==' 
'){selText=selText.substring(0,selText.length-1);post+=' ';}
 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;}



_______________________________________________
MediaWiki-CVS mailing list
MediaWiki-CVS@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs

Reply via email to