r59812 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r59811‎ | r59812 | r59813 >
Date:00:30, 8 December 2009
Author:adam
Status:ok (Comments)
Tags:
Comment:
Adding a disabling button to the insert link dialog
Modified paths:
  • /trunk/extensions/UsabilityInitiative/UsabilityInitiative.hooks.php (modified) (history)
  • /trunk/extensions/UsabilityInitiative/WikiEditor/Modules/Toolbar/Toolbar.js (modified) (history)
  • /trunk/extensions/UsabilityInitiative/WikiEditor/WikiEditor.combined.js (modified) (history)
  • /trunk/extensions/UsabilityInitiative/WikiEditor/WikiEditor.combined.min.js (modified) (history)
  • /trunk/extensions/UsabilityInitiative/WikiEditor/WikiEditor.hooks.php (modified) (history)
  • /trunk/extensions/UsabilityInitiative/css/combined.css (modified) (history)
  • /trunk/extensions/UsabilityInitiative/css/combined.min.css (modified) (history)
  • /trunk/extensions/UsabilityInitiative/css/wikiEditor.dialogs.css (modified) (history)
  • /trunk/extensions/UsabilityInitiative/js/plugins.combined.js (modified) (history)
  • /trunk/extensions/UsabilityInitiative/js/plugins.combined.min.js (modified) (history)

Diff [purge]

Index: trunk/extensions/UsabilityInitiative/UsabilityInitiative.hooks.php
@@ -21,17 +21,17 @@
2222 array( 'src' => 'css/suggestions.css', 'version' => 6 ),
2323 array( 'src' => 'css/wikiEditor.css', 'version' => 7 ),
2424 array( 'src' => 'css/wikiEditor.toolbar.css', 'version' => 7 ),
25 - array( 'src' => 'css/wikiEditor.dialogs.css', 'version' => 4 ),
 25+ array( 'src' => 'css/wikiEditor.dialogs.css', 'version' => 5 ),
2626 array( 'src' => 'css/wikiEditor.toc.css', 'version' => 23 ),
2727 array( 'src' => 'css/wikiEditor.preview.css', 'version' => 1 ),
2828 array( 'src' => 'css/vector/jquery-ui-1.7.2.css', 'version' => '1.7.2y' ),
2929 ),
3030 'combined' => array(
31 - array( 'src' => 'css/combined.css', 'version' => 32 ),
 31+ array( 'src' => 'css/combined.css', 'version' => 33 ),
3232 array( 'src' => 'css/vector/jquery-ui-1.7.2.css', 'version' => '1.7.2y' ),
3333 ),
3434 'minified' => array(
35 - array( 'src' => 'css/combined.min.css', 'version' => 32 ),
 35+ array( 'src' => 'css/combined.min.css', 'version' => 33 ),
3636 array( 'src' => 'css/vector/jquery-ui-1.7.2.css', 'version' => '1.7.2y' ),
3737 ),
3838 )
Index: trunk/extensions/UsabilityInitiative/css/wikiEditor.dialogs.css
@@ -17,4 +17,10 @@
1818 .ui-dialog-content .status-invalid input {
1919 border: 2px solid red;
2020 padding: 2px 1px;
 21+}
 22+
 23+.ui-dialog .ui-dialog-buttonpane button.disabled {
 24+ color: #7f7f7f;
 25+ background: #f2f2f2;
 26+ border-color: #cccccc;
2127 }
\ No newline at end of file
Index: trunk/extensions/UsabilityInitiative/css/combined.css
@@ -177,6 +177,12 @@
178178 .ui-dialog-content .status-invalid input {
179179 border: 2px solid red;
180180 padding: 2px 1px;
 181+}
 182+
 183+.ui-dialog .ui-dialog-buttonpane button.disabled {
 184+ color: #7f7f7f;
 185+ background: #f2f2f2;
 186+ border-color: #cccccc;
181187 }/* wikiEditor toc module */
182188 body.rtl .wikiEditor-ui-text {
183189 border-right: none;
Index: trunk/extensions/UsabilityInitiative/css/combined.min.css
@@ -167,6 +167,11 @@
168168 border:2px solid red;
169169 padding:2px 1px;
170170 }
 171+.ui-dialog .ui-dialog-buttonpane button.disabled{
 172+color:#7f7f7f;
 173+background:#f2f2f2;
 174+border-color:#cccccc;
 175+}
