Merge "Refactor ime lazy loading"

This commit is contained in:
jenkins-bot
2013-11-06 04:46:57 +00:00
committed by Gerrit Code Review
5 changed files with 122 additions and 84 deletions

View File

@@ -45,6 +45,7 @@ $wgResourceModules['ext.uls.ime'] = array(
'dependencies' => array( 'dependencies' => array(
'ext.uls.init', 'ext.uls.init',
'ext.uls.preferences', 'ext.uls.preferences',
'jquery.ime',
), ),
'messages' => array( 'messages' => array(
'uls-ime-helppage', 'uls-ime-helppage',
@@ -110,7 +111,6 @@ $wgResourceModules['ext.uls.interface'] = array(
// We can not delay webfonts loading since it is required // We can not delay webfonts loading since it is required
// immediately after page load // immediately after page load
'ext.uls.webfonts', 'ext.uls.webfonts',
'ext.uls.ime',
), ),
'messages' => array( 'messages' => array(
'uls-plang-title-languages', 'uls-plang-title-languages',

View File

@@ -256,8 +256,8 @@ class UniversalLanguageSelectorHooks {
*/ */
public static function addConfig( &$vars ) { public static function addConfig( &$vars ) {
global $wgULSGeoService, $wgULSIMEEnabled, $wgULSPosition, $wgULSNoWebfontsSelectors, global $wgULSGeoService, $wgULSIMEEnabled, $wgULSPosition, $wgULSNoWebfontsSelectors,
$wgULSAnonCanChangeLanguage, $wgULSEventLogging, $wgULSNoImeSelectors, $wgULSAnonCanChangeLanguage, $wgULSEventLogging, $wgULSImeSelectors,
$wgULSFontRepositoryBasePath, $wgExtensionAssetsPath; $wgULSNoImeSelectors, $wgULSFontRepositoryBasePath, $wgExtensionAssetsPath;
// Place constant stuff here (not depending on request context) // Place constant stuff here (not depending on request context)
if ( is_string( $wgULSGeoService ) ) { if ( is_string( $wgULSGeoService ) ) {
@@ -267,6 +267,7 @@ class UniversalLanguageSelectorHooks {
$vars['wgULSPosition'] = $wgULSPosition; $vars['wgULSPosition'] = $wgULSPosition;
$vars['wgULSAnonCanChangeLanguage'] = $wgULSAnonCanChangeLanguage; $vars['wgULSAnonCanChangeLanguage'] = $wgULSAnonCanChangeLanguage;
$vars['wgULSEventLogging'] = $wgULSEventLogging; $vars['wgULSEventLogging'] = $wgULSEventLogging;
$vars['wgULSImeSelectors'] = $wgULSImeSelectors;
$vars['wgULSNoImeSelectors'] = $wgULSNoImeSelectors; $vars['wgULSNoImeSelectors'] = $wgULSNoImeSelectors;
$vars['wgULSNoWebfontsSelectors'] = $wgULSNoWebfontsSelectors; $vars['wgULSNoWebfontsSelectors'] = $wgULSNoWebfontsSelectors;

View File

@@ -123,6 +123,19 @@ $wgULSPosition = 'personal';
*/ */
$wgULSEventLogging = false; $wgULSEventLogging = false;
/**
* Array of jQuery selectors of elements on which IME should be enabled.
*
* @since 2013.11
*/
$wgULSImeSelectors = array(
'input:not([type])',
'input[type=text]',
'input[type=search]',
'textarea',
'[contenteditable]',
);
/** /**
* Array of jQuery selectors of elements on which IME must not be enabled. * Array of jQuery selectors of elements on which IME must not be enabled.
* *

View File

@@ -195,41 +195,62 @@
}; };
}; };
/**
* Binds the event listeners.
*/
mw.ime.setup = function () { mw.ime.setup = function () {
var imeSelectors = mw.config.get( 'wgULSImeSelectors' ).join( ', ' );
mw.ime.init(); mw.ime.init();
$( 'body' ).on( 'focus.ime', inputSelector, function () { $( 'body' ).on( 'focus.ime', imeSelectors, function () {
var imeselector, $input, noImeSelector; mw.ime.handleFocus( $( this ) );
noImeSelector = mw.config.get( 'wgULSNoImeSelectors' ).join( ', ' );
$input = $( this );
if ( !$.ime ) {
mw.loader.using( 'jquery.ime', function () {
$input.trigger( 'focus' );
} ); } );
};
/**
* Loads necessary dependencies, checks input for validity and
* adds the ime menu for elements that should have it.
* @param {jquery.Element} $input
* @since 2013.11
*/
mw.ime.handleFocus = function ( $input ) {
var noImeSelectors;
if ( $input.is( '.noime' ) || $input.data( 'ime' ) ) {
// input does not need IME or already applied
return;
}
noImeSelectors = mw.config.get( 'wgULSNoImeSelectors' ).join( ', ' );
if ( noImeSelectors.length && $input.is( noImeSelectors ) ) {
$input.addClass( 'noime' );
return; return;
} }
mw.ime.init(); if ( !$.ime.preferences.isEnabled() ) {
if ( $input.is( '.noime' ) || !$.ime.preferences.isEnabled() ) {
return; return;
} }
if ( $input.is( '[contenteditable]' ) && !window.rangy ) { if ( $input.is( '[contenteditable]' ) && !window.rangy ) {
// for supporting content editable divs we need rangy library // For supporting content editable divs we need rangy library
mw.loader.using( 'rangy.core', function () { mw.loader.using( 'rangy.core', function () {
$input.trigger( 'focus' ); mw.ime.addIme( $input );
} ); } );
return; return;
} }
if ( noImeSelector.length && $input.is( noImeSelector ) ) { mw.ime.addIme( $input );
$input.addClass( 'noime' ); };
return;
} /**
* Just adds ime menu to any input element.
* @param {jquery.Element} $input
* @since 2013.11
*/
mw.ime.addIme = function ( $input ) {
var imeselector;
$input.ime( { $input.ime( {
languages: mw.ime.getIMELanguageList(), languages: mw.ime.getIMELanguageList(),
@@ -274,15 +295,8 @@
mw.hook( 'mw.uls.ime.change' ).fire( inputMethod ); mw.hook( 'mw.uls.ime.change' ).fire( inputMethod );
} ); } );
} }
} );
}; };
$( document ).ready( function () {
mw.uls.init( function () {
mw.ime.setup();
} );
} );
function imeNotification() { function imeNotification() {
var notificationMsg = ( mw.config.get( 'wgULSPosition' ) === 'personal' ) ? var notificationMsg = ( mw.config.get( 'wgULSPosition' ) === 'personal' ) ?
'ext-uls-input-disable-notification-info-personal' : 'ext-uls-input-disable-notification-info-personal' :

View File

@@ -297,6 +297,7 @@
rtlPage = $( 'body' ).hasClass( 'rtl' ), rtlPage = $( 'body' ).hasClass( 'rtl' ),
anonMode = ( mw.user.isAnon() && anonMode = ( mw.user.isAnon() &&
!mw.config.get( 'wgULSAnonCanChangeLanguage' ) ), !mw.config.get( 'wgULSAnonCanChangeLanguage' ) ),
imeSelector = mw.config.get( 'wgULSImeSelectors' ).join( ', ' ),
ulsPosition = mw.config.get( 'wgULSPosition' ); ulsPosition = mw.config.get( 'wgULSPosition' );
if ( ulsPosition === 'interlanguage' ) { if ( ulsPosition === 'interlanguage' ) {
@@ -445,6 +446,15 @@
} ); } );
showULSTooltip(); showULSTooltip();
$( 'body' ).on( 'focus.imeinit', imeSelector, function () {
var $input = $( this );
$( 'body' ).off( '.imeinit' );
mw.loader.using( 'ext.uls.ime', function () {
mw.ime.setup();
mw.ime.handleFocus( $input );
} );
} );
} ); } );
} ); } );
}( jQuery, mediaWiki ) ); }( jQuery, mediaWiki ) );