Whitespace cleanup, remove deprecated methods

* Fixed many white space issues- mainly whitespace missing before
  function start paranthesis eg: function()
* Removed the deprecated live methods and replaced with on
* Added file documentation for ext.uls.geoclient

Change-Id: Ib2c8cfed1a6ff3859495e707680d5c19882a33e8
This commit is contained in:
Santhosh Thottingal
2012-09-07 16:43:53 +05:30
parent d29364989f
commit 5b3f7cc269
6 changed files with 85 additions and 63 deletions

View File

@@ -17,7 +17,7 @@
* @licence MIT License * @licence MIT License
*/ */
( function( $, mw, window, undefined ) { ( function ( $, mw, window, undefined ) {
"use strict"; "use strict";
var template = '<div class="row"><div class="twelve columns"><h3>Display settings</h3></div></div>' var template = '<div class="row"><div class="twelve columns"><h3>Display settings</h3></div></div>'
@@ -112,7 +112,7 @@
languages.push( previousLanguages[lang] ); languages.push( previousLanguages[lang] );
} }
function buttonHandler( button ) { function buttonHandler ( button ) {
return function () { return function () {
that.uiLanguage = button.data( "language" ) || that.uiLanguage; that.uiLanguage = button.data( "language" ) || that.uiLanguage;
$( "div.uls-ui-languages button.button" ).removeClass( "down" ); $( "div.uls-ui-languages button.button" ).removeClass( "down" );
@@ -131,7 +131,7 @@
} }
$button.data( 'language', language ); $button.data( 'language', language );
$languages.append( $button ); $languages.append( $button );
$button.on ( 'click', buttonHandler( $button ) ); $button.on( 'click', buttonHandler( $button ) );
} }
this.prepareMoreLanguages(); this.prepareMoreLanguages();
}, },
@@ -151,13 +151,12 @@
$moreLanguagesButton.uls( { $moreLanguagesButton.uls( {
left: that.$parent.left, left: that.$parent.left,
top: that.$parent.top, top: that.$parent.top,
onReady: function( uls ) { onReady: function ( uls ) {
var $back = $( '<a>' ) var $back = $( '<a>' ).prop( 'href', '#' )
.prop( 'href', '#' )
.prop( 'title', 'Back to display settings' ) .prop( 'title', 'Back to display settings' )
.text( '← Back to display settings' ); // FIXME i18n .text( '← Back to display settings' ); // FIXME i18n
$back.click( function() { $back.click( function () {
uls.hide(); uls.hide();
that.$parent.show(); that.$parent.show();
} ); } );
@@ -165,13 +164,13 @@
uls.$menu.find( 'div.uls-title' ).append( $back ); uls.$menu.find( 'div.uls-title' ).append( $back );
uls.$menu.find( 'div.uls-title h1' ).text( 'Select display language' ); uls.$menu.find( 'div.uls-title h1' ).text( 'Select display language' );
}, },
onSelect: function( langCode ) { onSelect: function ( langCode ) {
that.uiLanguage = langCode; that.uiLanguage = langCode;
that.$parent.show(); that.$parent.show();
that.prepareUIFonts(); that.prepareUIFonts();
that.prepareLanguages(); that.prepareLanguages();
}, },
quickList: function() { quickList: function () {
return mw.uls.getFrequentLanguageList(); return mw.uls.getFrequentLanguageList();
} }
} ); } );
@@ -225,10 +224,9 @@
$fontSelector.find( 'option' ).remove(); $fontSelector.find( 'option' ).remove();
var savedFont = this.webfontPreferences.get( this.uiLanguage ); var savedFont = this.webfontPreferences.get( this.uiLanguage );
if( fonts && fonts.length ) { if ( fonts && fonts.length ) {
$.each( fonts, function ( key, font ) { $.each( fonts, function ( key, font ) {
var $fontOption = $( "<option>" ) var $fontOption = $( "<option>" ).attr( "value", font ).text( font );
.attr( "value", font ).text( font );
$fontSelector.append( $fontOption ); $fontSelector.append( $fontOption );
$fontOption.attr( 'selected', savedFont === font ); $fontOption.attr( 'selected', savedFont === font );
} ); } );
@@ -241,7 +239,7 @@
$systemFont.attr( 'selected', savedFont === 'system' || !savedFont ); $systemFont.attr( 'selected', savedFont === 'system' || !savedFont );
var $fontLabel = this.$template.find( 'label#ui-font-selector-label' ); var $fontLabel = this.$template.find( 'label#ui-font-selector-label' );
$fontLabel.html( "<strong>Select font for " + $.uls.data.autonym( this.uiLanguage ) $fontLabel.html( "<strong>Select font for " + $.uls.data.autonym( this.uiLanguage )
+ "</strong><div>Used for menus</div>"); + "</strong><div>Used for menus</div>" );
}, },
/** /**
@@ -254,10 +252,9 @@
$fontSelector.find( 'option' ).remove(); $fontSelector.find( 'option' ).remove();
var savedFont = this.webfontPreferences.get( this.contentLanguage ); var savedFont = this.webfontPreferences.get( this.contentLanguage );
if( fonts && fonts.length ) { if ( fonts && fonts.length ) {
$.each( fonts, function ( key, font ) { $.each( fonts, function ( key, font ) {
var $fontOption = $( "<option>" ) var $fontOption = $( "<option>" ).attr( "value", font ).text( font );
.attr( "value", font ).text( font );
$fontSelector.append( $fontOption ); $fontSelector.append( $fontOption );
$fontOption.attr( 'selected', savedFont === font ); $fontOption.attr( 'selected', savedFont === font );
} ); } );
@@ -268,7 +265,7 @@
var $systemFont = $( "<option>" ).val( 'system' ).text( 'System font' ); var $systemFont = $( "<option>" ).val( 'system' ).text( 'System font' );
$fontSelector.append( $systemFont ); $fontSelector.append( $systemFont );
$systemFont.attr( 'selected', savedFont === 'system' || !savedFont ); $systemFont.attr( 'selected', savedFont === 'system' || !savedFont );
var $fontLabel =this.$template.find( 'label#content-font-selector-label' ); var $fontLabel = this.$template.find( 'label#content-font-selector-label' );
$fontLabel.html( "<strong>Select font for " + $.uls.data.autonym( this.contentLanguage ) $fontLabel.html( "<strong>Select font for " + $.uls.data.autonym( this.contentLanguage )
+ "</strong><div>Used for content</div>" ); + "</strong><div>Used for content</div>" );
}, },
@@ -277,9 +274,10 @@
* Register general event listeners * Register general event listeners
*/ */
listen: function () { listen: function () {
var that = this, var that = this;
$contentFontSelector = this.$template.find( "select#content-font-selector" ), var $contentFontSelector = this.$template
$uiFontSelector = this.$template.find( "select#ui-font-selector" ); .find( "select#content-font-selector" ), $uiFontSelector = this.$template
.find( "select#ui-font-selector" );
// TODO all these repeated selectors can be placed in object constructor. // TODO all these repeated selectors can be placed in object constructor.
this.$template.find( 'button#uls-displaysettings-apply' ).on( 'click', function () { this.$template.find( 'button#uls-displaysettings-apply' ).on( 'click', function () {
@@ -361,4 +359,6 @@
$.fn.languagesettings.modules = $.extend( $.fn.languagesettings.modules, { $.fn.languagesettings.modules = $.extend( $.fn.languagesettings.modules, {
display: DisplaySettings display: DisplaySettings
} ); } );
}( jQuery, mediaWiki, window ) ); }( jQuery, mediaWiki, window ) );

View File

@@ -1,3 +1,22 @@
/**
* ULS GeoIP client
*
* Copyright (C) 2012 Alolita Sharma, Amir Aharoni, Arun Ganesh, Brandon Harris,
* Niklas Laxström, Pau Giner, Santhosh Thottingal, Siebrand Mazeland and other
* contributors. See CREDITS for a list.
*
* UniversalLanguageSelector is dual licensed GPLv2 or later and MIT. You don't
* have to do anything special to choose one license or the other and you don't
* have to notify anyone which license you are using. You are free to use
* UniversalLanguageSelector in commercial projects as long as the copyright
* header is left intact. See files GPL-LICENSE and MIT-LICENSE for details.
*
* @file
* @ingroup Extensions
* @licence GNU General Public Licence 2.0 or later
* @licence MIT License
*/
( function( mw, $ ) { ( function( mw, $ ) {
"use strict"; "use strict";

View File

@@ -17,7 +17,7 @@
* @licence MIT License * @licence MIT License
*/ */
( function( $, mw, window, document, undefined ) { ( function ( $, mw, window, document, undefined ) {
"use strict"; "use strict";
// MediaWiki override for ULS defaults. // MediaWiki override for ULS defaults.
@@ -34,7 +34,7 @@
* Change the language of wiki using setlang URL parameter * Change the language of wiki using setlang URL parameter
* @param {String} language * @param {String} language
*/ */
mw.uls.changeLanguage = function( language ) { mw.uls.changeLanguage = function ( language ) {
var uri = new mw.Uri( window.location.href ); var uri = new mw.Uri( window.location.href );
uri.extend( { uri.extend( {
setlang: language setlang: language
@@ -42,11 +42,11 @@
window.location.href = uri.toString(); window.location.href = uri.toString();
}; };
mw.uls.setPreviousLanguages = function( previousLanguages ) { mw.uls.setPreviousLanguages = function ( previousLanguages ) {
$.cookie( mw.uls.previousLanguagesCookie, $.toJSON( previousLanguages ) ); $.cookie( mw.uls.previousLanguagesCookie, $.toJSON( previousLanguages ) );
}; };
mw.uls.getPreviousLanguages = function() { mw.uls.getPreviousLanguages = function () {
var previousLanguages = $.cookie( mw.uls.previousLanguagesCookie ); var previousLanguages = $.cookie( mw.uls.previousLanguagesCookie );
if ( !previousLanguages ) { if ( !previousLanguages ) {
return []; return [];
@@ -55,15 +55,15 @@
return $.parseJSON( previousLanguages ).slice( -5 ); return $.parseJSON( previousLanguages ).slice( -5 );
}; };
mw.uls.getBrowserLanguage = function() { mw.uls.getBrowserLanguage = function () {
return ( window.navigator.language || window.navigator.userLanguage ).split( '-' )[0]; return ( window.navigator.language || window.navigator.userLanguage ).split( '-' )[0];
}; };
mw.uls.getAcceptLanguageList = function() { mw.uls.getAcceptLanguageList = function () {
return mw.config.get( "wgULSAcceptLanguageList" ); return mw.config.get( "wgULSAcceptLanguageList" );
}; };
mw.uls.getFrequentLanguageList = function() { mw.uls.getFrequentLanguageList = function () {
var unique = [], var unique = [],
list = [ mw.config.get( 'wgUserLanguage' ), list = [ mw.config.get( 'wgUserLanguage' ),
mw.config.get( 'wgContentLanguage' ), mw.config.get( 'wgContentLanguage' ),
@@ -73,13 +73,13 @@
if ( window.GEO ) { if ( window.GEO ) {
list = list.concat( $.uls.data.languagesInTerritory( window.GEO.country_code ) ); list = list.concat( $.uls.data.languagesInTerritory( window.GEO.country_code ) );
} }
$.each( list, function( i, v ) { $.each( list, function ( i, v ) {
if ( $.inArray( v, unique ) === -1 ) { if ( $.inArray( v, unique ) === -1 ) {
unique.push( v ); unique.push( v );
} }
} ); } );
// Filter out unknown and unsupported languages // Filter out unknown and unsupported languages
unique = $.grep( unique, function( langCode, index ) { unique = $.grep( unique, function ( langCode, index ) {
return $.fn.uls.defaults.languages[langCode]; return $.fn.uls.defaults.languages[langCode];
} ); } );
return unique; return unique;
@@ -113,7 +113,7 @@
top: position.top, top: position.top,
left: position.left left: position.left
} ); } );
$displaySettings.on( 'click', function() { $displaySettings.on( 'click', function () {
uls.hide(); uls.hide();
} ); } );
} }
@@ -122,18 +122,18 @@
onReady: function ( uls ) { onReady: function ( uls ) {
addDisplaySettings( uls ); addDisplaySettings( uls );
}, },
onSelect: function( language ) { onSelect: function ( language ) {
mw.uls.changeLanguage( language ); mw.uls.changeLanguage( language );
}, },
languages: mw.config.get( 'wgULSLanguages' ), languages: mw.config.get( 'wgULSLanguages' ),
searchAPI: mw.util.wikiScript( 'api' ) + "?action=languagesearch", searchAPI: mw.util.wikiScript( 'api' ) + "?action=languagesearch",
quickList: function() { quickList: function () {
return mw.uls.getFrequentLanguageList(); return mw.uls.getFrequentLanguageList();
} }
} ); } );
if( !previousLang ) { if ( !previousLang ) {
previousLanguages.push( currentLang ); previousLanguages.push( currentLang );
mw.uls.setPreviousLanguages( previousLanguages ); mw.uls.setPreviousLanguages( previousLanguages );
// Do not show tooltip. // Do not show tooltip.
@@ -155,7 +155,7 @@
html: true, html: true,
fade: true, fade: true,
trigger: 'manual', trigger: 'manual',
title: function() { title: function () {
var prevLangName = $.uls.data.autonym( previousLang ), var prevLangName = $.uls.data.autonym( previousLang ),
linkClass = 'uls-lang-link', linkClass = 'uls-lang-link',
title = "Language changed from <a href='#' lang = '" + title = "Language changed from <a href='#' lang = '" +
@@ -166,35 +166,35 @@
} ); } );
// Show the tipsy tooltip on page load. // Show the tipsy tooltip on page load.
$ulsTrigger.tipsy( 'show' ); $ulsTrigger.tipsy( 'show' );
tipsyTimer = window.setTimeout( function() { tipsyTimer = window.setTimeout( function () {
$ulsTrigger.tipsy('hide'); $ulsTrigger.tipsy('hide');
}, },
// The timeout after page reloading is longer, // The timeout after page reloading is longer,
// to give the user a better chance to see it. // to give the user a better chance to see it.
6000 6000
); );
$( '.tipsy' ).live( 'mouseout', function( e ) {
tipsyTimer = window.setTimeout( function() { // manually show the tooltip
$ulsTrigger.tipsy('hide'); $ulsTrigger.on( 'mouseover', function ( e ) {
}, $( this ).tipsy( 'show' );
3000 // hide the link in 3 seconds
);
} );
// if the mouse is over the tooltip, do not hide // if the mouse is over the tooltip, do not hide
$( '.tipsy' ).live( 'mouseover', function( e ) { $( '.tipsy' ).on( 'mouseover', function ( e ) {
window.clearTimeout( tipsyTimer ); window.clearTimeout( tipsyTimer );
} ); } );
// manually show the tooltip $( '.tipsy' ).on( 'mouseout', function ( e ) {
$ulsTrigger.bind( 'mouseover', function( e ) { tipsyTimer = window.setTimeout( function () {
$( this ).tipsy( 'show' ); $ulsTrigger.tipsy( 'hide' );
}, 3000 // hide the link in 3 seconds
);
} );
} ); } );
// hide the tooltip when clicked on uls trigger // hide the tooltip when clicked on uls trigger
$ulsTrigger.bind( 'click', function( e ) { $ulsTrigger.on( 'click', function ( e ) {
$( this ).tipsy( 'hide' ); $( this ).tipsy( 'hide' );
} ); } );
// Event handler for links in the tooltip // Event handler for links in the tooltip
$( 'a.uls-lang-link' ).live( 'click', function() { $( 'a.uls-lang-link' ).on( 'click', function () {
mw.uls.changeLanguage( $(this).attr( 'lang' ) ); mw.uls.changeLanguage( $( this ).attr( 'lang' ) );
} ); } );
} ); } );
}( jQuery, mediaWiki, window, document ) ); }( jQuery, mediaWiki, window, document ) );

