Index: trunk/extensions/Narayam/js/ext.narayam.core.js |
— | — | @@ -35,8 +35,9 @@ |
36 | 36 | var allImes = mw.config.get( 'wgNarayamAllSchemes' ) || {}; |
37 | 37 | // Currently selected scheme |
38 | 38 | var currentScheme = null; |
| 39 | + // Shortcut key for turning Narayam on and off |
| 40 | + var shortcutKey = getShortCutKey(); |
39 | 41 | |
40 | | - |
41 | 42 | /* Private functions */ |
42 | 43 | |
43 | 44 | /** |
— | — | @@ -112,18 +113,62 @@ |
113 | 114 | * @return bool |
114 | 115 | */ |
115 | 116 | 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(); |
118 | 121 | } |
119 | | - |
| 122 | + |
120 | 123 | /** |
| 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 | + /** |
121 | 153 | * Get a description of the shortcut key, e.g. "Ctrl-M" |
122 | 154 | * @return string |
123 | 155 | */ |
124 | 156 | 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; |
128 | 173 | } |
129 | 174 | |
130 | 175 | /** |