diff --git a/UniversalLanguageSelector.php b/UniversalLanguageSelector.php index 637cfb2e..6d0a0bd2 100644 --- a/UniversalLanguageSelector.php +++ b/UniversalLanguageSelector.php @@ -49,7 +49,10 @@ $wgResourceModules['ext.uls.init'] = array( 'scripts' => 'resources/ext.uls.init.js', 'localBasePath' => $dir, 'remoteExtPath' => 'UniversalLanguageSelector', - 'dependencies' => 'ext.uls.core', + 'dependencies' => array( + 'mediawiki.Uri', + 'ext.uls.core', + ), 'position' => 'top', ); @@ -79,7 +82,6 @@ $wgResourceModules['ext.uls.core'] = array( 'localBasePath' => $dir, 'remoteExtPath' => 'UniversalLanguageSelector', 'dependencies' => array( - 'mediawiki.Uri', 'ext.uls.data', 'ext.uls.lcd', ), diff --git a/examples/index.html b/examples/index.html index d5a2ada8..544c3723 100644 --- a/examples/index.html +++ b/examples/index.html @@ -22,17 +22,26 @@ - +
diff --git a/resources/ext.uls.core.js b/resources/ext.uls.core.js index ee51c6b4..fefd50a7 100644 --- a/resources/ext.uls.core.js +++ b/resources/ext.uls.core.js @@ -66,23 +66,18 @@ // Rendering stuff here }, - setLang: function( langCode ) { - // TODO: dependency on MediaWiki - var uri = new mw.Uri( window.location.href ); - uri.extend( { setlang: langCode } ); - window.location.href = uri.toString(); - }, - listen: function() { - var that = this; + var that = this, $lcd; // Register all event listeners to the ULS here. that.$element.on( 'click', $.proxy( that.click, that ) ); $( ".icon-close" ).on( 'click', $.proxy( that.click, that ) ); - var $lcd = $( "div.uls-language-list" ).lcd( { + $lcd = $( "div.uls-language-list" ).lcd( { languages: that.languages, clickhandler: function( langCode ) { - that.setLang( langCode ); + if ( that.options.onSelect ) { + that.options.onSelect.call( this, langCode ); + } } } ).data( "lcd" ); $( "#languagefilter" ).languagefilter( { @@ -160,7 +155,8 @@ }; $.fn.uls.defaults = { - menu: '.uls-menu' + menu: '.uls-menu', + onSelect: null // Callback function to be called when a language is selected }; $.fn.uls.Constructor = ULS; diff --git a/resources/ext.uls.init.js b/resources/ext.uls.init.js index 94fa3269..f5589023 100644 --- a/resources/ext.uls.init.js +++ b/resources/ext.uls.init.js @@ -19,6 +19,14 @@ ( function( $ ) { $( document ).ready( function() { - $( '.uls-trigger' ).uls(); + $( '.uls-trigger' ).uls( { + onSelect : function( language ) { + var uri = new mw.Uri( window.location.href ); + uri.extend( { + setlang : language + } ); + window.location.href = uri.toString(); + } + } ); } ); } )( jQuery );