171176 body.rtl .wikiEditor-ui-text{
172177 border-right:none;
173178 border-left:solid silver 1px;
@@ -707,4 +712,4 @@
708713 .wikiEditor-preview-contents{
709714 padding:1em;
710715 background-color:white;
711 -}
\ No newline at end of file
 716+}
Index: trunk/extensions/UsabilityInitiative/WikiEditor/WikiEditor.hooks.php
@@ -16,14 +16,14 @@
1717 array( 'src' => 'Modules/Preview/Preview.js', 'version' => 3 ),
1818 array( 'src' => 'Modules/Publish/Publish.js', 'version' => 2 ),
1919 array( 'src' => 'Modules/Toc/Toc.js', 'version' => 2 ),
20 - array( 'src' => 'Modules/Toolbar/Toolbar.js', 'version' => 13 ),
 20+ array( 'src' => 'Modules/Toolbar/Toolbar.js', 'version' => 14 ),
2121 array( 'src' => 'Modules/Toolbar/TemplateEditor.js', 'version' => 1 ),
2222 ),
2323 'combined' => array(
24 - array( 'src' => 'WikiEditor.combined.js', 'version' => 11 ),
 24+ array( 'src' => 'WikiEditor.combined.js', 'version' => 12 ),
2525 ),
2626 'minified' => array(
27 - array( 'src' => 'WikiEditor.combined.min.js', 'version' => 11 ),
 27+ array( 'src' => 'WikiEditor.combined.min.js', 'version' => 12 ),
2828 ),
2929 );
3030 static $messages = array(
Index: trunk/extensions/UsabilityInitiative/WikiEditor/WikiEditor.combined.js
@@ -937,6 +937,15 @@
938938 $j( '#wikieditor-toolbar-link-int-target-status-' + status ).show();
939939 $j( '#wikieditor-toolbar-link-int-target' ).parent().addClass( 'status-' + status );
940940 }
 941+ if ( status == 'invalid' ) {
 942+ $j( '.ui-dialog:visible .ui-dialog-buttonpane button:first' )
 943+ .attr('disabled', true)
 944+ .addClass('disabled');
 945+ } else {
 946+ $j( '.ui-dialog:visible .ui-dialog-buttonpane button:first' )
 947+ .removeAttr('disabled')
 948+ .removeClass('disabled');
 949+ }
941950 }
942951 // Abort previous request
943952 var request = $j( '#wikieditor-toolbar-link-int-target-status' ).data( 'request' );
@@ -1234,7 +1243,7 @@
12351244 insertText = '[' + escTarget + ' ' + escText + ']';
12361245 }
12371246 // Preserve whitespace in selection when replacing
1238 - insertText = whitespace[0] + insertText + whitespace[1];
 1247+ if ( whitespace ) insertText = whitespace[0] + insertText + whitespace[1];
