diff --git a/Resources.php b/Resources.php index 6ae9c6b5..6ce8de8f 100644 --- a/Resources.php +++ b/Resources.php @@ -33,12 +33,10 @@ $wgResourceModules['ext.uls.geoclient'] = array( $wgResourceModules['ext.uls.ime'] = array( 'scripts' => 'resources/js/ext.uls.ime.js', 'dependencies' => array( + 'jquery.ime', 'ext.uls.init', 'ext.uls.preferences', ), - 'messages' => array( - 'uls-ime-helppage', - ), ) + $resourcePaths; // Styles for users who disabled JavaScript @@ -77,9 +75,11 @@ $wgResourceModules['ext.uls.inputsettings'] = array( 'dependencies' => array( 'ext.uls.languagesettings', 'ext.uls.ime', - 'jquery.ime', 'jquery.i18n', ), + 'messages' => array( + 'uls-ime-helppage', + ), ) + $resourcePaths; // Interface language selection module diff --git a/resources/js/ext.uls.ime.js b/resources/js/ext.uls.ime.js index 51438344..cc1df4e7 100644 --- a/resources/js/ext.uls.ime.js +++ b/resources/js/ext.uls.ime.js @@ -19,7 +19,7 @@ ( function ( $, mw, document, undefined ) { 'use strict'; - var mwImeRulesPath, inputSelector, inputPreferences, ulsIMEPreferences, customHelpLink; + var mwImeRulesPath, inputSelector, inputPreferences; mwImeRulesPath = mw.config.get( 'wgExtensionAssetsPath' ) + '/UniversalLanguageSelector/lib/jquery.ime/'; @@ -57,7 +57,8 @@ return unique.slice( 0, 6 ); }; - ulsIMEPreferences = { + // Extend the ime preference system + $.extend( $.ime.preferences, { save: function ( callback ) { if ( !this.registry.isDirty ) { @@ -101,10 +102,15 @@ getDefaultLanguage: function () { return mw.config.get( 'wgContentLanguage' ); } - }; + } ); - // Add a 'more setttings' link that takes to input settings of ULS - customHelpLink = function () { + // MediaWiki specific overrides for jquery.ime + $.extend( $.ime.defaults, { + imePath: mwImeRulesPath + } ); + + // Add a 'more settings' link that takes to input settings of ULS + $.fn.imeselector.Constructor.prototype.helpLink = function () { var $disableInputToolsLink, $moreSettingsLink, imeselector = this; @@ -167,40 +173,19 @@ $( inputSelector ).trigger( 'destroy.ime' ); }; - mw.ime.init = function () { - // Extend the ime preference system - $.extend( $.ime.preferences, ulsIMEPreferences ); - // MediaWiki specific overrides for jquery.ime - $.extend( $.ime.defaults, { - imePath: mwImeRulesPath - } ); - // Load the ime preferences - $.ime.preferences.load(); - $.fn.imeselector.Constructor.prototype.helpLink = customHelpLink; - }; - mw.ime.setup = function () { - if ( $.ime ) { - mw.ime.init(); - } $( 'body' ).on( 'focus.ime', inputSelector, function () { var imeselector, $input, noImeSelector; - $input = $( this ); - - if ( !$.ime ) { - mw.loader.using( 'jquery.ime', function () { - mw.ime.init(); - $input.trigger( 'focus.ime' ); - } ); - return; - } - + // It's possible to disable IME through the settings + // panels before it was initialized, so we need to check + // that it's supposed to be initialized if ( !$.ime.preferences.isEnabled() ) { return; } + $input = $( this ); noImeSelector = mw.config.get( 'wgULSNoImeSelectors' ).join( ', ' ); if ( noImeSelector.length && $input.is( noImeSelector ) ) { @@ -253,7 +238,12 @@ $( document ).ready( function () { mw.uls.init( function () { - mw.ime.setup(); + // Load the ime preferences + $.ime.preferences.load(); + + if ( $.ime.preferences.isEnabled() ) { + mw.ime.setup(); + } } ); } ); diff --git a/resources/js/ext.uls.inputsettings.js b/resources/js/ext.uls.inputsettings.js index df263cfa..ae0cc72e 100644 --- a/resources/js/ext.uls.inputsettings.js +++ b/resources/js/ext.uls.inputsettings.js @@ -94,8 +94,7 @@ this.$parent.$settingsPanel.append( this.$template ); $enabledOnly = this.$template.find( '.enabled-only' ); - // ime system is lazy loaded, make sure it is initialized - mw.ime.init(); + if ( $.ime.preferences.isEnabled() ) { $enabledOnly.removeClass( 'hide' ); } else {