Load jquery.ime only when user focus on editable fields

To reduce javascript size for page load.

Change-Id: I71928ac5149cbcf2cc75073fdf628403e6abe456
This commit is contained in:
Santhosh Thottingal
2013-07-25 17:33:54 +05:30
committed by Amir E. Aharoni
parent d92c75518b
commit 63d547915f
3 changed files with 37 additions and 26 deletions

View File

@@ -33,10 +33,12 @@ $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
@@ -75,11 +77,9 @@ $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

View File

@@ -19,7 +19,7 @@
( function ( $, mw, document, undefined ) {
'use strict';
var mwImeRulesPath, inputSelector, inputPreferences;
var mwImeRulesPath, inputSelector, inputPreferences, ulsIMEPreferences, customHelpLink;
mwImeRulesPath = mw.config.get( 'wgExtensionAssetsPath' ) +
'/UniversalLanguageSelector/lib/jquery.ime/';
@@ -57,8 +57,7 @@
return unique.slice( 0, 6 );
};
// Extend the ime preference system
$.extend( $.ime.preferences, {
ulsIMEPreferences = {
save: function ( callback ) {
if ( !this.registry.isDirty ) {
@@ -102,15 +101,10 @@
getDefaultLanguage: function () {
return mw.config.get( 'wgContentLanguage' );
}
} );
};
// 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 () {
// Add a 'more setttings' link that takes to input settings of ULS
customHelpLink = function () {
var $disableInputToolsLink, $moreSettingsLink,
imeselector = this;
@@ -173,19 +167,40 @@
$( 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;
// 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
$input = $( this );
if ( !$.ime ) {
mw.loader.using( 'jquery.ime', function () {
mw.ime.init();
$input.trigger( 'focus.ime' );
} );
return;
}
if ( !$.ime.preferences.isEnabled() ) {
return;
}
$input = $( this );
noImeSelector = mw.config.get( 'wgULSNoImeSelectors' ).join( ', ' );
if ( noImeSelector.length && $input.is( noImeSelector ) ) {
@@ -238,12 +253,7 @@
$( document ).ready( function () {
mw.uls.init( function () {
// Load the ime preferences
$.ime.preferences.load();
if ( $.ime.preferences.isEnabled() ) {
mw.ime.setup();
}
mw.ime.setup();
} );
} );

View File

@@ -94,7 +94,8 @@
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 {