12391248 $j.wikiEditor.modules.toolbar.fn.doAction( $j(this).data( 'context' ), {
12401249 type: 'replace',
12411250 options: {
Index: trunk/extensions/UsabilityInitiative/WikiEditor/WikiEditor.combined.min.js
@@ -33,7 +33,8 @@
3434 </tr>\
3535 </table></fieldset>',init:function(){function isExternalLink(s){if(typeof arguments.callee.regex=='undefined'){arguments.callee.regex=new RegExp("(^("+urlprotocols+"))|(^www\\.)|([^.]\\.[a-z]{2,}($|\\/))",'i');}
3636 return s.match(arguments.callee.regex);}
37 -function updateExistence(){function updateWidget(status){$j('#wikieditor-toolbar-link-int-target-status').children().hide();$j('#wikieditor-toolbar-link-int-target').parent().removeClass('status-invalid status-external status-notexists status-exists status-loading');if(status){$j('#wikieditor-toolbar-link-int-target-status-'+status).show();$j('#wikieditor-toolbar-link-int-target').parent().addClass('status-'+status);}}
 37+function updateExistence(){function updateWidget(status){$j('#wikieditor-toolbar-link-int-target-status').children().hide();$j('#wikieditor-toolbar-link-int-target').parent().removeClass('status-invalid status-external status-notexists status-exists status-loading');if(status){$j('#wikieditor-toolbar-link-int-target-status-'+status).show();$j('#wikieditor-toolbar-link-int-target').parent().addClass('status-'+status);}
 38+if(status=='invalid'){$j('.ui-dialog:visible .ui-dialog-buttonpane button:first').attr('disabled',true).addClass('disabled');}else{$j('.ui-dialog:visible .ui-dialog-buttonpane button:first').removeAttr('disabled').removeClass('disabled');}}
3839 var request=$j('#wikieditor-toolbar-link-int-target-status').data('request');if(request){request.abort();}
3940 var target=$j('#wikieditor-toolbar-link-int-target').val();var cache=$j('#wikieditor-toolbar-link-int-target-status').data('existencecache');if(cache[target]){updateWidget(cache[target]);return;}
4041 if(target==''){updateWidget(false);return;}
@@ -68,7 +69,7 @@
6970 insertText=escTarget;else if(text=='')
7071 insertText='['+escTarget+']';else
7172 insertText='['+escTarget+' '+escText+']';}
72 -insertText=whitespace[0]+insertText+whitespace[1];$j.wikiEditor.modules.toolbar.fn.doAction($j(this).data('context'),{type:'replace',options:{pre:insertText}},$j(this));$j('#wikieditor-toolbar-link-int-target, #wikieditor-toolbar-link-int-text').val('');$j('#wikieditor-toolbar-link-type-int, #wikieditor-toolbar-link-type-ext').attr('checked','');$j(this).dialog('close');},'wikieditor-toolbar-tool-link-cancel':function(){$j(this).dialog('close');}},open:function(){$j(this).data('articlePathRegex',new RegExp('^'+RegExp.escape(wgServer+wgArticlePath).replace(/\\\$1/g,'(.*)')+'$'));var selection=$j(this).data('context').$textarea.textSelection('getSelection');$j('#wikieditor-toolbar-link-int-target').focus();$j('#wikieditor-toolbar-link-dialog').data('whitespace',['','']);if(selection!=''){var target,text,type;var matches;if((matches=selection.match(/^(\s*)\[\[([^\]\|]+)(\|([^\]\|]*))?\]\](\s*)$/))){target=matches[2];text=(matches[4]?matches[4]:matches[2]);type='int';$j('#wikieditor-toolbar-link-dialog').data('whitespace',[matches[1],matches[5]]);}else if((matches=selection.match(/^(\s*)\[([^\] ]+)( ([^\]]+))?\](\s*)$/))){target=matches[2];text=(matches[4]?matches[4]:'');type='ext';$j('#wikieditor-toolbar-link-dialog').data('whitespace',[matches[1],matches[5]]);}else{target=text=selection;}
 73+if(whitespace)insertText=whitespace[0]+insertText+whitespace[1];$j.wikiEditor.modules.toolbar.fn.doAction($j(this).data('context'),{type:'replace',options:{pre:insertText}},$j(this));$j('#wikieditor-toolbar-link-int-target, #wikieditor-toolbar-link-int-text').val('');$j('#wikieditor-toolbar-link-type-int, #wikieditor-toolbar-link-type-ext').attr('checked','');$j(this).dialog('close');},'wikieditor-toolbar-tool-link-cancel':function(){$j(this).dialog('close');}},open:function(){$j(this).data('articlePathRegex',new RegExp('^'+RegExp.escape(wgServer+wgArticlePath).replace(/\\\$1/g,'(.*)')+'$'));var selection=$j(this).data('context').$textarea.textSelection('getSelection');$j('#wikieditor-toolbar-link-int-target').focus();$j('#wikieditor-toolbar-link-dialog').data('whitespace',['','']);if(selection!=''){var target,text,type;var matches;if((matches=selection.match(/^(\s*)\[\[([^\]\|]+)(\|([^\]\|]*))?\]\](\s*)$/))){target=matches[2];text=(matches[4]?matches[4]:matches[2]);type='int';$j('#wikieditor-toolbar-link-dialog').data('whitespace',[matches[1],matches[5]]);}else if((matches=selection.match(/^(\s*)\[([^\] ]+)( ([^\]]+))?\](\s*)$/))){target=matches[2];text=(matches[4]?matches[4]:'');type='ext';$j('#wikieditor-toolbar-link-dialog').data('whitespace',[matches[1],matches[5]]);}else{target=text=selection;}
