r55389 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r55388‎ | r55389 | r55390 >
Date:18:36, 20 August 2009
Author:tparscal
Status:deferred
Tags:
Comment:
Added some support code for click tracking that builds a nice looking string which describes the tool that was used in terms of the UI structure - such as "main.format.bold" or "characters.latin.ç".
Modified paths:
  • /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.toolbar.js (modified) (history)

Diff [purge]

Index: trunk/extensions/UsabilityInitiative/js/plugins/jquery.wikiEditor.toolbar.js
@@ -195,8 +195,30 @@
196196 *
197197 * @param {Object} context
198198 * @param {Object} action
 199+ * @param {Object} source
199200 */
200 - doAction : function( context, action ) {
 201+ doAction : function( context, action, source ) {
 202+ // Verify that this has been called from a source that's within the toolbar
 203+ if ( source.closest( '.wikiEditor-ui-toolbar' ).size() ) {
 204+ // Build a unique id for this action by tracking the parent rel attributes up to the toolbar level
 205+ var rels = [];
 206+ var step = source;
 207+ var i = 0;
 208+ while ( !step.hasClass( 'wikiEditor-ui-toolbar' ) ) {
 209+ if ( i > 25 ) {
 210+ break;
 211+ }
 212+ i++;
 213+ var rel = step.attr( 'rel' );
 214+ if ( rel ) {
 215+ rels.push( step.attr( 'rel' ) );
 216+ }
 217+ step = step.parent();
 218+ }
 219+ rels.reverse();
 220+ var id = rels.join( '.' );
 221+ // PERFORM CLICK TRACKING HERE!
 222+ }
201223 switch ( action.type ) {
202224 case 'replace':
203225 case 'encapsulate':
@@ -285,7 +307,7 @@
286308 .data( 'context', context )
287309 .click( function() {
288310 $.wikiEditor.modules.toolbar.fn.doAction(
289 - $(this).data( 'context' ), $(this).data( 'action' )
 311+ $(this).data( 'context' ), $(this).data( 'action' ), $(this)
290312 );
291313 return false;
292314 } );
@@ -308,7 +330,7 @@
309331 .data( 'context', context )
310332 .click( function() {
311333 $.wikiEditor.modules.toolbar.fn.doAction(
312 - $(this).data( 'context' ), $(this).data( 'action' )
 334+ $(this).data( 'context' ), $(this).data( 'action' ), $(this)
313335 );
314336 } )
315337 .text( optionLabel )
@@ -385,7 +407,8 @@
386408 .click( function() {
387409 $.wikiEditor.modules.toolbar.fn.doAction(
388410 $(this).parent().data( 'context' ),
389 - $(this).parent().data( 'actions' )[$(this).attr( 'rel' )]
 411+ $(this).parent().data( 'actions' )[$(this).attr( 'rel' )],
 412+ $(this)
390413 );
391414 return false;
392415 } );
Index: trunk/extensions/UsabilityInitiative/js/plugins.combined.js
@@ -625,24 +625,10 @@
626626 conf._data.keypressed_count = 0;
627627 })
628628 .keypress( function() {
629 - // When arrow up/down keys are held down,
630 - // keypress events fire rapidly. Slow this down
631 - // to one in every 120 ms
632 - if ( conf._data.keypressed == 38 || conf._data.keypressed == 40 ) {
633 - var now = new Date().getTime();
634 - if ( now - conf._data.last_keypress < 120 ) {
635 - return;
636 - }
637 - }
638 - conf._data.last_keypress = now;
639629 conf._data.keypressed_count++;
640630 processKey( conf._data.keypressed );
641631 })
642632 .keyup( function() {
643 - // Reset last_keypress here instead of in
644 - // keydown because at least in Firefox, all
645 - // keypresses are preceded by a keydown
646 - conf._data.last_keypress = 0;
647633 // Some browsers won't throw keypress() for
648634 // arrow keys. If we got a keydown and a keyup
649635 // without a keypress in between, solve that
@@ -1568,8 +1554,30 @@
15691555 *
15701556 * @param {Object} context
15711557 * @param {Object} action
 1558+ * @param {Object} source
15721559 */
1573 - doAction : function( context, action ) {
 1560+ doAction : function( context, action, source ) {
 1561+ // Verify that this has been called from a source that's within the toolbar
 1562+ if ( source.closest( '.wikiEditor-ui-toolbar' ).size() ) {
 1563+ // Build a unique id for this action by tracking the parent rel attributes up to the toolbar level
 1564+ var rels = [];
 1565+ var step = source;
 1566+ var i = 0;
 1567+ while ( !step.hasClass( 'wikiEditor-ui-toolbar' ) ) {
 1568+ if ( i > 25 ) {
 1569+ break;
 1570+ }
 1571+ i++;
 1572+ var rel = step.attr( 'rel' );
 1573+ if ( rel ) {
 1574+ rels.push( step.attr( 'rel' ) );
 1575+ }
 1576+ step = step.parent();
 1577+ }
 1578+ rels.reverse();
 1579+ var id = rels.join( '.' );
 1580+ // PERFORM CLICK TRACKING HERE!
 1581+ }
15741582 switch ( action.type ) {
15751583 case 'replace':
15761584 case 'encapsulate':
@@ -1658,7 +1666,7 @@
16591667 .data( 'context', context )
16601668 .click( function() {
16611669 $.wikiEditor.modules.toolbar.fn.doAction(
1662 - $(this).data( 'context' ), $(this).data( 'action' )
 1670+ $(this).data( 'context' ), $(this).data( 'action' ), $(this)
16631671 );
16641672 return false;
16651673 } );
@@ -1681,7 +1689,7 @@
16821690 .data( 'context', context )
16831691 .click( function() {
16841692 $.wikiEditor.modules.toolbar.fn.doAction(
1685 - $(this).data( 'context' ), $(this).data( 'action' )
 1693+ $(this).data( 'context' ), $(this).data( 'action' ), $(this)
16861694 );
16871695 } )
16881696 .text( optionLabel )
@@ -1758,7 +1766,8 @@
17591767 .click( function() {
17601768 $.wikiEditor.modules.toolbar.fn.doAction(
17611769 $(this).parent().data( 'context' ),
1762 - $(this).parent().data( 'actions' )[$(this).attr( 'rel' )]
 1770+ $(this).parent().data( 'actions' )[$(this).attr( 'rel' )],
 1771+ $(this)
17631772 );
17641773 return false;
17651774 } );
Index: trunk/extensions/UsabilityInitiative/js/plugins.combined.min.js
@@ -67,8 +67,7 @@
6868 conf.maxGrowFactor=2;if(typeof conf.maxRows=='undefined')
6969 conf.maxRows=7;if(typeof conf.submitOnClick=='undefined')
7070 conf.submitOnClick=false;if(typeof conf.suggestions!='object')
71 -conf.suggestions=[];conf._data={};conf._data.textbox=$(this);conf._data.timerID=null;conf._data.prevText=null;conf._data.visibleResults=0;conf._data.mouseDownOn=$([]);conf._data.div=$('<div />').addClass('os-suggest').css({top:Math.round($(this).offset().top)+this.offsetHeight,left:Math.round($(this).offset().left),width:$(this).outerWidth()}).hide().appendTo($('body'));$('<table />').addClass('os-suggest-results').width($(this).outerWidth()).appendTo(conf._data.div);$(this).attr('autocomplete','off').keydown(function(e){conf._data.keypressed=(e.keyCode==undefined)?e.which:e.keyCode;conf._data.keypressed_count=0;}).keypress(function(){if(conf._data.keypressed==38||conf._data.keypressed==40){var now=new Date().getTime();if(now-conf._data.last_keypress<120){return;}}
72 -conf._data.last_keypress=now;conf._data.keypressed_count++;processKey(conf._data.keypressed);}).keyup(function(){conf._data.last_keypress=0;if(conf._data.keypressed_count==0)
 71+conf.suggestions=[];conf._data={};conf._data.textbox=$(this);conf._data.timerID=null;conf._data.prevText=null;conf._data.visibleResults=0;conf._data.mouseDownOn=$([]);conf._data.div=$('<div />').addClass('os-suggest').css({top:Math.round($(this).offset().top)+this.offsetHeight,left:Math.round($(this).offset().left),width:$(this).outerWidth()}).hide().appendTo($('body'));$('<table />').addClass('os-suggest-results').width($(this).outerWidth()).appendTo(conf._data.div);$(this).attr('autocomplete','off').keydown(function(e){conf._data.keypressed=(e.keyCode==undefined)?e.which:e.keyCode;conf._data.keypressed_count=0;}).keypress(function(){conf._data.keypressed_count++;processKey(conf._data.keypressed);}).keyup(function(){if(conf._data.keypressed_count==0)
7372 processKey(conf._data.keypressed);}).blur(function(){if(conf._data.mouseDownOn.size()>0)
7473 return;conf._data.div.hide();cancelPendingSuggestions();});conf._data.div.mouseover(function(e){var tr=$(e.target).closest('.os-suggest tr');highlightResult(tr,false);}).mousedown(function(e){var tr=$(e.target).closest('.os-suggest tr');conf._data.mouseDownOn=tr;}).mouseup(function(e){var tr=$(e.target).closest('.os-suggest tr');var other=conf._data.mouseDownOn;conf._data.mouseDownOn=$([]);if(tr.get(0)!=other.get(0))
7574 return;highlightResult(tr,true);conf._data.div.hide();conf._data.textbox.focus();if(conf.submitOnClick)
@@ -146,21 +145,25 @@
147146 $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;}));}
148147 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();}
149148 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;}
150 -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){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]||'')}}
 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;}
 150+i++;var rel=step.attr('rel');if(rel){rels.push(step.attr('rel'));}
 151+step=step.parent();}
 152+rels.reverse();var id=rels.join('.');}
 153+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]||'')}}
