r60081 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r60080‎ | r60081 | r60082 >
Date:17:32, 15 December 2009
Author:adam
Status:deferred
Tags:
Comment:
WikiEditor - altering scrollToTop to restore NTOC functionallity. Tested in FF 3.5
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
@@ -71,7 +71,7 @@
7272 array( 'src' => 'js/plugins/jquery.namespaceSelect.js', 'version' => 1 ),
7373 array( 'src' => 'js/plugins/jquery.suggestions.js', 'version' => 6 ),
7474 array( 'src' => 'js/plugins/jquery.textSelection.js', 'version' => 21 ),
75 - array( 'src' => 'js/plugins/jquery.wikiEditor.js', 'version' => 34 ),
 75+ array( 'src' => 'js/plugins/jquery.wikiEditor.js', 'version' => 35 ),
7676 array( 'src' => 'js/plugins/jquery.wikiEditor.highlight.js', 'version' => 1 ),
7777 array( 'src' => 'js/plugins/jquery.wikiEditor.toolbar.js', 'version' => 39 ),
7878 array( 'src' => 'js/plugins/jquery.wikiEditor.dialogs.js', 'version' => 9 ),
@@ -81,10 +81,10 @@
8282 array( 'src' => 'js/plugins/jquery.wikiEditor.publish.js', 'version' => 0 ),
8383 ),
8484 'combined' => array(
85 - array( 'src' => 'js/plugins.combined.js', 'version' => 108 ),
 85+ array( 'src' => 'js/plugins.combined.js', 'version' => 109 ),
8686 ),
8787 'minified' => array(
88 - array( 'src' => 'js/plugins.combined.min.js', 'version' => 108 ),
 88+ array( 'src' => 'js/plugins.combined.min.js', 'version' => 109 ),
8989 ),
9090 ),
9191 );
Index: trunk/extensions/UsabilityInitiative/js/plugins/jquery.wikiEditor.js
@@ -531,10 +531,10 @@
532532 * @param force If true, scroll the element even if it's already visible
533533 */
534534 'scrollToTop': function( $element, force ) {
535 - var body = context.$content.closest( 'body' );
 535+ var html = context.$content.closest( 'html' );
536536 var y = $element.offset().top - context.$content.offset().top;
537 - if ( force || y < body.scrollTop() || y > body.scrollTop() + body.height() )
538 - body.scrollTop( y );
 537+ if ( force || y < html.scrollTop() || y > html.scrollTop() + context.$iframe.height() )
 538+ html.scrollTop( y );
539539 $element.trigger( 'scrollToTop' );
540540 },
541541 /**
Index: trunk/extensions/UsabilityInitiative/js/plugins.combined.js
@@ -1570,7 +1570,7 @@
15711571 switch ( event.type ) {
15721572 case 'keypress':
15731573 if ( /* TODO: test if something interesting was deleted */ true ) {
1574 - event.data.scope = 'division';
 1574+ event.data.scope = 'keydown';
15751575 } else {
15761576 event.data.scope = 'character';
15771577 }
@@ -1696,7 +1696,13 @@
16971697 }
16981698 // We use .html() instead of .text() so HTML entities are handled right
16991699 // Setting the HTML of the textarea doesn't work on all browsers, use a dummy <div> instead
1700 - return $( '<div />' ).html( context.$content.html().replace( /\<br\>/g, "\n" ) ).text();
 1700+
 1701+
 1702+ //get rid of the noincludes when getting text
 1703+ var $dummyDiv = $( '<div />' ).html( context.$content.html().replace( /\<br\>/g, "\n" ) );
 1704+ $dummyDiv.find( ".wiki-editor-noinclude" ).each( function() { $( this ).remove(); } );
 1705+ return $dummyDiv.text();
 1706+