7374 if(typeof text!='undefined')
7475 $j('#wikieditor-toolbar-link-int-text').val(text).change();if(typeof target!='undefined')
7576 $j('#wikieditor-toolbar-link-int-target').val(target).change();if(typeof type!='undefined')
Index: trunk/extensions/UsabilityInitiative/WikiEditor/Modules/Toolbar/Toolbar.js
@@ -889,6 +889,15 @@
890890 $j( '#wikieditor-toolbar-link-int-target-status-' + status ).show();
891891 $j( '#wikieditor-toolbar-link-int-target' ).parent().addClass( 'status-' + status );
892892 }
 893+ if ( status == 'invalid' ) {
 894+ $j( '.ui-dialog:visible .ui-dialog-buttonpane button:first' )
 895+ .attr('disabled', true)
 896+ .addClass('disabled');
 897+ } else {
 898+ $j( '.ui-dialog:visible .ui-dialog-buttonpane button:first' )
 899+ .removeAttr('disabled')
 900+ .removeClass('disabled');
 901+ }
893902 }
894903 // Abort previous request
895904 var request = $j( '#wikieditor-toolbar-link-int-target-status' ).data( 'request' );
@@ -1186,7 +1195,7 @@
11871196 insertText = '[' + escTarget + ' ' + escText + ']';
11881197 }
11891198 // Preserve whitespace in selection when replacing
1190 - insertText = whitespace[0] + insertText + whitespace[1];
 1199+ if ( whitespace ) insertText = whitespace[0] + insertText + whitespace[1];
