r56948 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r56947‎ | r56948 | r56949 >
Date:11:23, 26 September 2009
Author:catrope
Status:ok
Tags:
Comment:
EditToolbar: (bug 20605) Also trigger Insert/Replace button when Enter key is pressed on the dialog. This doesn't work in all browsers: Chrome, for one, doesn't seem to catch keypress events at all when the dialog or one of its non-form field children is selected.
Modified paths:
  • /trunk/extensions/UsabilityInitiative/EditToolbar/EditToolbar.js (modified) (history)
  • /trunk/extensions/UsabilityInitiative/EditToolbar/EditToolbar.php (modified) (history)

Diff [purge]

Index: trunk/extensions/UsabilityInitiative/EditToolbar/EditToolbar.js
@@ -757,7 +757,7 @@
758758 <li><a href="#edittoolbar-link-dialog-tab-int" rel="edittoolbar-tool-link-int"></a></li>\
759759 <li><a href="#edittoolbar-link-dialog-tab-ext" rel="edittoolbar-tool-link-ext"></a></li>\
760760 </ul>\
761 - <div id="edittoolbar-link-dialog-tab-int"><form><fieldset><table><tr>\
 761+ <div id="edittoolbar-link-dialog-tab-int"><fieldset><table><tr>\
762762 <td><label for="edittoolbar-link-int-target" rel="edittoolbar-tool-link-int-target"></label></td>\
763763 <td>\
764764 <input type="text" id="edittoolbar-link-int-target" />\
@@ -766,14 +766,14 @@
767767 </tr><tr>\
768768 <td><label for="edittoolbar-link-int-text" rel="edittoolbar-tool-link-int-text"></label></td>\
769769 <td><input type="text" id="edittoolbar-link-int-text" /></td>\
770 - </table></fieldset><input type="submit" style="display: none;" /></form></div>\
771 - <div id="edittoolbar-link-dialog-tab-ext"><form><fieldset><table><tr>\
 770+ </table></fieldset></div>\
 771+ <div id="edittoolbar-link-dialog-tab-ext"><fieldset><table><tr>\
772772 <td><label for="edittoolbar-link-ext-target" rel="edittoolbar-tool-link-ext-target"></label></td>\
773773 <td><input type="text" id="edittoolbar-link-ext-target" /></td>\
774774 </tr><tr>\
775775 <td><label for="edittoolbar-link-ext-text" rel="edittoolbar-tool-link-ext-text"></label></td>\
776776 <td><input type="text" id="edittoolbar-link-ext-text" /></td>\
777 - </table></fieldset><input type="submit" style="display: none;" /></form></div>\
 777+ </table></fieldset></div>\
778778 </div>',
779779 init: function() {
780780 // Updates the UI to show if the page title being inputed by the user exists or not
@@ -838,15 +838,6 @@
839839 $j(this).find( '[rel]' ).each( function() {
840840 $j(this).text( gM( $j(this).attr( 'rel' ) ) );
841841 });
842 - // Assign the proper action to the hidden submit buttons
843 - // triggered when the user presses Enter
844 - $j(this).find( 'form' ).submit( function( e ) {
845 - e.preventDefault();
846 - $j(this)
847 - .closest( '.ui-dialog' )
848 - .find( 'button:first' )
849 - .click();
850 - });
851842 // Build tabs
852843 $j( '#edittoolbar-link-tabs' ).tabs();
853844 // Automatically copy the value of the internal link page title field to the link text field unless the user
@@ -1023,8 +1014,8 @@
10241015 open: function() {
10251016 // Pre-fill the text fields based on the current selection
10261017 var selection = $j(this).data( 'context' ).$textarea.getSelection();
1027 - $j( '#edittoolbar-link-dialog-tab-int' ).data( 'whitespace', [ '', '' ] );
1028 - $j( '#edittoolbar-link-dialog-tab-ext' ).data( 'whitespace', [ '', '' ] );
 1018+ $j( '#edittoolbar-link-dialog-tab-int' ).data( 'whitespace', [ '', '' ] );
 1019+ $j( '#edittoolbar-link-dialog-tab-ext' ).data( 'whitespace', [ '', '' ] );
10291020 if ( selection != '' ) {
10301021 var intText, intTarget, extText, extTarget;
10311022 var matches;
@@ -1063,6 +1054,19 @@
10641055 $j( '#edittoolbar-link-int-text' ).val() == $j( '#edittoolbar-link-int-target' ).val()
10651056 );
10661057 $j( '#edittoolbar-link-int-target' ).suggestions();
 1058+
 1059+ if ( !( $j(this).data( 'dialogkeypressset' ) ) ) {
 1060+ $j(this).data( 'dialogkeypressset', true );
 1061+ // Execute the action associated with the first button
 1062+ // when the user presses Enter
 1063+ $j(this).closest( '.ui-dialog' ).keypress( function( e ) {
 1064+ if ( ( e.keyCode || e.which ) == 13 ) {
 1065+ $j(this)
 1066+ .find( 'button:first' )
 1067+ .click();
 1068+ }
 1069+ });
 1070+ }
10671071 }
10681072 }
10691073 },
@@ -1070,7 +1074,7 @@
10711075 titleMsg: 'edittoolbar-tool-table-title',
10721076 id: 'edittoolbar-table-dialog',
10731077 html: '\
1074 - <form><fieldset><legend rel="edittoolbar-tool-table-dimensions"></legend><table><tr>\
 1078+ <fieldset><legend rel="edittoolbar-tool-table-dimensions"></legend><table><tr>\
10751079 <td><input type="checkbox" id="edittoolbar-table-dimensions-header" value="1" /></td>\
10761080 <td class="label"><label for="edittoolbar-table-dimensions-header"\
10771081 rel="edittoolbar-tool-table-dimensions-header"></label></td>\
@@ -1081,19 +1085,19 @@
10821086 <td class="label"><label for="edittoolbar-table-dimensions-rows"\
10831087 rel="edittoolbar-tool-table-dimensions-rows"></label></td>\
10841088 <td><input type="text" id="edittoolbar-table-dimensions-rows" size="2" /></td>\
1085 - </tr></table></fieldset><input type="submit" style="display: none;" /></form>',
 1089+ </tr></table></fieldset>',
