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

View File

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

View File

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

View File

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

View File

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