From 0385ed8bfbe281135bb6c6b7122cf49bb0de3d92 Mon Sep 17 00:00:00 2001 From: "Amir E. Aharoni" Date: Mon, 8 Oct 2012 21:30:42 +0200 Subject: [PATCH] (bug 39531) Only show the fonts dropdown if there are fonts The Display settings template is wrapped in a new
to allow easy $template.find() queries. This change requires a change in jquery.webfonts, that makes the lib function return an empty list when there are no fonts: https://github.com/wikimedia/jquery.webfonts/pull/1 Change-Id: Ief5a920439df340360a44ca95de2a7f070b96d5d --- resources/js/ext.uls.displaysettings.js | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/resources/js/ext.uls.displaysettings.js b/resources/js/ext.uls.displaysettings.js index 4485fee8..0bd5aabe 100644 --- a/resources/js/ext.uls.displaysettings.js +++ b/resources/js/ext.uls.displaysettings.js @@ -20,7 +20,8 @@ ( function ( $, mw, undefined ) { "use strict"; - var template = '
' // Top "Display settings" title + var template = '
' + + '
' // Top "Display settings" title + '
' + '

' + '
' @@ -82,6 +83,7 @@ + '' + '' + '
' + + '
' + '
'; // FIXME i18n and too much hardcoding. var DisplaySettings = function ( $parent ) { @@ -275,13 +277,15 @@ * TODO Can this be merged with prepareContentLanguages? */ prepareUIFonts: function () { - if ( this.uiLanguage === this.contentLanguage ) { - $( 'div.uls-ui-fonts' ).hide(); + var fonts = this.$webfonts.list( this.uiLanguage ), + $uiFonts = this.$template.find( 'div.uls-ui-fonts' ); + + if ( this.uiLanguage === this.contentLanguage || fonts.length === 0 ) { + $uiFonts.hide(); return; } else { - $( 'div.uls-ui-fonts' ).show(); + $uiFonts.show(); } - var fonts = this.$webfonts.list( this.uiLanguage ); var $fontSelector = this.$template.find( 'select#ui-font-selector' ); $fontSelector.find( 'option' ).remove(); @@ -317,7 +321,16 @@ * Prepare the font selector for UI language. */ prepareContentFonts: function () { - var fonts = this.$webfonts.list( this.contentLanguage ); + var fonts = this.$webfonts.list( this.contentLanguage ), + $contentFonts = this.$template.find( 'div.uls-content-fonts' ); + + if ( fonts.length === 0 ) { + $contentFonts.hide(); + return; + } else { + $contentFonts.show(); + } + var $fontSelector = this.$template.find( '#content-font-selector' ); $fontSelector.find( 'option' ).remove();