10861090 init: function() {
10871091 $j(this).find( '[rel]' ).each( function() {
10881092 $j(this).text( gM( $j(this).attr( 'rel' ) ) );
10891093 });
1090 - // Assign the proper action to the hidden submit buttons
1091 - // triggered when the user presses Enter
1092 - $j(this).find( 'form' ).submit( function( e ) {
1093 - e.preventDefault();
1094 - $j(this)
1095 - .closest( '.ui-dialog' )
1096 - .find( 'button:first' )
1097 - .click();
 1094+ // Execute the action associated with the first button
 1095+ // when the user presses Enter
 1096+ $j(this).closest( '.ui-dialog' ).keypress( function( e ) {
 1097+ if ( ( e.keyCode || e.which ) == 13 ) {
 1098+ $j(this)
 1099+ .find( 'button:first' )
 1100+ .click();
 1101+ }
10981102 });
10991103 $j( '#edittoolbar-table-dimensions-rows' ).val( 2 );
11001104 $j( '#edittoolbar-table-dimensions-columns' ).val( 2 );
@@ -1139,6 +1143,20 @@
11401144 'edittoolbar-tool-table-cancel': function() {
11411145 $j(this).dialog( 'close' );
11421146 }
 1147+ },
 1148+ open: function() {
 1149+ if ( !( $j(this).data( 'dialogkeypressset' ) ) ) {
 1150+ $j(this).data( 'dialogkeypressset', true );
 1151+ // Execute the action associated with the first button
 1152+ // when the user presses Enter
 1153+ $j(this).closest( '.ui-dialog' ).keypress( function( e ) {
 1154+ if ( ( e.keyCode || e.which ) == 13 ) {
 1155+ $j(this)
 1156+ .find( 'button:first' )
 1157+ .click();
 1158+ }
 1159+ });
 1160+ }
11431161 }
11441162 }
11451163 },
@@ -1146,7 +1164,7 @@
11471165 titleMsg: 'edittoolbar-tool-replace-title',
11481166 id: 'edittoolbar-replace-dialog',
11491167 html: '\
1150 - <form><fieldset><table><tr>\
 1168+ <fieldset><table><tr>\
11511169 <td><label for="edittoolbar-replace-search" rel="edittoolbar-tool-replace-search"></label></td>\
11521170 <td><input type="text" id="edittoolbar-replace-search" /></td>\
11531171 </tr><tr>\
@@ -1161,19 +1179,19 @@
11621180 </tr><tr>\
11631181 <td><input type="checkbox" id="edittoolbar-replace-all" /></td>\
11641182 <td><label for="edittoolbar-replace-all" rel="edittoolbar-tool-replace-all"></label></td>\
1165 - </tr></table></fieldset><input type="submit" style="display: none;" /></form>',
 1183+ </tr></table></fieldset>',
11661184 init: function() {
11671185 $j(this).find( '[rel]' ).each( function() {
11681186 $j(this).text( gM( $j(this).attr( 'rel' ) ) );
11691187 });
1170 - // Assign the proper action to the hidden submit buttons
1171 - // triggered when the user presses Enter
1172 - $j(this).find( 'form' ).submit( function( e ) {
1173 - e.preventDefault();
1174 - $j(this)
1175 - .closest( '.ui-dialog' )
1176 - .find( 'button:first' )
1177 - .click();
 1188+ // Execute the action associated with the first button
 1189+ // when the user presses Enter
 1190+ $j(this).closest( '.ui-dialog' ).keypress( function( e ) {
 1191+ if ( ( e.keyCode || e.which ) == 13 ) {
 1192+ $j(this)
 1193+ .find( 'button:first' )
 1194+ .click();
 1195+ }
11781196 });
11791197 },
11801198 dialog: {
@@ -1252,6 +1270,20 @@
12531271 $j(this).dialog( 'close' );
12541272 $j(this).data( 'context' ).$textarea.focus();
12551273 }
 1274+ },
 1275+ open: function() {
 1276+ if ( !( $j(this).data( 'dialogkeypressset' ) ) ) {
 1277+ $j(this).data( 'dialogkeypressset', true );
 1278+ // Execute the action associated with the first button
 1279+ // when the user presses Enter
 1280+ $j(this).closest( '.ui-dialog' ).keypress( function( e ) {
 1281+ if ( ( e.keyCode || e.which ) == 13 ) {
 1282+ $j(this)
 1283+ .find( 'button:first' )
 1284+ .click();
 1285+ }
 1286+ });
 1287+ }
12561288 }
12571289 }
12581290 }
Index: trunk/extensions/UsabilityInitiative/EditToolbar/EditToolbar.php
@@ -19,7 +19,7 @@
2020 /* Configuration */
2121
2222 // Bump the version number every time you change any of the .css/.js files
23 -$wgEditToolbarStyleVersion = 37;
 23+$wgEditToolbarStyleVersion = 38;
2424
2525 // Set this to true to simply override the stock toolbar for everyone
2626 $wgEditToolbarGlobalEnable = false;

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r56391EditToolbar: (bug 20605) Trigger Insert/Replace when Enter key is pressed by ...catrope19:40, 15 September 2009

Status & tagging log