r101790 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r101789‎ | r101790 | r101791 >
Date:05:54, 3 November 2011
Author:santhosh
Status:ok
Tags:
Comment:
Fix the shortcut key of Narayam in OSX and Firefox, Opera browsers.
Refer Bug 31026

i18n card #188, #172o
Modified paths:
  • /trunk/extensions/Narayam/js/ext.narayam.core.js (modified) (history)

Diff [purge]

Index: trunk/extensions/Narayam/js/ext.narayam.core.js
@@ -35,8 +35,9 @@
3636 var allImes = mw.config.get( 'wgNarayamAllSchemes' ) || {};
3737 // Currently selected scheme
3838 var currentScheme = null;
 39+ // Shortcut key for turning Narayam on and off
 40+ var shortcutKey = getShortCutKey();
3941
40 -
4142 /* Private functions */
4243
4344 /**
@@ -112,18 +113,62 @@
113114 * @return bool
114115 */
115116 function isShortcutKey( e ) {
116 - return e.ctrlKey &&
117 - String.fromCharCode( e.which ).toLowerCase() == 'm';
 117+ return e.altKey == shortcutKey.altKey &&
 118+ e.ctrlKey == shortcutKey.ctrlKey &&
 119+ e.shiftKey == shortcutKey.shiftKey &&
 120+ String.fromCharCode( e.which ).toLowerCase() == shortcutKey.key.toLowerCase();
118121 }
119 -
 122+
120123 /**
 124+ * Get the shortcut key for the tool, depending on OS, browser
 125+ * @return shortcutKey
 126+ */
 127+ function getShortCutKey() {
 128+ var defaultShortcut = {
 129+ altKey: false,
 130+ ctrlKey: true,
 131+ shiftKey: false,
 132+ cmdKey: false,
 133+ key: 'm'
 134+ }
 135+ // Browser sniffing to determine the available shortcutKey
 136+ // Refer: mediawiki.util.js and en.wikipedia.org/wiki/Access_key
 137+ var profile = $.client.profile();
 138+ // Safari/Konqueror on any platform, but not Safari on Windows
 139+ // or any browser on Mac except chrome and opera
 140+ if ( !( profile.platform == 'win' && profile.name == 'safari' ) &&
 141+ ( profile.name == 'safari'|| profile.platform == 'mac' || profile.name == 'konqueror' )
 142+ && !(profile.name == 'opera' || profile.name == 'chrome' ) ) {
 143+ defaultShortcut.key = 'g';
 144+ }
 145+ // For Opera in OSX, shortcut is control+command+m.
 146+ if ( profile.name == 'opera' && profile.platform == 'mac' ) {
 147+ defaultShortcut.cmdKey = true;
 148+ }
 149+ return defaultShortcut;
 150+ }
 151+
 152+ /**
121153 * Get a description of the shortcut key, e.g. "Ctrl-M"
122154 * @return string
123155 */
124156 function shortcutText() {
125 - var text = 'Ctrl-M';
126 - // TODO: Address Bug #31026
127 - return text;
 157+ var text = '';
 158+ // TODO: Localize these things (in core, too)
 159+ if ( shortcutKey.ctrlKey ) {
 160+ text += 'Ctrl-';
 161+ }
 162+ if ( shortcutKey.shiftKey ) {
 163+ text += 'Shift-';
 164+ }
 165+ if ( shortcutKey.altKey ) {
 166+ text += 'Alt-';
 167+ }
 168+ if ( shortcutKey.cmdKey ) {
 169+ text += 'Command-';
 170+ }
 171+ text += shortcutKey.key.toUpperCase();
 172+ return text;
128173 }
129174
130175 /**

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r101605Remove the option to have configurable shortcut key. It wont work in all brow...santhosh09:34, 2 November 2011

Status & tagging log