r83156 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r83155‎ | r83156 | r83157 >
Date:18:36, 3 March 2011
Author:catrope
Status:ok
Tags:
Comment:
Narayam: Add more function documentation
Modified paths:
  • /trunk/extensions/Narayam/ext.narayam.core.js (modified) (history)

Diff [purge]

Index: trunk/extensions/Narayam/ext.narayam.core.js
@@ -29,7 +29,7 @@
3030 var availableSchemes = mw.config.get( 'wgNarayamAvailableSchemes' ) || {};
3131 // Currently selected scheme
3232 var currentScheme = null;
33 - // Shortcut key
 33+ // Shortcut key for turning Narayam on and off
3434 var shortcutKey = mw.config.get( 'wgNarayamShortcutKey' ) || {
3535 altKey: false,
3636 ctrlKey: false,
@@ -100,6 +100,11 @@
101101 return -1;
102102 }
103103
 104+ /**
 105+ * Check whether a keypress event corresponds to the shortcut key
 106+ * @param e Event object
 107+ * @return bool
 108+ */
104109 function isShortcutKey( e ) {
105110 return e.altKey == shortcutKey.altKey &&
106111 e.ctrlKey == shortcutKey.ctrlKey &&
@@ -107,6 +112,10 @@
108113 String.fromCharCode( e.which ).toLowerCase() == shortcutKey.key.toLowerCase();
109114 }
110115
 116+ /**
 117+ * Get a description of the shortcut key, e.g. "Ctrl-M"
 118+ * @return string
 119+ */
111120 function shortcutText() {
112121 var text = '';
113122 // TODO: Localize these things (in core, too)
@@ -123,6 +132,10 @@
124133 return text;
125134 }
126135
 136+ /**
 137+ * Keydown event handler. Handles shortcut key presses
 138+ * @param e Event object
 139+ */
127140 function onkeydown( e ) {
128141 // If the current scheme uses the alt key, ignore keydown for Alt+? combinations
129142 if ( enabled && currentScheme.extended_keyboard && e.altKey && !e.ctrlKey ) {
@@ -136,6 +149,10 @@
137150 return true;
138151 }
139152
 153+ /**
 154+ * Keypress event handler. This is where the real work happens
 155+ * @param e Event object
 156+ */
140157 function onkeypress( e ) {
141158 if ( !enabled ) {
142159 return true;
@@ -201,6 +218,10 @@
202219 return false;
203220 }
204221
 222+ /**
 223+ * Change handler for the scheme dropdown. Updates the current scheme
 224+ * based on the new selection in the dropdown.
 225+ */
205226 function updateSchemeFromSelect() {
206227 var scheme = $( this ).val();
207228 that.setScheme( scheme );
@@ -226,6 +247,9 @@
227248 }
228249 };
229250
 251+ /**
 252+ * Enable Narayam
 253+ */
230254 this.enable = function() {
231255 if ( !enabled && currentScheme !== null ) {
232256 $inputs.addClass( 'narayam-input' );
@@ -235,6 +259,9 @@
236260 }
237261 };
238262
 263+ /**
 264+ * Disable Narayam
 265+ */
239266 this.disable = function() {
240267 if ( enabled ) {
241268 $inputs.removeClass( 'narayam-input' );
@@ -244,6 +271,9 @@
245272 }
246273 };
247274
 275+ /**
 276+ * Toggle the enabled/disabled state
 277+ */
248278 this.toggle = function() {
249279 if ( enabled ) {
250280 that.disable();
@@ -268,6 +298,10 @@
269299 }
270300 };
271301
 302+ /**
 303+ * Change the current transliteration scheme
 304+ * @param name String
 305+ */
272306 this.setScheme = function( name ) {
273307 if ( name in schemes ) {
274308 currentScheme = schemes[name];
@@ -275,6 +309,11 @@
276310 }
277311 };
278312
 313+ /**
 314+ * Set up Narayam. This adds the scheme dropdown, binds the handlers
 315+ * and initializes the enabled/disabled state and selected scheme
 316+ * from a cookie or wgNarayamEnableByDefault
 317+ */
279318 this.setup = function() {
280319 // Build scheme dropdown
281320 $select = $( '<select />' );

Status & tagging log