151154 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];}
152155 $j('<div /> ').attr('id',action.id).html(action.html).data('context',context).appendTo($j('body')).each(action.init).dialog(dialogConf);}
153156 $j('#'+action.id).dialog('open');break;default:break;}},buildGroup:function(context,id,group){var $group=$('<div />').attr({'class':'group group-'+id,'rel':id});var label=$.wikiEditor.modules.toolbar.fn.autoMsg(group,'label');if(label){$group.append('<div class="label">'+label+'</div>')}
154157 if('tools'in group){for(tool in group.tools){$group.append($.wikiEditor.modules.toolbar.fn.buildTool(context,tool,group.tools[tool]));}}
155158 return $group;},buildTool:function(context,id,tool){if('filters'in tool){for(filter in tool.filters){if($(tool.filters[filter]).size()==0){return null;}}}
156159 var label=$.wikiEditor.modules.toolbar.fn.autoMsg(tool,'label');switch(tool.type){case'button':var src=tool.icon;if(src.indexOf('http://')!==0&&src.indexOf('https://')!==0){src=$.wikiEditor.modules.toolbar.imgPath+src;}
157 -$button=$('<img />').attr({'src':src,'width':22,'height':22,'alt':label,'title':label,'rel':id,'class':'tool tool-button'});if('action'in tool){$button.data('action',tool.action).data('context',context).click(function(){$.wikiEditor.modules.toolbar.fn.doAction($(this).data('context'),$(this).data('action'));return false;});}
158 -return $button;case'select':var $select=$('<div />').attr({'rel':id,'class':'tool tool-select'}).click(function(){var $options=$(this).find('.options');$options.animate({'opacity':'toggle'},'fast');});$options=$('<div />').addClass('options');if('list'in tool){for(option in tool.list){var optionLabel=$.wikiEditor.modules.toolbar.fn.autoMsg(tool.list[option],'label');$options.append($('<a />').data('action',tool.list[option].action).data('context',context).click(function(){$.wikiEditor.modules.toolbar.fn.doAction($(this).data('context'),$(this).data('action'));}).text(optionLabel).addClass('option').attr('rel',option));}}
 160+$button=$('<img />').attr({'src':src,'width':22,'height':22,'alt':label,'title':label,'rel':id,'class':'tool tool-button'});if('action'in tool){$button.data('action',tool.action).data('context',context).click(function(){$.wikiEditor.modules.toolbar.fn.doAction($(this).data('context'),$(this).data('action'),$(this));return false;});}
 161+return $button;case'select':var $select=$('<div />').attr({'rel':id,'class':'tool tool-select'}).click(function(){var $options=$(this).find('.options');$options.animate({'opacity':'toggle'},'fast');});$options=$('<div />').addClass('options');if('list'in tool){for(option in tool.list){var optionLabel=$.wikiEditor.modules.toolbar.fn.autoMsg(tool.list[option],'label');$options.append($('<a />').data('action',tool.list[option].action).data('context',context).click(function(){$.wikiEditor.modules.toolbar.fn.doAction($(this).data('context'),$(this).data('action'),$(this));}).text(optionLabel).addClass('option').attr('rel',option));}}
159162 $select.append($('<div />').addClass('menu').append($options));$select.append($('<div />').addClass('label').text(label));return $select;default:return null;}},buildBookmark:function(context,id,page){var label=$.wikiEditor.modules.toolbar.fn.autoMsg(page,'label');return $('<div />').text(label).attr('rel',id).data('context',context).click(function(){$(this).parent().parent().find('.page').hide();$(this).parent().parent().find('.page-'+$(this).attr('rel')).show();$(this).siblings().removeClass('current');$(this).addClass('current');var section=$(this).parent().parent().attr('rel');$.cookie('wikiEditor-'+$(this).data('context').instance+'-booklet-'+section+'-page',$(this).attr('rel'));});},buildPage:function(context,id,page){var $page=$('<div />').attr({'class':'page page-'+id,'rel':id});switch(page.layout){case'table':$page.addClass('page-table');var html='<table cellpadding=0 cellspacing=0 '+'border=0 width="100%" class="table table-"'+id+'">';if('headings'in page){html+=$.wikiEditor.modules.toolbar.fn.buildHeading(context,page.headings)}
160163 if('rows'in page){for(row in page.rows){html+=$.wikiEditor.modules.toolbar.fn.buildRow(context,page.rows[row])}}
161164 $page.html(html);break;case'characters':$page.addClass('page-characters');$characters=$('<div />').data('context',context).data('actions',{});var actions=$characters.data('actions');if('language'in page){$characters.attr('lang',page.language);}
162165 if('direction'in page){$characters.attr('dir',page.direction);}
163166 if('characters'in page){var html='';for(character in page.characters){html+=$.wikiEditor.modules.toolbar.fn.buildCharacter(page.characters[character],actions);}
164 -$characters.html(html).children().click(function(){$.wikiEditor.modules.toolbar.fn.doAction($(this).parent().data('context'),$(this).parent().data('actions')[$(this).attr('rel')]);return false;});}
 167+$characters.html(html).children().click(function(){$.wikiEditor.modules.toolbar.fn.doAction($(this).parent().data('context'),$(this).parent().data('actions')[$(this).attr('rel')],$(this));return false;});}
165168 $page.append($characters);break;}
166169 return $page;},buildHeading:function(context,headings){var html='<tr>';for(heading in headings){html+='<th>'+$.wikiEditor.modules.toolbar.fn.autoMsg(headings[heading],'content')+'</th>';}
167170 return html;},buildRow:function(context,row){var html='<tr>';for(cell in row){html+='<td class="cell cell-'+cell+'" valign="top"><span>'+

Follow-up revisions

RevisionCommit summaryAuthorDate
r55532EditToolbar:...catrope17:55, 23 August 2009

Status & tagging log