r55458 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r55457‎ | r55458 | r55459 >
Date:23:17, 21 August 2009
Author:tparscal
Status:deferred
Tags:
Comment:
Changes the logic introduced in r55269 so that unknown browsers are assumed to work properly. Also moved the definition of which browsers are supported to a globally accessible location so that developers have some options for testing things in unsuported browsers.
Modified paths:
  • /trunk/extensions/UsabilityInitiative/EditToolbar/EditToolbar.js (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/EditToolbar/EditToolbar.js
@@ -1,7 +1,7 @@
22 /* JavaScript for EditToolbar extension */
33
44 js2AddOnloadHook( function() {
5 - if ( $j.wikiEditor.isSupported() ) {
 5+ if ( $j.wikiEditor != undefined && $j.wikiEditor.isSupported() || !$j.wikiEditor.isSupportKnown() ) {
66 // Remove the old toolbar
77 $j( '#toolbar' ).remove();
88 // Build a wikiEditor around the textarea
Index: trunk/extensions/UsabilityInitiative/js/plugins/jquery.wikiEditor.js
@@ -15,17 +15,21 @@
1616 $.wikiEditor = {
1717 'modules': {},
1818 'instances': [],
19 - 'isSupported': function() {
20 - function isSupported( supportedBrowsers ) {
21 - return $.browser.name in supportedBrowsers && $.browser.versionNumber >= supportedBrowsers[$.browser.name];
22 - }
23 - var supportedBrowsers = {
24 - 'ltr': { 'msie': 7, 'firefox': 2, 'opera': 9, 'safari': 3, 'chrome': 1, 'camino': 1 },
25 - 'rtl': { 'msie': 8, 'firefox': 2, 'opera': 9, 'safari': 3, 'chrome': 1, 'camino': 1 }
26 - };
27 - return isSupported( supportedBrowsers[$( 'body.rtl' ).size() ? 'rtl' : 'ltr'] );
 19+ 'supportedBrowsers': {
 20+ 'ltr': { 'msie': 7, 'firefox': 2, 'opera': 9, 'safari': 3, 'chrome': 1, 'camino': 1 },
 21+ 'rtl': { 'msie': 8, 'firefox': 2, 'opera': 9, 'safari': 3, 'chrome': 1, 'camino': 1 }
2822 }
2923 };
 24+$.wikiEditor.isSupportKnown = function() {
 25+ return ( function( supportedBrowsers ) {
 26+ return $.browser.name in supportedBrowsers;
 27+ } )( $.wikiEditor.supportedBrowsers[$( 'body.rtl' ).size() ? 'rtl' : 'ltr'] );
 28+};
 29+$.wikiEditor.isSupported = function() {
 30+ return ( function( supportedBrowsers ) {
 31+ return $.browser.name in supportedBrowsers && $.browser.versionNumber >= supportedBrowsers[$.browser.name];
 32+ } )( $.wikiEditor.supportedBrowsers[$( 'body.rtl' ).size() ? 'rtl' : 'ltr'] );
 33+};
3034 $.fn.wikiEditor = function() {
3135
3236 /* Initialization */
Index: trunk/extensions/UsabilityInitiative/js/plugins.combined.js
@@ -1026,17 +1026,21 @@
10271027 $.wikiEditor = {
10281028 'modules': {},
10291029 'instances': [],
1030 - 'isSupported': function() {
1031 - function isSupported( supportedBrowsers ) {
1032 - return $.browser.name in supportedBrowsers && $.browser.versionNumber >= supportedBrowsers[$.browser.name];
1033 - }
1034 - var supportedBrowsers = {
1035 - 'ltr': { 'msie': 7, 'firefox': 2, 'opera': 9, 'safari': 3, 'chrome': 1, 'camino': 1 },
1036 - 'rtl': { 'msie': 8, 'firefox': 2, 'opera': 9, 'safari': 3, 'chrome': 1, 'camino': 1 }
1037 - };
1038 - return isSupported( supportedBrowsers[$( 'body.rtl' ).size() ? 'rtl' : 'ltr'] );
 1030+ 'supportedBrowsers': {
 1031+ 'ltr': { 'msie': 7, 'firefox': 2, 'opera': 9, 'safari': 3, 'chrome': 1, 'camino': 1 },
 1032+ 'rtl': { 'msie': 8, 'firefox': 2, 'opera': 9, 'safari': 3, 'chrome': 1, 'camino': 1 }
10391033 }
10401034 };
 1035+$.wikiEditor.isSupportKnown = function() {
 1036+ return ( function( supportedBrowsers ) {
 1037+ return $.browser.name in supportedBrowsers;
 1038+ } )( $.wikiEditor.supportedBrowsers[$( 'body.rtl' ).size() ? 'rtl' : 'ltr'] );
 1039+};
 1040+$.wikiEditor.isSupported = function() {
 1041+ return ( function( supportedBrowsers ) {
 1042+ return $.browser.name in supportedBrowsers && $.browser.versionNumber >= supportedBrowsers[$.browser.name];
 1043+ } )( $.wikiEditor.supportedBrowsers[$( 'body.rtl' ).size() ? 'rtl' : 'ltr'] );
 1044+};
10411045 $.fn.wikiEditor = function() {
10421046
10431047 /* Initialization */
@@ -1558,7 +1562,8 @@
15591563 */
15601564 doAction : function( context, action, source ) {
15611565 // Verify that this has been called from a source that's within the toolbar
1562 - if ( source.closest( '.wikiEditor-ui-toolbar' ).size() ) {
 1566+ // 'trackAction' defined in click tracking
 1567+ if ($.trackAction != undefined && source.closest( '.wikiEditor-ui-toolbar' ).size() ) {
15631568 // Build a unique id for this action by tracking the parent rel attributes up to the toolbar level
15641569 var rels = [];
15651570 var step = source;
@@ -1576,7 +1581,7 @@
15771582 }
15781583 rels.reverse();
15791584 var id = rels.join( '.' );
1580 - // PERFORM CLICK TRACKING HERE!
 1585+ $.trackAction(id);
15811586 }
15821587 switch ( action.type ) {
15831588 case 'replace':
Index: trunk/extensions/UsabilityInitiative/js/plugins.combined.min.js
@@ -107,8 +107,7 @@
108108 return($.os.name=='mac'?13:($.os.name=='linux'?15:16))*row;}
109109 return this.each(function(){$(this).focus();if(this.selectionStart||this.selectionStart=='0'){this.selectionStart=pos;this.selectionEnd=pos;$(this).scrollTop(getCaretScrollPosition(this));}else if(document.selection&&document.selection.createRange){var range=document.selection.createRange();var oldPos=$(this).getCaretPosition();var goBack=false;if(oldPos==pos){pos++;goBack=true;}
110110 range.moveToElementText(this);range.collapse();range.move('character',pos);range.select();this.scrollTop+=range.offsetTop;if(goBack){range.move('character',-1);range.select();}}
111 -$(this).trigger('scrollToPosition');});}});})(jQuery);(function($){$.wikiEditor={'modules':{},'instances':[],'isSupported':function(){function isSupported(supportedBrowsers){return $.browser.name in supportedBrowsers&&$.browser.versionNumber>=supportedBrowsers[$.browser.name];}
112 -var supportedBrowsers={'ltr':{'msie':7,'firefox':2,'opera':9,'safari':3,'chrome':1,'camino':1},'rtl':{'msie':8,'firefox':2,'opera':9,'safari':3,'chrome':1,'camino':1}};return isSupported(supportedBrowsers[$('body.rtl').size()?'rtl':'ltr']);}};$.fn.wikiEditor=function(){var context=$(this).data('context');if(typeof context!=='undefined'){arguments=$.makeArray(arguments);if(arguments.length>0){var call=arguments.shift();if(call in context.api){context.api[call](context,arguments[0]==undefined?{}:arguments[0]);}
 111+$(this).trigger('scrollToPosition');});}});})(jQuery);(function($){$.wikiEditor={'modules':{},'instances':[],'supportedBrowsers':{'ltr':{'msie':7,'firefox':2,'opera':9,'safari':3,'chrome':1,'camino':1},'rtl':{'msie':8,'firefox':2,'opera':9,'safari':3,'chrome':1,'camino':1}}};$.wikiEditor.isSupportKnown=function(){return(function(supportedBrowsers){return $.browser.name in supportedBrowsers;})($.wikiEditor.supportedBrowsers[$('body.rtl').size()?'rtl':'ltr']);};$.wikiEditor.isSupported=function(){return(function(supportedBrowsers){return $.browser.name in supportedBrowsers&&$.browser.versionNumber>=supportedBrowsers[$.browser.name];})($.wikiEditor.supportedBrowsers[$('body.rtl').size()?'rtl':'ltr']);};$.fn.wikiEditor=function(){var context=$(this).data('context');if(typeof context!=='undefined'){arguments=$.makeArray(arguments);if(arguments.length>0){var call=arguments.shift();if(call in context.api){context.api[call](context,arguments[0]==undefined?{}:arguments[0]);}
113112 return $(this).data('context',context);}
114113 return $(this);}
115114 var instance=$.wikiEditor.instances.length;context={'$textarea':$(this),'modules':{},'data':{},'instance':instance};$.wikiEditor.instances[instance]=$(this);$(this).wrap($('<div></div>').addClass('wikiEditor-ui').attr('id','wikiEditor-ui')).wrap($('<div></div>').addClass('wikiEditor-ui-bottom').attr('id','wikiEditor-ui-bottom')).wrap($('<div></div>').addClass('wikiEditor-ui-text').attr('id','wikiEditor-ui-text'));context.$ui=$(this).parent().parent().parent();context.$ui.after($('<div style="clear:both;"></div>'));context.$ui.prepend($('<div></div>').addClass('wikiEditor-ui-top').attr('id','wikiEditor-ui-top'));context.api={addModule:function(context,data){function callModuleApi(module,call,data){if(module in $.wikiEditor.modules&&'fn'in $.wikiEditor.modules[module]&&call in $.wikiEditor.modules[module].fn){$.wikiEditor.modules[module].fn[call](context,data);}}
@@ -145,10 +144,10 @@
146145 $characters=context.modules.$toolbar.find('div[rel='+data.section+'].section '+'div[rel='+data.page+'].page div');var actions=$characters.data('actions');for(character in data[type]){$characters.append($($.wikiEditor.modules.toolbar.fn.buildCharacter(data[type][character],actions)).click(function(){$.wikiEditor.modules.toolbar.fn.doAction($(this).parent().data('context'),$(this).parent().data('actions')[$(this).attr('rel')]);return false;}));}
147146 break;default:break;}}},removeFromToolbar:function(context,data){if(typeof data.section=='string'){var tab='div.tabs span[rel='+data.section+'].tab';var target='div[rel='+data.section+'].section';if(typeof data.group=='string'){target+=' div[rel='+data.group+'].group';if(typeof data.tool=='string'){target+=' div[rel='+data.tool+'].tool';}}else if(typeof data.page=='string'){var index=target+' div.index div[rel='+data.page+']';target+=' div.pages div[rel='+data.page+'].page';if(typeof data.character=='string'){target+=' a[rel='+data.character+']';}else if(typeof data.row=='number'){target+=' table tr:not(:has(th)):eq('+data.row+')';}else{context.modules.$toolbar.find(index).remove();$.wikiEditor.modules.toolbar.fn.updateBookletSelection(context,null,context.modules.$toolbar.find(target),context.modules.$toolbar.find(index));}}else{context.modules.$toolbar.find(tab).remove();}
148147 context.modules.$toolbar.find(target).remove();}}},fn:{autoMsg:function(object,property){if(property in object){return object[property];}else if(property+'Msg'in object){return gM(object[property+'Msg']);}else{return'';}},create:function(context,config){if('$toolbar'in context.modules){return;}
149 -context.modules.$toolbar=$('<div />').addClass('wikiEditor-ui-toolbar').attr('id','wikiEditor-ui-toolbar');$.wikiEditor.modules.toolbar.fn.build(context,config);context.$ui.find('.wikiEditor-ui-top').append(context.modules.$toolbar);},doAction:function(context,action,source){if(source.closest('.wikiEditor-ui-toolbar').size()){var rels=[];var step=source;var i=0;while(!step.hasClass('wikiEditor-ui-toolbar')){if(i>25){break;}
 148+context.modules.$toolbar=$('<div />').addClass('wikiEditor-ui-toolbar').attr('id','wikiEditor-ui-toolbar');$.wikiEditor.modules.toolbar.fn.build(context,config);context.$ui.find('.wikiEditor-ui-top').append(context.modules.$toolbar);},doAction:function(context,action,source){if($.trackAction!=undefined&&source.closest('.wikiEditor-ui-toolbar').size()){var rels=[];var step=source;var i=0;while(!step.hasClass('wikiEditor-ui-toolbar')){if(i>25){break;}
150149 i++;var rel=step.attr('rel');if(rel){rels.push(step.attr('rel'));}
151150 step=step.parent();}
152 -rels.reverse();var id=rels.join('.');}
 151+rels.reverse();var id=rels.join('.');$.trackAction(id);}
153152 switch(action.type){case'replace':case'encapsulate':var parts={'pre':'','peri':'','post':''};for(part in parts){if(part+'Msg'in action.options){parts[part]=gM(action.options[part+'Msg'],(action.options[part]||null));}else{parts[part]=(action.options[part]||'')}}
154153 context.$textarea.encapsulateSelection(parts.pre,parts.peri,parts.post,action.options.ownline,action.type=='replace');break;case'dialog':if($j('#'+action.id).size()==0){var dialogConf=action.dialog;dialogConf.bgiframe=true;dialogConf.autoOpen=false;dialogConf.modal=true;dialogConf.title=gM(action.titleMsg);for(msg in dialogConf.buttons){dialogConf.buttons[gM(msg)]=dialogConf.buttons[msg];delete dialogConf.buttons[msg];}
155154 $j('<div /> ').attr('id',action.id).html(action.html).data('context',context).appendTo($j('body')).each(action.init).dialog(dialogConf);}

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r55269Added browser support detection. We no longer override the old toolbar unless...tparscal20:57, 18 August 2009

Status & tagging log