onSelect callback option for ULS
* Correct the dependencies for ext.uls.core, it need not depend on mediawiki.Uri. * Move the setlang function out of ULS core js. * Add a callback function to the example. Change-Id: Ie3598236b2a884580092194c57558ec109d20803
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -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 );
|
||||
|
||||
Reference in New Issue
Block a user