17011707 },
17021708 /**
17031709 * Sets the complete contents of the iframe (in plain text, not HTML; HTML passed will be converted to entities)
@@ -1835,10 +1841,10 @@
18361842 * @param force If true, scroll the element even if it's already visible
18371843 */
18381844 'scrollToTop': function( $element, force ) {
1839 - var body = context.$content.closest( 'body' );
 1845+ var html = context.$content.closest( 'html' );
18401846 var y = $element.offset().top - context.$content.offset().top;
1841 - if ( force || y < body.scrollTop() || y > body.scrollTop() + body.height() )
1842 - body.scrollTop( y );
 1847+ if ( force || y < html.scrollTop() || y > html.scrollTop() + context.$iframe.height() )
 1848+ html.scrollTop( y );
18431849 $element.trigger( 'scrollToTop' );
18441850 },
18451851 /**
Index: trunk/extensions/UsabilityInitiative/js/plugins.combined.min.js
@@ -90,7 +90,7 @@
9191 return src+'?'+wgWikiEditorIconVersion;}};$.fn.wikiEditor=function(){if(!$j.wikiEditor.isSupported()){return $(this);}
9292 var context=$(this).data('wikiEditor-context');if(typeof context=='undefined'){context={'$textarea':$(this),'views':{},'modules':{},'data':{},'instance':$.wikiEditor.instances.push($(this))-1};context.api={'addModule':function(context,data){var modules={};if(typeof data=='string'){modules[data]={};}else if(typeof data=='object'){modules=data;}
9393 for(module in modules){if(typeof module=='string'&&module in $.wikiEditor.modules){if('api'in $.wikiEditor.modules[module]){for(call in $.wikiEditor.modules[module].api){if(!(call in context.api)){context.api[call]=$.wikiEditor.modules[module].api[call];}}}
94 -if('fn'in $.wikiEditor.modules[module]&&'create'in $.wikiEditor.modules[module].fn){context.modules[module]={};$.wikiEditor.modules[module].fn.create(context,modules[module]);}}}}};context.evt={'change':function(event){switch(event.type){case'keypress':if(true){event.data.scope='division';}else{event.data.scope='character';}
 94+if('fn'in $.wikiEditor.modules[module]&&'create'in $.wikiEditor.modules[module].fn){context.modules[module]={};$.wikiEditor.modules[module].fn.create(context,modules[module]);}}}}};context.evt={'change':function(event){switch(event.type){case'keypress':if(true){event.data.scope='keydown';}else{event.data.scope='character';}
9595 break;case'mousedown':if(true){event.data.scope='division';}else{return false;}
9696 break;default:event.data.scope='division';break;}
9797 return true;}};context.fn={'trigger':function(name,event){if(typeof event=='undefined'){event={'type':'custom'};}
@@ -100,7 +100,7 @@
101101 event.preventDefault();return false;}).text($.wikiEditor.autoMsg(options,'title'))).appendTo(context.$tabs);}
102102 if(!context.$tabs.children().size()){addTab({'name':'wikitext','titleMsg':'wikieditor-wikitext-tab'});}
103103 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();}
104 -return $('<div />').html(context.$content.html().replace(/\<br\>/g,"\n")).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();}
 104+var $dummyDiv=$('<div />').html(context.$content.html().replace(/\<br\>/g,"\n"));$dummyDiv.find(".wiki-editor-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();}
105105 if(retval.text){retval=retval.text;}else if(retval.toString){retval=retval.toString();}
106106 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+=' ';}
107107 var range=context.$iframe[0].contentWindow.getSelection().getRangeAt(0);if(options.ownline){if(range.startOffset!=0){pre="\n"+options.pre;}
@@ -109,8 +109,8 @@
110110 if(lastNode){context.fn.scrollToTop(lastNode);}
111111 context.$content.trigger('encapsulateSelection',[pre,options.peri,post,options.ownline,options.replace]);return context.$textarea;},'getCaretPosition':function(options){},'setSelection':function(options){var sel=context.$iframe[0].contentWindow.getSelection();var sc=options.startContainer,ec=options.endContainer;sc=sc.jquery?sc[0]:sc;ec=ec.jquery?ec[0]:ec;while(sc.firstChild&&sc.nodeName!='#text'){sc=sc.firstChild;}
112112 while(ec.firstChild&&ec.nodeName!='#text'){ec=ec.firstChild;}
113 -sel.extend(sc,options.start);sel.collapseToStart();if(options.end!=options.start||sc!=ec){sel.extend(ec,options.end);}},'scrollToCaretPosition':function(options){},'scrollToTop':function($element,force){var body=context.$content.closest('body');var y=$element.offset().top-context.$content.offset().top;if(force||y<body.scrollTop()||y>body.scrollTop()+body.height())
114 -body.scrollTop(y);$element.trigger('scrollToTop');},'beforeSelection':function(selector,getAll){if(typeof selector=='undefined')
 113+sel.extend(sc,options.start);sel.collapseToStart();if(options.end!=options.start||sc!=ec){sel.extend(ec,options.end);}},'scrollToCaretPosition':function(options){},'scrollToTop':function($element,force){var html=context.$content.closest('html');var y=$element.offset().top-context.$content.offset().top;if(force||y<html.scrollTop()||y>html.scrollTop()+context.$iframe.height())
 114+html.scrollTop(y);$element.trigger('scrollToTop');},'beforeSelection':function(selector,getAll){if(typeof selector=='undefined')
115115 selector='*';var retval=[];var range=context.$iframe[0].contentWindow.getSelection().getRangeAt(0);var e=range.startContainer;}};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,'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(){context.$iframe[0].contentWindow.document.designMode='on';context.$content=$(context.$iframe[0].contentWindow.document.body);context.$content.append(context.$textarea.val().replace(/</g,'&lt;').replace(/>/g,'&gt;'));if($('body').is('.rtl')){context.$content.addClass('rtl').attr('dir','rtl');}
116116 context.$textarea.attr('disabled',true);context.$textarea.hide();context.$iframe.show();context.fn.trigger('ready');});context.$textarea.closest('form').submit(function(){context.$textarea.attr('disabled',false);context.$textarea.val(context.$textarea.textSelection('getContents'));});}
117117 arguments=$.makeArray(arguments);if(arguments.length>0){var call=arguments.shift();if(call in context.api){context.api[call](context,typeof arguments[0]=='undefined'?{}:arguments[0]);}}

Status & tagging log