11911200 $j.wikiEditor.modules.toolbar.fn.doAction( $j(this).data( 'context' ), {
11921201 type: 'replace',
11931202 options: {
Index: trunk/extensions/UsabilityInitiative/js/plugins.combined.js
@@ -1526,28 +1526,32 @@
15271527 /* Event Handlers */
15281528 context.evt = {
15291529 'change': function( event ) {
1530 - // BTW: context is in event.data.context
1531 -
15321530 switch ( event.type ) {
15331531 case 'keypress':
1534 - if ( /* something interesting was deleted */ false ) {
1535 - //console.log( 'MAJOR CHANGE' );
 1532+ if ( /* TODO: test if something interesting was deleted */ true ) {
 1533+ event.data.scope = 'division';
15361534 } else {
1537 - //console.log( 'MINOR CHANGE' );
 1535+ event.data.scope = 'character';
15381536 }
15391537 break;
15401538 case 'mousedown': // FIXME: mouseup?
1541 - if ( /* text was dragged and dropped */ false ) {
1542 - //console.log( 'MAJOR CHANGE' );
 1539+ if ( /* TODO: test if text was dragged and dropped */ true ) {
 1540+ event.data.scope = 'division';
15431541 } else {
1544 - //console.log( 'MINOR CHANGE' );
 1542+ event.data.scope = 'none';
15451543 }
15461544 break;
15471545 default:
1548 - //console.log( 'MAJOR CHANGE' );
 1546+ event.data.scope = 'division';
15491547 break;
15501548 }
1551 -
 1549+ if ( event.data.scope !== 'none' ) {
 1550+ for ( module in $.wikiEditor.modules ) {
 1551+ if ( 'evt' in $.wikiEditor.modules[module] && 'change' in $.wikiEditor.modules[module].evt ) {
 1552+ $.wikiEditor.modules[module].evt.change( context, event );
 1553+ }
 1554+ }
 1555+ }
15521556 }
15531557 };
15541558
Index: trunk/extensions/UsabilityInitiative/js/plugins.combined.min.js
@@ -90,9 +90,10 @@
9191 src=path+src;return src+'?'+wgWikiEditorIconVersion;},'fixOperaBrokenness':function(s){return s;}};$.fn.wikiEditor=function(){if($j.wikiEditor.isSupportKnown()&&!$j.wikiEditor.isSupported()){return $(this);}
9292 var context=$(this).data('wikiEditor-context');if(typeof context=='undefined'){var instance=$.wikiEditor.instances.length;context={'$textarea':$(this),'views':{},'modules':{},'data':{},'instance':instance};$.wikiEditor.instances[instance]=$(this);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);}}
9393 if(typeof data=='string'){callModuleApi(data,'create',{});}else if(typeof data=='object'){for(module in data){if(typeof module=='string'){callModuleApi(module,'create',data[module]);}}}}};for(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 -context.evt={'change':function(event){switch(event.type){case'keypress':if(false){}else{}
95 -break;case'mousedown':if(false){}else{}
96 -break;default:break;}}};context.fn={'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);}
 94+context.evt={'change':function(event){switch(event.type){case'keypress':if(true){event.data.scope='division';}else{event.data.scope='character';}
 95+break;case'mousedown':if(true){event.data.scope='division';}else{event.data.scope='none';}
 96+break;default:event.data.scope='division';break;}
 97+if(event.data.scope!=='none'){for(module in $.wikiEditor.modules){if('evt'in $.wikiEditor.modules[module]&&'change'in $.wikiEditor.modules[module].evt){$.wikiEditor.modules[module].evt.change(context,event);}}}}};context.fn={'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);}
9798 event.preventDefault();return false;}).text($.wikiEditor.autoMsg(options,'title'))).appendTo(context.$tabs);}
9899 if(!context.$tabs.children().size()){addTab({'name':'wikitext','titleMsg':'wikieditor-wikitext-tab'});}
99100 addTab(options);return $('<div></div>').addClass('wikiEditor-ui-view wikiEditor-ui-view-'+options.name).hide().appendTo(context.$ui);},'setup':function(){var contentHTML=$('<div />').text(context.$textarea.val()).html();context.$iframe[0].contentWindow.document.open();context.$iframe[0].contentWindow.document.write('<html><head><title>wikiEditor</title><script>var context = window.parent.jQuery.wikiEditor.instances['+context.instance+'].data( "wikiEditor-context" ); window.parent.jQuery( document ).bind( "keydown keypress keyup mousedown mouseup cut paste", { "context": context }, context.evt.change );</script></head><body style="margin:0;padding:0;width:100%;height:100%;white-space:pre-wrap;font-family:monospace">'+contentHTML+'</body></html>');context.$iframe[0].contentWindow.document.close();context.$iframe[0].contentWindow.document.designMode='on';context.$content=$(context.$iframe[0].contentWindow.document.body);if($('body').is('.rtl')){context.$content.addClass('rtl').attr('dir','rtl');}

Follow-up revisions

RevisionCommit summaryAuthorDate
r59854Addressing Roan's comments on r59817 and r59812. Also adding a css rule to wi...adam22:28, 8 December 2009

Comments

#Comment by Catrope (talk | contribs)   13:19, 8 December 2009
+							.attr('disabled', true)
+							.addClass('disabled');

Please use the same coding style as the rest of the file, which in this case means using .addClass( 'disabled' );.

-					insertText = whitespace[0] + insertText + whitespace[1];
+					if ( whitespace ) insertText = whitespace[0] + insertText + whitespace[1];

If I'm not mistaken, whitespace is always defined (initialized to [, ]), so this conditional is useless.

Status & tagging log