From 4a09ed96d5914e318a5a0a3c1585fc9cd3b4db00 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Niklas=20Laxstr=C3=B6m?= Date: Sat, 8 Nov 2014 11:47:33 +0100 Subject: [PATCH] Fix JavaScript error on pages without headings Error was caused because .css( 'font-family' ) returns undefined for elements which do not exist. Merged two blocks both extending the default settings. Bug: 67676 Change-Id: Ic33f3934166f4feb6dd088ca0d14e249fcf237a3 --- resources/js/ext.uls.webfonts.js | 31 ++++++++++++++----------------- 1 file changed, 14 insertions(+), 17 deletions(-) diff --git a/resources/js/ext.uls.webfonts.js b/resources/js/ext.uls.webfonts.js index 9bc30caf..745549ae 100644 --- a/resources/js/ext.uls.webfonts.js +++ b/resources/js/ext.uls.webfonts.js @@ -129,18 +129,14 @@ $.extend( $.fn.webfonts.defaults, { repository: mediawikiFontRepository, fontStack: $( 'body' ).css( 'font-family' ).split( /, /g ), - exclude: mw.config.get( 'wgULSNoWebfontsSelectors' ).join( ', ' ) - } ); - - $.fn.webfonts.defaults = $.extend( $.fn.webfonts.defaults, { - /** - * Returns a suitable font from font repository based - * on the given language and html classes and user preference. - * - * @param {Object} repository - * @param {string} language - * @param {array} classes - */ + /** + * Returns a suitable font from font repository based + * on the given language and html classes and user preference. + * + * @param {Object} repository + * @param {string} language + * @param {array} classes + */ fontSelector: function ( repository, language, classes ) { var font, autonym, defaultFont; @@ -191,19 +187,20 @@ }, exclude: ( function () { - var excludes = $.fn.webfonts.defaults.exclude; + var excludes = mw.config.get( 'wgULSNoWebfontsSelectors' ).join( ', ' ); if ( mw.user.options.get( 'editfont' ) !== 'default' ) { // Exclude textboxes from webfonts if the user has edit area font option // set using 'Preferences' page - excludes = ( excludes ) ? - excludes + ',textarea' : - 'textarea'; + excludes = excludes ? excludes + ',textarea' : 'textarea'; } return excludes; }() ), - overridableFontFamilies: [ $( 'h1' ).css( 'font-family' ) ] + overridableFontFamilies: ( function () { + var headingFont = $( 'h1' ).css( 'font-family' ); + return headingFont ? [ headingFont ] : []; + }() ) } ); // Execute after task queue is processed so that the rendering is complete.