Index: trunk/extensions/UsabilityInitiative/UsabilityInitiative.hooks.php |
— | — | @@ -135,12 +135,12 @@ |
136 | 136 | array( |
137 | 137 | 'src' => 'js/plugins/jquery.wikiEditor.js', |
138 | 138 | 'class' => 'j.wikiEditor', |
139 | | - 'version' => 66 |
| 139 | + 'version' => 67 |
140 | 140 | ), |
141 | 141 | array( |
142 | 142 | 'src' => 'js/plugins/jquery.wikiEditor.highlight.js', |
143 | 143 | 'class' => 'j.wikiEditor.modules.highlight', |
144 | | - 'version' => 21 |
| 144 | + 'version' => 22 |
145 | 145 | ), |
146 | 146 | array( |
147 | 147 | 'src' => 'js/plugins/jquery.wikiEditor.toolbar.js', |
— | — | @@ -173,10 +173,10 @@ |
174 | 174 | 'version' => 1 ), |
175 | 175 | ), |
176 | 176 | 'combined' => array( |
177 | | - array( 'src' => 'js/plugins.combined.js', 'version' => 176 ), |
| 177 | + array( 'src' => 'js/plugins.combined.js', 'version' => 177 ), |
178 | 178 | ), |
179 | 179 | 'minified' => array( |
180 | | - array( 'src' => 'js/plugins.combined.min.js', 'version' => 176 ), |
| 180 | + array( 'src' => 'js/plugins.combined.min.js', 'version' => 177 ), |
181 | 181 | ), |
182 | 182 | ), |
183 | 183 | ); |
Index: trunk/extensions/UsabilityInitiative/js/plugins/jquery.wikiEditor.js |
— | — | @@ -368,17 +368,17 @@ |
369 | 369 | .appendTo( context.$ui ); |
370 | 370 | }, |
371 | 371 | 'htmlToText': function( html ) { |
372 | | - // We use .html() instead of .text() so HTML entities are handled right - setting the HTML of the textarea |
373 | | - // doesn't work on all browsers, use a dummy <div> instead |
374 | | - // Get rid of the noincludes when getting text |
| 372 | + // We use this elaborate trickery for cross-browser compatibility |
| 373 | + // IE does overzealous whitespace collapsing for $( '<pre />' ).html( html ); |
375 | 374 | var $pre = $( '<pre>' + |
376 | 375 | html |
377 | | - .replace( /\r?\n/g, "" ) |
| 376 | + .replace( /\r?\n/g, "" ) // IE7 inserts newlines before block elements |
378 | 377 | .replace( /\<br[^\>]*\>/gi, "\n" ) |
379 | | - .replace( / /g, " " ) |
380 | | - .replace( /\<p[^\>]*\>/gi, "\n" ) |
| 378 | + .replace( / /g, " " ) // We inserted these to prevent IE from collapsing spaces |
| 379 | + .replace( /\<p[^\>]*\>/gi, "\n" ) // IE uses </p><p> for user-inserted line breaks |
381 | 380 | .replace( /\<\/p[^\>]*\>/gi, "" ) |
382 | 381 | + '</pre>' ); |
| 382 | + // Get rid of the noincludes when getting text |
383 | 383 | $pre.find( '.wikiEditor-noinclude' ).each( function() { $( this ).remove(); } ); |
384 | 384 | $pre.find( '.wikiEditor-tab' ).each( function() { $( this ).text( "\t" ) } ); |
385 | 385 | return $pre.text(); |
— | — | @@ -674,8 +674,8 @@ |
675 | 675 | } |
676 | 676 | var seekPos = context.fn.htmlToText( range2.htmlText ).length; |
677 | 677 | var offsets = context.fn.getOffsets(); |
678 | | - e = offsets[seekPos].node; |
679 | | - offset = offsets[seekPos].offset; |
| 678 | + e = offsets[seekPos] ? offsets[seekPos].node : null; |
| 679 | + offset = offsets[seekPos] ? offsets[seekPos].offset : null; |
680 | 680 | if ( !e ) |
681 | 681 | return $( [] ); |
682 | 682 | } |
— | — | @@ -903,26 +903,15 @@ |
904 | 904 | if ( $.browser.msie ) { |
905 | 905 | // Browser sniffing is not ideal, but executing this code on a non-broken browser doesn't cause harm |
906 | 906 | if ( $.browser.versionNumber <= 7 ) { |
907 | | - // Replace all spaces matching /(^|n) +/ with - IE <= 7 needs this because of its overzealous |
| 907 | + // Replace all spaces matching - IE <= 7 needs this because of its overzealous |
908 | 908 | // whitespace collapsing; |
909 | | - var prefix = '', suffix = html; |
910 | | - while ( suffix ) { |
911 | | - var match = suffix.match( /(^|\n) / ); |
912 | | - if ( match ) { |
913 | | - prefix += suffix.substr( 0, match.index + match[0].length - 1 ) + ' '; |
914 | | - suffix = suffix.substr( match.index + match[0].length ); |
915 | | - } else { |
916 | | - break; |
917 | | - } |
918 | | - } |
919 | | - html = prefix + suffix; |
| 909 | + html = html.replace( / /g, " " ); |
920 | 910 | } else { |
921 | 911 | // IE8 is happy if we just convert the first leading space to |
922 | 912 | html = html.replace( /(^|\n) /g, "$1 " ); |
923 | 913 | } |
924 | 914 | html = html.replace( /\t/g, '<span class="wikiEditor-tab"></span>' ); |
925 | 915 | } |
926 | | - // We must append, because IE will crash if we set html() - which is the same as empty() and append() |
927 | 916 | context.$content.html( html.replace( /\r?\n/g, '<br />' ) ); |
928 | 917 | // Reflect direction of parent frame into child |
929 | 918 | if ( $( 'body' ).is( '.rtl' ) ) { |
Index: trunk/extensions/UsabilityInitiative/js/plugins/jquery.wikiEditor.highlight.js |
— | — | @@ -282,7 +282,7 @@ |
283 | 283 | |
284 | 284 | // Remove markers that were previously inserted but weren't passed to this function |
285 | 285 | context.$content.find( 'div.wikiEditor-highlight:not(.wikiEditor-highlight-tmp)' ).each( function() { |
286 | | - if ( typeof $(this).data( 'marker' ).unwrap == 'function' ) |
| 286 | + if ( $(this).data( 'marker' ) && typeof $(this).data( 'marker' ).unwrap == 'function' ) |
287 | 287 | $(this).data( 'marker' ).unwrap( this ); |
288 | 288 | if ( $(this).children().size() > 0 ) { |
289 | 289 | $(this).replaceWith( $(this).children() ); |
Index: trunk/extensions/UsabilityInitiative/js/plugins.combined.js |
— | — | @@ -6730,17 +6730,17 @@ |
6731 | 6731 | .appendTo( context.$ui ); |
6732 | 6732 | }, |
6733 | 6733 | 'htmlToText': function( html ) { |
6734 | | - // We use .html() instead of .text() so HTML entities are handled right - setting the HTML of the textarea |
6735 | | - // doesn't work on all browsers, use a dummy <div> instead |
6736 | | - // Get rid of the noincludes when getting text |
| 6734 | + // We use this elaborate trickery for cross-browser compatibility |
| 6735 | + // IE does overzealous whitespace collapsing for $( '<pre />' ).html( html ); |
6737 | 6736 | var $pre = $( '<pre>' + |
6738 | 6737 | html |
6739 | | - .replace( /\r?\n/g, "" ) |
| 6738 | + .replace( /\r?\n/g, "" ) // IE7 inserts newlines before block elements |
6740 | 6739 | .replace( /\<br[^\>]*\>/gi, "\n" ) |
6741 | | - .replace( / /g, " " ) |
6742 | | - .replace( /\<p[^\>]*\>/gi, "\n" ) |
| 6740 | + .replace( / /g, " " ) // We inserted these to prevent IE from collapsing spaces |
| 6741 | + .replace( /\<p[^\>]*\>/gi, "\n" ) // IE uses </p><p> for user-inserted line breaks |
6743 | 6742 | .replace( /\<\/p[^\>]*\>/gi, "" ) |
6744 | 6743 | + '</pre>' ); |
| 6744 | + // Get rid of the noincludes when getting text |
6745 | 6745 | $pre.find( '.wikiEditor-noinclude' ).each( function() { $( this ).remove(); } ); |
6746 | 6746 | $pre.find( '.wikiEditor-tab' ).each( function() { $( this ).text( "\t" ) } ); |
6747 | 6747 | return $pre.text(); |
— | — | @@ -7036,8 +7036,8 @@ |
7037 | 7037 | } |
7038 | 7038 | var seekPos = context.fn.htmlToText( range2.htmlText ).length; |
7039 | 7039 | var offsets = context.fn.getOffsets(); |
7040 | | - e = offsets[seekPos].node; |
7041 | | - offset = offsets[seekPos].offset; |
| 7040 | + e = offsets[seekPos] ? offsets[seekPos].node : null; |
| 7041 | + offset = offsets[seekPos] ? offsets[seekPos].offset : null; |
7042 | 7042 | if ( !e ) |
7043 | 7043 | return $( [] ); |
7044 | 7044 | } |
— | — | @@ -7265,26 +7265,15 @@ |
7266 | 7266 | if ( $.browser.msie ) { |
7267 | 7267 | // Browser sniffing is not ideal, but executing this code on a non-broken browser doesn't cause harm |
7268 | 7268 | if ( $.browser.versionNumber <= 7 ) { |
7269 | | - // Replace all spaces matching /(^|n) +/ with - IE <= 7 needs this because of its overzealous |
| 7269 | + // Replace all spaces matching - IE <= 7 needs this because of its overzealous |
7270 | 7270 | // whitespace collapsing; |
7271 | | - var prefix = '', suffix = html; |
7272 | | - while ( suffix ) { |
7273 | | - var match = suffix.match( /(^|\n) / ); |
7274 | | - if ( match ) { |
7275 | | - prefix += suffix.substr( 0, match.index + match[0].length - 1 ) + ' '; |
7276 | | - suffix = suffix.substr( match.index + match[0].length ); |
7277 | | - } else { |
7278 | | - break; |
7279 | | - } |
7280 | | - } |
7281 | | - html = prefix + suffix; |
| 7271 | + html = html.replace( / /g, " " ); |
7282 | 7272 | } else { |
7283 | 7273 | // IE8 is happy if we just convert the first leading space to |
7284 | 7274 | html = html.replace( /(^|\n) /g, "$1 " ); |
7285 | 7275 | } |
7286 | 7276 | html = html.replace( /\t/g, '<span class="wikiEditor-tab"></span>' ); |
7287 | 7277 | } |
7288 | | - // We must append, because IE will crash if we set html() - which is the same as empty() and append() |
7289 | 7278 | context.$content.html( html.replace( /\r?\n/g, '<br />' ) ); |
7290 | 7279 | // Reflect direction of parent frame into child |
7291 | 7280 | if ( $( 'body' ).is( '.rtl' ) ) { |
— | — | @@ -7764,7 +7753,7 @@ |
7765 | 7754 | |
7766 | 7755 | // Remove markers that were previously inserted but weren't passed to this function |
7767 | 7756 | context.$content.find( 'div.wikiEditor-highlight:not(.wikiEditor-highlight-tmp)' ).each( function() { |
7768 | | - if ( typeof $(this).data( 'marker' ).unwrap == 'function' ) |
| 7757 | + if ( $(this).data( 'marker' ) && typeof $(this).data( 'marker' ).unwrap == 'function' ) |
7769 | 7758 | $(this).data( 'marker' ).unwrap( this ); |
7770 | 7759 | if ( $(this).children().size() > 0 ) { |
7771 | 7760 | $(this).replaceWith( $(this).children() ); |
Index: trunk/extensions/UsabilityInitiative/js/plugins.combined.min.js |
— | — | @@ -464,7 +464,7 @@ |
465 | 465 | var topBound=html.scrollTop()>body.scrollTop()?html.scrollTop():body.scrollTop(),bottomBound=topBound+context.$iframe.height();if(force||y<topBound||y>bottomBound){html.scrollTop(y);body.scrollTop(y);} |
466 | 466 | $element.trigger('scrollToTop');},'beforeSelection':function(selector,strict){if(typeof selector=='undefined'){selector='*';} |
467 | 467 | var e,offset;if(context.$iframe[0].contentWindow.getSelection){var selection=context.$iframe[0].contentWindow.getSelection();if(selection.baseNode!==null){e=selection.getRangeAt(0).startContainer;offset=selection.startOffset;}else{return $([]);}}else if(context.$iframe[0].contentWindow.document.selection){var range=context.$iframe[0].contentWindow.document.selection.createRange();var range2=context.$iframe[0].contentWindow.document.body.createTextRange();try{range2.setEndPoint('EndToStart',range);}catch(e){return $([]);} |
468 | | -var seekPos=context.fn.htmlToText(range2.htmlText).length;var offsets=context.fn.getOffsets();e=offsets[seekPos].node;offset=offsets[seekPos].offset;if(!e) |
| 468 | +var seekPos=context.fn.htmlToText(range2.htmlText).length;var offsets=context.fn.getOffsets();e=offsets[seekPos]?offsets[seekPos].node:null;offset=offsets[seekPos]?offsets[seekPos].offset:null;if(!e) |
469 | 469 | return $([]);} |
470 | 470 | if(e.nodeName!='#text'){var newE=e.firstChild;for(var i=0;i<offset-1&&newE;i++){newE=newE.nextSibling;} |
471 | 471 | while(newE&&newE.lastChild){newE=newE.lastChild;} |
— | — | @@ -483,8 +483,7 @@ |
484 | 484 | if(leavingP){context.offsets[nextPos]={'node':t.node,'offset':nextPos-pos,'length':nextPos-pos+1,'depth':t.depth,'lastTextNode':lastTextNode,'lastTextNodeDepth':lastTextNodeDepth};} |
485 | 485 | pos=nextPos+(leavingP?1:0);if(t.node.nodeName=='#text'){lastTextNode=t.node;lastTextNodeDepth=t.depth;} |
486 | 486 | t=nextT;}}};context.$textarea.wrap($('<div></div>').addClass('wikiEditor-ui')).wrap($('<div></div>').addClass('wikiEditor-ui-view wikiEditor-ui-view-wikitext')).wrap($('<div></div>').addClass('wikiEditor-ui-left')).wrap($('<div></div>').addClass('wikiEditor-ui-bottom')).wrap($('<div></div>').addClass('wikiEditor-ui-text'));context.$ui=context.$textarea.parent().parent().parent().parent().parent();context.$wikitext=context.$textarea.parent().parent().parent().parent();context.$wikitext.before($('<div></div>').addClass('wikiEditor-ui-controls').append($('<div></div>').addClass('wikiEditor-ui-tabs').hide()).append($('<div></div>').addClass('wikiEditor-ui-buttons'))).before($('<div style="clear:both;"></div>'));context.$controls=context.$ui.find('.wikiEditor-ui-buttons').hide();context.$buttons=context.$ui.find('.wikiEditor-ui-buttons');context.$tabs=context.$ui.find('.wikiEditor-ui-tabs');context.$ui.after($('<div style="clear:both;"></div>'));context.$wikitext.append($('<div></div>').addClass('wikiEditor-ui-right'));context.$wikitext.find('.wikiEditor-ui-left').prepend($('<div></div>').addClass('wikiEditor-ui-top'));context.view='wikitext';$(window).resize(function(event){context.fn.trigger('resize',event)});context.$iframe=$('<iframe></iframe>').attr({'frameBorder':0,'border':0,'src':wgScriptPath+'/extensions/UsabilityInitiative/js/plugins/jquery.wikiEditor.html?'+'instance='+context.instance+'&ts='+(new Date()).getTime(),'id':'wikiEditor-iframe-'+context.instance}).css({'backgroundColor':'white','width':'100%','height':context.$textarea.height(),'display':'none','overflow-y':'scroll','overflow-x':'hidden'}).insertAfter(context.$textarea).load(function(){if(!this.isSecondRun){context.$iframe[0].contentWindow.document.designMode='on';if($.browser.msie){this.isSecondRun=true;return;}} |
487 | | -context.$content=$(context.$iframe[0].contentWindow.document.body);var html=context.$textarea.val().replace(/\</g,'<').replace(/\>/g,'>');if($.browser.msie){if($.browser.versionNumber<=7){var prefix='',suffix=html;while(suffix){var match=suffix.match(/(^|\n) /);if(match){prefix+=suffix.substr(0,match.index+match[0].length-1)+' ';suffix=suffix.substr(match.index+match[0].length);}else{break;}} |
488 | | -html=prefix+suffix;}else{html=html.replace(/(^|\n) /g,"$1 ");} |
| 487 | +context.$content=$(context.$iframe[0].contentWindow.document.body);var html=context.$textarea.val().replace(/\</g,'<').replace(/\>/g,'>');if($.browser.msie){if($.browser.versionNumber<=7){html=html.replace(/ /g," ");}else{html=html.replace(/(^|\n) /g,"$1 ");} |
489 | 488 | html=html.replace(/\t/g,'<span class="wikiEditor-tab"></span>');} |
490 | 489 | context.$content.html(html.replace(/\r?\n/g,'<br />'));if($('body').is('.rtl')){context.$content.addClass('rtl').attr('dir','rtl');} |
491 | 490 | context.$textarea.attr('disabled',true);context.$textarea.hide();context.$iframe.show();context.fn.trigger('ready');$(context.$iframe[0].contentWindow.document).bind('keyup mouseup paste cut encapsulateSelection',function(event){context.fn.trigger('change',event);}).delayedBind(250,'keyup mouseup paste cut encapsulateSelection',function(event){context.fn.trigger('delayedChange',event);});});context.$textarea.closest('form').submit(function(){context.$textarea.attr('disabled',false);context.$textarea.val(context.$textarea.textSelection('getContents'));});} |
— | — | @@ -510,7 +509,7 @@ |
511 | 510 | if(ca1&&ca2&&ca1.parentNode&&ca2.nextSibling){var anchor=markers[i].getAnchor(ca1,ca2);if(!anchor){var newNode=ca1.ownerDocument.createElement('div');var commonAncestor=ca1.parentNode;var nextNode=ca2.nextSibling;if(markers[i].anchor=='wrap'){var n=ca1;while(n!=nextNode){var ns=n.nextSibling;newNode.appendChild(n);n=ns;} |
512 | 511 | if(nextNode){commonAncestor.insertBefore(newNode,nextNode);}else{commonAncestor.appendChild(newNode);}}else if(markers[i].anchor=='before'){commonAncestor.insertBefore(newNode,ca1);}else if(markers[i].anchor=='after'){if(nextNode){commonAncestor.insertBefore(newNode,nextNode);}else{commonAncestor.appendChild(newNode);}} |
513 | 512 | $(newNode).data('marker',markers[i]).addClass('wikiEditor-highlight wikiEditor-highlight-tmp');markers[i].afterWrap(newNode,markers[i]);}else{$(anchor).addClass('wikiEditor-highlight-tmp').data('marker',markers[i]);markers[i].onSkip(anchor);}}} |
514 | | -context.$content.find('div.wikiEditor-highlight:not(.wikiEditor-highlight-tmp)').each(function(){if(typeof $(this).data('marker').unwrap=='function') |
| 513 | +context.$content.find('div.wikiEditor-highlight:not(.wikiEditor-highlight-tmp)').each(function(){if($(this).data('marker')&&typeof $(this).data('marker').unwrap=='function') |
515 | 514 | $(this).data('marker').unwrap(this);if($(this).children().size()>0){$(this).replaceWith($(this).children());}else{$(this).replaceWith($(this).html());}});context.$content.find('div.wikiEditor-highlight-tmp').removeClass('wikiEditor-highlight-tmp');}}};})(jQuery);(function($){$.wikiEditor.modules.preview={fn:{create:function(context,config){if('initialized'in context.modules.preview){return;} |
516 | 515 | context.modules.preview={'initialized':true,'previewText':null,'changesText':null};context.modules.preview.$preview=context.fn.addView({'name':'preview','titleMsg':'wikieditor-preview-tab','init':function(context){var wikitext=context.fn.getContents();if(context.modules.preview.previewText==wikitext){return;} |
517 | 516 | context.modules.preview.$preview.find('.wikiEditor-preview-contents').empty();context.modules.preview.$preview.find('.wikiEditor-preview-loading').show();$.post(wgScriptPath+'/api.php',{'action':'parse','title':wgPageName,'text':wikitext,'prop':'text','pst':'','format':'json'},function(data){if(typeof data.parse=='undefined'||typeof data.parse.text=='undefined'||typeof data.parse.text['*']=='undefined'){return;} |