Index: trunk/extensions/Narayam/js/ext.narayam.core.js |
— | — | @@ -32,7 +32,7 @@ |
33 | 33 | var availableSchemes = mw.config.get( 'wgNarayamAvailableSchemes' ) || {}; |
34 | 34 | // All input methods. This will be used for selecting input methods from languages |
35 | 35 | // other than uselang- optionally |
36 | | - var allImes = mw.config.get( 'wgNarayamAllSchemes' ) || {}; |
| 36 | + var allImes = mw.config.get( 'wgNarayamAllSchemes' ) || {}; |
37 | 37 | // Currently selected scheme |
38 | 38 | var currentScheme = null; |
39 | 39 | // Shortcut key for turning Narayam on and off |
— | — | @@ -51,14 +51,14 @@ |
52 | 52 | function transliterate( str, keyBuffer, useExtended ) { |
53 | 53 | var rules = currentScheme.extended_keyboard && useExtended ? |
54 | 54 | currentScheme.rules_x : currentScheme.rules; |
55 | | - for ( var i = 0; i < rules.length; i++ ) { |
| 55 | + for ( var i = 0; i < rules.length; i++ ) { |
56 | 56 | var regex = new RegExp( rules[i][0] + '$' ); |
57 | | - if ( regex.test( str ) // Input string match |
| 57 | + if ( regex.test( str ) // Input string match |
58 | 58 | && |
59 | 59 | ( |
60 | 60 | rules[i][1].length == 0 // Keybuffer match not required |
61 | 61 | || |
62 | | - ( // Keybuffer match specified, so it should be met |
| 62 | + ( // Keybuffer match specified, so it should be met |
63 | 63 | rules[i][1].length > 0 |
64 | 64 | && rules[i][1].length <= keyBuffer.length |
65 | 65 | && new RegExp( rules[i][1] + '$' ).test( keyBuffer ) |
— | — | @@ -83,8 +83,7 @@ |
84 | 84 | function lastNChars( str, pos, n ) { |
85 | 85 | if ( n === 0 ) { |
86 | 86 | return ''; |
87 | | - } |
88 | | - if ( pos <= n ) { |
| 87 | + } else if ( pos <= n ) { |
89 | 88 | return str.substr( 0, pos ); |
90 | 89 | } else { |
91 | 90 | return str.substr( pos - n, n ); |
— | — | @@ -133,13 +132,13 @@ |
134 | 133 | key: 'm' |
135 | 134 | } |
136 | 135 | // Browser sniffing to determine the available shortcutKey |
137 | | - // Refer: mediawiki.util.js and en.wikipedia.org/wiki/Access_key |
| 136 | + // Refer: mediawiki.util.js and en.wikipedia.org/wiki/Access_key |
138 | 137 | var profile = $.client.profile(); |
139 | 138 | // Safari/Konqueror on any platform, but not Safari on Windows |
140 | 139 | // or any browser on Mac except chrome and opera |
141 | 140 | if ( !( profile.platform == 'win' && profile.name == 'safari' ) && |
142 | 141 | ( profile.name == 'safari'|| profile.platform == 'mac' || profile.name == 'konqueror' ) |
143 | | - && !(profile.name == 'opera' || profile.name == 'chrome' ) ) { |
| 142 | + && !( profile.name == 'opera' || profile.name == 'chrome' ) ) { |
144 | 143 | defaultShortcut.key = 'g'; |
145 | 144 | } |
146 | 145 | // For Opera in OSX, shortcut is control+command+m. |
— | — | @@ -177,8 +176,6 @@ |
178 | 177 | * current state of Narayam |
179 | 178 | */ |
180 | 179 | function changeVisual( $element ) { |
181 | | - // It is simple in working |
182 | | - // If Narayam is active add narayam class otherwise remove narayam class |
183 | 180 | if ( enabled ) { |
184 | 181 | $element.addClass( 'narayam-input' ); |
185 | 182 | } else { |
— | — | @@ -280,14 +277,13 @@ |
281 | 278 | replacement = replacement.substring( divergingPos ); |
282 | 279 | |
283 | 280 | $this.textSelection( 'encapsulateSelection', { |
284 | | - 'peri': replacement, |
285 | | - 'replace': true, |
286 | | - 'selectPeri': false, |
287 | | - 'selectionStart': startPos - input.length + 1, |
288 | | - 'selectionEnd': endPos |
| 281 | + peri: replacement, |
| 282 | + replace: true, |
| 283 | + selectPeri: false, |
| 284 | + selectionStart: startPos - input.length + 1, |
| 285 | + selectionEnd: endPos |
| 286 | + } ); |
289 | 287 | |
290 | | - } ); |
291 | | - |
292 | 288 | e.stopPropagation(); |
293 | 289 | return false; |
294 | 290 | } |
— | — | @@ -297,7 +293,7 @@ |
298 | 294 | * @param e Event object |
299 | 295 | */ |
300 | 296 | function onfocus( e ) { |
301 | | - if (!$( this ).data( 'narayamKeyBuffer' )) { |
| 297 | + if ( !$( this ).data( 'narayamKeyBuffer' ) ) { |
302 | 298 | // First-time focus on the input field |
303 | 299 | // So, initialise a key buffer for it |
304 | 300 | $( this ).data( 'narayamKeyBuffer', '' ); |
— | — | @@ -322,7 +318,7 @@ |
323 | 319 | * or an array of DOM elements, or a single DOM element, or a selector |
324 | 320 | */ |
325 | 321 | this.addInputs = function( inputs ) { |
326 | | - if (typeof( inputs ) == "string" ) { |
| 322 | + if ( typeof( inputs ) === "string" ) { |
327 | 323 | // If a string is passed, it is CSS selector |
328 | 324 | // We can use jQuery's .live() instead of .bind() |
329 | 325 | // So Narayam can work on elements added later to DOM too |
— | — | @@ -337,8 +333,8 @@ |
338 | 334 | $newInputs |
339 | 335 | .bind( 'keydown.narayam', onkeydown ) |
340 | 336 | .bind( 'keypress.narayam', onkeypress ) |
341 | | - .bind( 'focus', onfocus) |
342 | | - .bind( 'blur', onblur); |
| 337 | + .bind( 'focus', onfocus ) |
| 338 | + .bind( 'blur', onblur ); |
343 | 339 | } |
344 | 340 | }; |
345 | 341 | |
— | — | @@ -347,9 +343,9 @@ |
348 | 344 | */ |
349 | 345 | this.enable = function() { |
350 | 346 | if ( !enabled ) { |
351 | | - $.cookie( 'narayam-enabled', '1', { 'path': '/', 'expires': 30 } ); |
| 347 | + $.cookie( 'narayam-enabled', '1', { path: '/', expires: 30 } ); |
352 | 348 | $( '#narayam-toggle' ).prop( 'checked', true ); |
353 | | - $( 'li#pt-narayam') |
| 349 | + $( 'li#pt-narayam' ) |
354 | 350 | .removeClass( 'narayam-inactive' ) |
355 | 351 | .addClass( 'narayam-active' ); |
356 | 352 | enabled = true; |
— | — | @@ -361,9 +357,9 @@ |
362 | 358 | */ |
363 | 359 | this.disable = function() { |
364 | 360 | if ( enabled ) { |
365 | | - $.cookie( 'narayam-enabled', '0', { 'path': '/', 'expires': 30 } ); |
| 361 | + $.cookie( 'narayam-enabled', '0', { path: '/', expires: 30 } ); |
366 | 362 | $( '#narayam-toggle' ).prop( 'checked', false ); |
367 | | - $( 'li#pt-narayam') |
| 363 | + $( 'li#pt-narayam' ) |
368 | 364 | .removeClass( 'narayam-active' ) |
369 | 365 | .addClass( 'narayam-inactive' ); |
370 | 366 | enabled = false; |
— | — | @@ -424,7 +420,6 @@ |
425 | 421 | this.addScheme = function( name, data ) { |
426 | 422 | schemes[name] = data; |
427 | 423 | return true; |
428 | | - |
429 | 424 | }; |
430 | 425 | |
431 | 426 | /** |
— | — | @@ -436,21 +431,20 @@ |
437 | 432 | if ( typeof recent === "string" ) { |
438 | 433 | recent = recent.split( "," ); |
439 | 434 | }; |
440 | | - recent = $.grep(recent, function(value) { |
| 435 | + recent = $.grep( recent, function( value ) { |
441 | 436 | return value != name; |
442 | | - }); |
| 437 | + } ); |
443 | 438 | recent.unshift( name ); |
444 | 439 | recent = recent.slice( 0, recentItemsLength ); |
445 | 440 | recent = recent.join( "," ); |
446 | | - $.cookie( 'narayam-scheme', recent, { 'path': '/', 'expires': 30 } ); |
| 441 | + $.cookie( 'narayam-scheme', recent, { path: '/', expires: 30 } ); |
447 | 442 | if ( name in schemes ) { |
448 | 443 | currentScheme = schemes[name]; |
449 | | - } |
450 | | - else { |
| 444 | + } else { |
451 | 445 | // load the rules dynamically. |
452 | | - mw.loader.using( "ext.narayam.rules." + name, function() { |
| 446 | + mw.loader.using( "ext.narayam.rules." + name, function() { |
453 | 447 | currentScheme = schemes[name]; |
454 | | - }); |
| 448 | + } ); |
455 | 449 | } |
456 | 450 | return true; |
457 | 451 | }; |
— | — | @@ -461,20 +455,14 @@ |
462 | 456 | * from a cookie or wgNarayamEnableByDefault |
463 | 457 | */ |
464 | 458 | this.setup = function() { |
465 | | - // Build the menu |
466 | | - if ( !that.buildMenu() ) { |
467 | | - // /buildMenu() returned false |
468 | | - // No need to proceed |
469 | | - return; |
470 | | - } |
471 | | - |
| 459 | + that.buildMenu(); |
472 | 460 | // Restore state from cookies |
473 | 461 | var recentSchemes = $.cookie( 'narayam-scheme' ); |
474 | 462 | var lastScheme = null; |
475 | 463 | if ( typeof recent === "string" ) { |
476 | 464 | lastScheme = recent.split( "," )[0]; |
477 | 465 | } |
478 | | - if ( lastScheme) { |
| 466 | + if ( lastScheme ) { |
479 | 467 | that.setScheme( lastScheme ); |
480 | 468 | $( '#narayam-' + lastScheme ).prop( 'checked', true ); |
481 | 469 | } else { |
— | — | @@ -487,30 +475,26 @@ |
488 | 476 | var enabledCookie = $.cookie( 'narayam-enabled' ); |
489 | 477 | if ( enabledCookie == '1' || ( mw.config.get( 'wgNarayamEnabledByDefault' ) && enabledCookie !== '0' ) ) { |
490 | 478 | that.enable(); |
491 | | - } |
492 | | - else { |
| 479 | + } else { |
493 | 480 | $( 'li#pt-narayam' ).addClass( 'narayam-inactive' ); |
494 | 481 | } |
495 | 482 | // Renew the narayam-enabled cookie. narayam-scheme is renewed by setScheme() |
496 | 483 | if ( enabledCookie ) { |
497 | | - $.cookie( 'narayam-enabled', enabledCookie, { |
498 | | - 'path': '/', |
499 | | - 'expires': 30 |
500 | | - } ); |
| 484 | + $.cookie( 'narayam-enabled', enabledCookie, { path: '/', expires: 30 } ); |
501 | 485 | } |
502 | 486 | |
503 | 487 | }; |
504 | 488 | /** |
505 | 489 | * Construct the menu item, for the given scheme name. |
506 | 490 | */ |
507 | | - this.buildMenuItem =function(scheme) { |
| 491 | + this.buildMenuItem = function( scheme ) { |
508 | 492 | var $input = $( '<input type="radio" name="narayam-input-method" class="narayam-scheme" />' ); |
509 | 493 | $input.attr( 'id', 'narayam-' + scheme ).val( scheme ); |
510 | 494 | |
511 | 495 | var $narayamMenuItemLabel = $( '<label>' ) |
512 | | - .attr( 'for' ,'narayam-' + scheme ) |
513 | | - .append( $input ) |
514 | | - .append( mw.message( "narayam-"+ scheme ).escaped() ); |
| 496 | + .attr( 'for' ,'narayam-' + scheme ) |
| 497 | + .append( $input ) |
| 498 | + .append( mw.message( "narayam-"+ scheme ).escaped() ); |
515 | 499 | |
516 | 500 | var $narayamMenuItem = $( '<li>' ) |
517 | 501 | .append( $input ) |
— | — | @@ -539,8 +523,8 @@ |
540 | 524 | if ( $.inArray( scheme, seen ) > -1 ) { continue; } |
541 | 525 | seen.push( scheme ); |
542 | 526 | if ( count++ > recentItemsLength ) { break; } |
543 | | - $narayamMenuItem = that.buildMenuItem(scheme); |
544 | | - $narayamMenuItem.addClass('narayam-recent-menu-item'); |
| 527 | + $narayamMenuItem = that.buildMenuItem( scheme ); |
| 528 | + $narayamMenuItem.addClass( 'narayam-recent-menu-item' ); |
545 | 529 | $narayamMenuItems.append( $narayamMenuItem ); |
546 | 530 | } |
547 | 531 | // menu items for the language of wiki. |
— | — | @@ -551,21 +535,21 @@ |
552 | 536 | if ( !langschemes ) continue; |
553 | 537 | for ( var scheme in langschemes ) { |
554 | 538 | haveSchemes = true; |
555 | | - if ( $.inArray( scheme, seen ) > -1 ) { continue; } |
| 539 | + if ( $.inArray( scheme, seen ) !== -1 ) { continue; } |
556 | 540 | seen.push( scheme ); |
557 | | - $narayamMenuItem = that.buildMenuItem(scheme); |
| 541 | + $narayamMenuItem = that.buildMenuItem( scheme ); |
558 | 542 | $narayamMenuItems.append( $narayamMenuItem ); |
559 | 543 | } |
560 | 544 | } |
| 545 | + |
561 | 546 | if ( !haveSchemes ) { |
562 | 547 | // No schemes available, don't show the tool |
563 | | - // So return false |
564 | 548 | return false; |
565 | 549 | } |
566 | 550 | |
567 | 551 | // Event listener for scheme selection. |
568 | 552 | $( '.narayam-scheme', $( '#narayam-menu-items > ul')[0] ).live( 'click', function() { |
569 | | - that.setScheme( $(this).val() ); |
| 553 | + that.setScheme( $( this ).val() ); |
570 | 554 | } ); |
571 | 555 | |
572 | 556 | // Build enable/disable checkbox and label |
— | — | @@ -579,20 +563,21 @@ |
580 | 564 | .text( mw.msg( 'narayam-toggle-ime', shortcutText() ) ) |
581 | 565 | .prepend( $checkbox ) |
582 | 566 | .prop( 'title', mw.msg( 'narayam-checkbox-tooltip' ) ); |
| 567 | + |
| 568 | + var $moreLink = $( '<a>' ) |
| 569 | + .text( mw.msg( 'narayam-more-imes' ) ) |
| 570 | + .click( function() { |
| 571 | + $('.narayam-scheme-dynamic-item').toggle( 'fast' ); |
| 572 | + if ( $('li.narayam-more-imes-link').hasClass( 'open' ) ) { |
| 573 | + $('li.narayam-more-imes-link').removeClass( 'open' ); |
| 574 | + } else { |
| 575 | + $('li.narayam-more-imes-link').addClass( 'open' ); |
| 576 | + } |
| 577 | + } ); |
583 | 578 | |
584 | | - $narayamMenuItems.append( $( '<li>' ).addClass( 'narayam-more-imes-link' ) |
585 | | - .append( |
586 | | - $( '<a>' ) |
587 | | - .text( mw.msg( 'narayam-more-imes' ) ) |
588 | | - .click( function() { |
589 | | - $('.narayam-scheme-dynamic-item').toggle('fast'); |
590 | | - if( $('li.narayam-more-imes-link').hasClass( 'open' )){ |
591 | | - $('li.narayam-more-imes-link').removeClass('open'); |
592 | | - }else{ |
593 | | - $('li.narayam-more-imes-link').addClass('open'); |
594 | | - } |
595 | | - }) |
596 | | - ) |
| 579 | + $narayamMenuItems.append( $( '<li>' ) |
| 580 | + .addClass( 'narayam-more-imes-link' ) |
| 581 | + .append( $moreLink ) |
597 | 582 | ); |
598 | 583 | |
599 | 584 | for ( var lang in allImes ) { |
— | — | @@ -601,7 +586,7 @@ |
602 | 587 | // Donot repeat the input methods in more input methods section. |
603 | 588 | // If already shown on recent items. |
604 | 589 | if ( $.inArray( langscheme, seen ) > -1 ) { continue; } |
605 | | - $narayamMenuItem = that.buildMenuItem(langscheme); |
| 590 | + $narayamMenuItem = that.buildMenuItem( langscheme ); |
606 | 591 | $narayamMenuItem.addClass( 'narayam-scheme-dynamic-item' ); |
607 | 592 | $narayamMenuItems.append( $narayamMenuItem ); |
608 | 593 | |
— | — | @@ -610,10 +595,10 @@ |
611 | 596 | |
612 | 597 | // Event listener for scheme selection - dynamic loading of rules. |
613 | 598 | $( '.narayam-scheme', $('.narayam-scheme-dynamic-item') ).live( 'click', function() { |
614 | | - that.setScheme( $(this).val() ); |
| 599 | + that.setScheme( $( this ).val() ); |
615 | 600 | // rebuild the menu items with recent items. |
616 | 601 | $( '#narayam-menu-items' ).html( $.narayam.buildMenuItems() ); |
617 | | - $( '#narayam-' + $(this).val() ).prop( 'checked', true ); |
| 602 | + $( '#narayam-' + $( this ).val() ).prop( 'checked', true ); |
618 | 603 | if ( enabled ) { |
619 | 604 | $( '#narayam-toggle' ).prop( 'checked', true ); |
620 | 605 | } |
— | — | @@ -624,7 +609,7 @@ |
625 | 610 | var $link = $( '<a>' ) |
626 | 611 | .text( mw.msg( 'narayam-help' ) ) |
627 | 612 | .prop( 'href', mw.util.wikiGetlink( helppage ) ); |
628 | | - var $li = $( '<li>' ).addClass( 'narayam-help-link' ); |
| 613 | + var $li = $( '<li>' ).addClass( 'narayam-help-link' ); |
629 | 614 | $narayamMenuItems.append( $li.append( $link ) ); |
630 | 615 | } |
631 | 616 | |