View File

@@ -55,19 +55,20 @@
LanguageSettings.prototype = { LanguageSettings.prototype = {
constructor: LanguageSettings, constructor: LanguageSettings,
init: function(){ init: function () {
$( "body" ).append( this.$window ); $( "body" ).append( this.$window );
this.hide(); this.hide();
}, },
listen: function() { listen: function () {
var that = this; var that = this;
// Register all event listeners to the ULS language settings here. // Register all event listeners to the ULS language settings here.
that.$element.on( "click", $.proxy( that.show, that ) ); that.$element.on( "click", $.proxy( that.show, that ) );
that.$window.find( 'span#languagesettings-close' ).on( "click", $.proxy( that.hide, that ) ); that.$window.find( 'languagesettings-close' )
.on( "click", $.proxy( that.hide, that ) );
}, },
render: function() { render: function () {
// Get the name of all registered modules and list them in left side menu. // Get the name of all registered modules and list them in left side menu.
var modules = $.fn.languagesettings.modules; var modules = $.fn.languagesettings.modules;
var firstModule = modules[this.options.defaultModule]; var firstModule = modules[this.options.defaultModule];
@@ -85,7 +86,7 @@
firstModule.render(); firstModule.render();
}, },
renderModule: function( moduleName ) { renderModule: function ( moduleName ) {
var $settingsMenuItems = this.$window.find( ".settings-menu-items" ); var $settingsMenuItems = this.$window.find( ".settings-menu-items" );
var module = new $.fn.languagesettings.modules[moduleName]( this ); var module = new $.fn.languagesettings.modules[moduleName]( this );
var $settingsTitle = $( "<div>" ) var $settingsTitle = $( "<div>" )
@@ -103,14 +104,14 @@
$settingsMenuItems.append( $settingsLink ); $settingsMenuItems.append( $settingsLink );
$settingsLink.on( "click", function() { $settingsLink.on( "click", function () {
var module = $( this ).data( "module" ); var module = $( this ).data( "module" );
module.render(); module.render();
$( this ).addClass( 'active' ); $( this ).addClass( 'active' );
} ); } );
}, },
show: function() { show: function () {
if ( !this.initialized ) { if ( !this.initialized ) {
this.render(); this.render();
this.initialized = true; this.initialized = true;
@@ -136,15 +137,15 @@
this.$window.hide(); this.$window.hide();
}, },
click: function( e ) { click: function ( e ) {
if ( !this.shown ) { if ( !this.shown ) {
this.show(); this.show();
} }
} }
}; };
$.fn.languagesettings = function( option ) { $.fn.languagesettings = function ( option ) {
return this.each( function() { return this.each( function () {
var $this = $( this ), var $this = $( this ),
data = $this.data( "languagesettings" ), data = $this.data( "languagesettings" ),
options = typeof option === "object" && option; options = typeof option === "object" && option;

View File

@@ -18,7 +18,7 @@
* @licence MIT License * @licence MIT License
*/ */
( function( $, mw ) { ( function ( $, mw, undefined ) {
"use strict"; "use strict";
var ULSPreferences = function ( group ) { var ULSPreferences = function ( group ) {
@@ -46,6 +46,7 @@
/** /**
* Set the preference * Set the preference
*
* @param {String} key * @param {String} key
* @param value * @param value
*/ */
@@ -58,6 +59,7 @@
/** /**
* Get a preference value for the given preference name * Get a preference value for the given preference name
*
* @param key * @param key
* @returns * @returns
*/ */
@@ -104,7 +106,7 @@
}; };
mw.uls = mw.uls || {}; mw.uls = mw.uls || {};
mw.uls.preferences = function( group ) { mw.uls.preferences = function ( group ) {
var data = $( 'body' ).data( "preferences" ); var data = $( 'body' ).data( "preferences" );
if ( !data ) { if ( !data ) {

View File

@@ -36,7 +36,7 @@
fontSelector: function ( repository, language ) { fontSelector: function ( repository, language ) {
var font = webfontsPreferences.get( language ); var font = webfontsPreferences.get( language );
if ( !font ) { if ( !font ) {
font = repository.defaultFont(language); font = repository.defaultFont( language );
} }
if ( font === 'system' ) { if ( font === 'system' ) {
font = null; font = null;