diff options
author | 2015-08-15 13:31:33 +0200 | |
---|---|---|
committer | 2015-08-15 13:31:33 +0200 | |
commit | e50bd0890c549fe3f4b5cd1cc990c643ba130ead (patch) | |
tree | 2f7c84bdb7011a0c43bad01b1af62153a626caef /MLEB/UniversalLanguageSelector/resources/js | |
parent | Update Widgets (diff) | |
download | extensions-e50bd0890c549fe3f4b5cd1cc990c643ba130ead.tar.gz extensions-e50bd0890c549fe3f4b5cd1cc990c643ba130ead.tar.bz2 extensions-e50bd0890c549fe3f4b5cd1cc990c643ba130ead.zip |
Update MLEB
Diffstat (limited to 'MLEB/UniversalLanguageSelector/resources/js')
6 files changed, 81 insertions, 91 deletions
diff --git a/MLEB/UniversalLanguageSelector/resources/js/ext.uls.compactlinks.js b/MLEB/UniversalLanguageSelector/resources/js/ext.uls.compactlinks.js index 20c44e9f..20364f88 100644 --- a/MLEB/UniversalLanguageSelector/resources/js/ext.uls.compactlinks.js +++ b/MLEB/UniversalLanguageSelector/resources/js/ext.uls.compactlinks.js @@ -239,7 +239,7 @@ var assistantLanguages = mw.user.options.get( 'translate-editlangs' ); if ( assistantLanguages && assistantLanguages !== 'default' ) { - return $.grep( assistantLanguages.split(/,\s*/), function ( language ) { + return $.grep( assistantLanguages.split( /,\s*/ ), function ( language ) { return $.inArray( language, languages ) >= 0; } ); } @@ -287,20 +287,16 @@ * Add the trigger at the bottom of the language list */ addTrigger: function () { - var $trigger, $triggerLabel; + var $trigger; $trigger = $( '<button>' ) .addClass( 'mw-interlanguage-selector mw-ui-button active' ) - .html( '…' ); // '…' - - $triggerLabel = $( '<label>' ) - .attr( 'id', 'more-lang-label' ) - .text( $.i18n( + .html( $.i18n( 'ext-uls-compact-link-count', mw.language.convertNumber( this.listSize - this.compactSize ) ) ); - this.$interlanguageList.append( $trigger, $triggerLabel ); + this.$interlanguageList.append( $trigger ); this.$trigger = $trigger; }, diff --git a/MLEB/UniversalLanguageSelector/resources/js/ext.uls.displaysettings.js b/MLEB/UniversalLanguageSelector/resources/js/ext.uls.displaysettings.js index bf57aed4..3d90e05a 100644 --- a/MLEB/UniversalLanguageSelector/resources/js/ext.uls.displaysettings.js +++ b/MLEB/UniversalLanguageSelector/resources/js/ext.uls.displaysettings.js @@ -533,7 +533,7 @@ mw.webfonts.setup(); // Allow the webfonts library to finish loading - setTimeout( function() { + setTimeout( function () { displaySettings.$webfonts = $( 'body' ).data( 'webfonts' ); mw.webfonts.preferences.enable(); diff --git a/MLEB/UniversalLanguageSelector/resources/js/ext.uls.init.js b/MLEB/UniversalLanguageSelector/resources/js/ext.uls.init.js index d7c493b9..5a112e75 100644 --- a/MLEB/UniversalLanguageSelector/resources/js/ext.uls.init.js +++ b/MLEB/UniversalLanguageSelector/resources/js/ext.uls.init.js @@ -19,25 +19,7 @@ ( function ( $, mw ) { 'use strict'; - // FIXME: Remove when ULS minimum MW version is 1.22 - if ( mw.hook === undefined ) { - mw.hook = ( function () { - var lists = {}, - slice = Array.prototype.slice; - - return function ( name ) { - var list = lists[ name ] || ( lists[ name ] = $.Callbacks( 'memory' ) ); - - return { - add: list.add, - remove: list.remove, - fire: function () { - return list.fireWith( null, slice.call( arguments ) ); - } - }; - }; - }() ); - } + var hasOwn = Object.prototype.hasOwnProperty; mw.uls = mw.uls || {}; mw.uls.previousLanguagesCookie = 'uls-previous-languages'; @@ -183,7 +165,7 @@ var target; // If the language is already known and defined, just use it - if ( $.fn.uls.defaults.languages[ langCode ] !== undefined ) { + if ( hasOwn.call( $.fn.uls.defaults.languages, langCode ) ) { return true; } @@ -194,7 +176,7 @@ if ( target ) { // Check that the redirect's target is known // to this instance of ULS - return $.fn.uls.defaults.languages[ target ] !== undefined; + return hasOwn.call( $.fn.uls.defaults.languages, target ); } return false; @@ -215,12 +197,6 @@ ] }; - // jquery.client changed in MediaWiki 1.22. - // FIXME: Remove when ULS minimum MW version is 1.22. - if ( parseInt( mw.config.get( 'wgVersion' ).split( '.' )[ 1 ], '10' ) < 22 ) { - return !/MSIE [67]/i.test( navigator.userAgent ); - } - return !$.client.test( blacklist, null, true ); } diff --git a/MLEB/UniversalLanguageSelector/resources/js/ext.uls.interface.js b/MLEB/UniversalLanguageSelector/resources/js/ext.uls.interface.js index 265fa48b..96aaa2ef 100644 --- a/MLEB/UniversalLanguageSelector/resources/js/ext.uls.interface.js +++ b/MLEB/UniversalLanguageSelector/resources/js/ext.uls.interface.js @@ -164,74 +164,93 @@ } /** + * Gets the name of the previously active language + * @param {string} code Language code of previously selected language. + * @return {jQuery.Promise} + */ + function getUndoAutonym( code ) { + var + deferred = $.Deferred(), + autonym = $.cookie( mw.uls.previousLanguageAutonymCookie ); + + if ( autonym ) { + deferred.resolve( autonym ); + } else { + mw.loader.using( 'jquery.uls.data', function () { + deferred.resolve( $.uls.data.getAutonym( code ) ); + } ); + } + + return deferred.promise(); + } + + /** * The tooltip to be shown when language changed using ULS. * It also allows to undo the language selection. */ function showULSTooltip() { - var ulsPosition = mw.config.get( 'wgULSPosition' ), + var previousLang, $ulsTrigger, anonMode, showUndo, newLanguage, previousLanguages, + ulsPosition = mw.config.get( 'wgULSPosition' ), currentLang = mw.config.get( 'wgUserLanguage' ), - previousLang, - previousLanguageAutonym, - $ulsTrigger, - anonMode, rtlPage = $( 'body' ).hasClass( 'rtl' ), tipsyGravity = { personal: 'n', interlanguage: rtlPage ? 'e' : 'w' - }, - previousLanguages = mw.uls.getPreviousLanguages() || []; - - previousLang = previousLanguages.slice( -1 )[0]; + }; $ulsTrigger = ( ulsPosition === 'interlanguage' ) ? $( '.uls-settings-trigger' ) : $( '.uls-trigger' ); - if ( previousLang === currentLang ) { - $ulsTrigger.tipsy( { gravity: rtlPage ? 'e' : 'w' } ); - - return; - } - - previousLanguages.push( currentLang ); - mw.uls.setPreviousLanguages( previousLanguages ); + previousLanguages = mw.uls.getPreviousLanguages() || []; + previousLang = previousLanguages.slice( -1 )[0]; + // Whether we see current language for the first time + newLanguage = currentLang !== previousLang; + // Whether user is able to change language anonMode = ( mw.user.isAnon() && !mw.config.get( 'wgULSAnonCanChangeLanguage' ) ); + // Whether user is able to change language, and just did so + showUndo = !anonMode && newLanguage && previousLang !== undefined; + + if ( newLanguage ) { + previousLanguages.push( currentLang ); + mw.uls.setPreviousLanguages( previousLanguages ); + } - if ( anonMode || !previousLang ) { - // Do not show tooltip + if ( !showUndo ) { + // In interlanguage mode, we will have normal tooltip, make it look same using tipsy + $ulsTrigger.tipsy( { gravity: tipsyGravity[ulsPosition] } ); return; } - previousLanguageAutonym = $.cookie( mw.uls.previousLanguageAutonymCookie ) || - previousLang; - - // Attach a tipsy tooltip to the trigger - $ulsTrigger.tipsy( { - gravity: tipsyGravity[ulsPosition], - delayOut: 3000, - html: true, - fade: true, - trigger: 'manual', - title: function () { - var link; - - link = $( '<a>' ).text( previousLanguageAutonym ) - .attr( { - href: '#', - 'class': 'uls-prevlang-link', - lang: previousLang, - // We could get dir from uls.data, - // but we are trying to avoid loading it - // and 'auto' is safe enough in this context - dir: 'auto' - } ); + getUndoAutonym( previousLang ).done( function( autonym ) { + // Attach a tipsy tooltip to the trigger + $ulsTrigger.tipsy( { + gravity: tipsyGravity[ulsPosition], + delayOut: 3000, + html: true, + fade: true, + trigger: 'manual', + title: function () { + var link; + + link = $( '<a>' ).text( autonym ) + .attr( { + href: '#', + 'class': 'uls-prevlang-link', + lang: previousLang, + // We could get dir from uls.data, + // but we are trying to avoid loading it + // and 'auto' is safe enough in this context + dir: 'auto' + } ); - // Get the html of the link by wrapping it in div first - link = $( '<div>' ).html( link ).html(); + // Get the html of the link by wrapping it in div first + link = $( '<div>' ).html( link ).html(); - return mw.msg( 'ext-uls-undo-language-tooltip-text', link ); - } + return mw.message( 'ext-uls-undo-language-tooltip-text', '$1' ).escaped().replace( '$1', link ); + } + } ); } ); // Now that we set the previous languages, @@ -315,8 +334,8 @@ $pLang = $( '#p-lang' ); // Add an element near the interlanguage links header $ulsTrigger = $( '<span>' ).addClass( 'uls-settings-trigger' ); - // Append ULS cog to languages section, but make sure it is visible. - $pLang.show().prepend( $ulsTrigger ); + // Append ULS cog to languages section. + $pLang.prepend( $ulsTrigger ); // Take care of any other elements with this class. $ulsTrigger = $( '.uls-settings-trigger' ); // Remove the dummy link, which was added to make sure that the section appears diff --git a/MLEB/UniversalLanguageSelector/resources/js/ext.uls.languagesettings.js b/MLEB/UniversalLanguageSelector/resources/js/ext.uls.languagesettings.js index a6360c2a..5f93693a 100644 --- a/MLEB/UniversalLanguageSelector/resources/js/ext.uls.languagesettings.js +++ b/MLEB/UniversalLanguageSelector/resources/js/ext.uls.languagesettings.js @@ -31,9 +31,8 @@ '</div>'; settingsPanel = '<div id="languagesettings-settings-panel" class="eight columns">' + '</div>'; - buttonsRow = '<div class="row"></div>' + - // Apply and Cancel buttons - '<div class="row language-settings-buttons">' + + // Apply and Cancel buttons + buttonsRow = '<div class="row language-settings-buttons">' + '<div class="eleven columns">' + '<button class="button uls-settings-cancel" data-i18n="ext-uls-language-settings-cancel"></button>' + '<button class="button active blue uls-settings-apply" data-i18n="ext-uls-language-settings-apply" disabled></button>' + @@ -43,11 +42,11 @@ panelsRow = '<div class="row" id="languagesettings-panels">' + settingsMenu + settingsPanel + - buttonsRow + '</div>'; windowTemplate = '<div style="display: block;" id="language-settings-dialog" class="grid uls-menu uls-wide">' + closeRow + panelsRow + + buttonsRow + '</div>'; function LanguageSettings( element, options ) { diff --git a/MLEB/UniversalLanguageSelector/resources/js/ext.uls.webfonts.js b/MLEB/UniversalLanguageSelector/resources/js/ext.uls.webfonts.js index 745549ae..f905f745 100644 --- a/MLEB/UniversalLanguageSelector/resources/js/ext.uls.webfonts.js +++ b/MLEB/UniversalLanguageSelector/resources/js/ext.uls.webfonts.js @@ -98,10 +98,10 @@ for ( index = 0; index < length; index++ ) { $fixture.text( text[index] ); - width[index] = $fixture.width() || width[index-1]; + width[index] = $fixture.width() || width[index - 1]; height[index] = $fixture.height(); - if( index > 0 && + if ( index > 0 && ( width[index] !== width[index - 1] || height[index] !== height[index - 1] ) ) { @@ -206,7 +206,7 @@ // Execute after task queue is processed so that the rendering is complete. // This is important because webfonts behavior depends on the font-family // property values set by stylesheets. - setTimeout( function() { + setTimeout( function () { $( 'body' ).webfonts(); // Load the CSS required for the Autonym font. Note that this won't download the font. |