diff --git a/Resources.php b/Resources.php index 5c9ef2c4..723a3c87 100644 --- a/Resources.php +++ b/Resources.php @@ -153,6 +153,16 @@ $wgResourceModules['ext.uls.webfonts'] = array( $wgResourceModules['ext.uls.webfonts.repository'] = array( 'scripts' => 'resources/js/ext.uls.webfonts.repository.js', + 'targets' => array( 'desktop', 'mobile' ), +) + $resourcePaths; + +$wgResourceModules['ext.uls.webfonts.mobile'] = array( + 'scripts' => 'resources/js/ext.uls.webfonts.mobile.js', + 'targets' => array( 'mobile' ), + 'dependencies' => array( + 'jquery.webfonts', + 'ext.uls.webfonts.repository', + ), ) + $resourcePaths; $wgResourceModules['jquery.i18n'] = array( @@ -234,6 +244,7 @@ $wgResourceModules['jquery.uls.grid'] = array( $wgResourceModules['jquery.webfonts'] = array( 'scripts' => 'lib/jquery.webfonts.js', + 'targets' => array( 'desktop', 'mobile' ), ) + $resourcePaths; // A module named rangy is defined in VisualExtension with more features of rangy. diff --git a/UniversalLanguageSelector.hooks.php b/UniversalLanguageSelector.hooks.php index 8de93f25..6e2f5638 100644 --- a/UniversalLanguageSelector.hooks.php +++ b/UniversalLanguageSelector.hooks.php @@ -344,4 +344,21 @@ class UniversalLanguageSelectorHooks { return true; } + + /** + * Add basic webfonts support to the mobile interface (via MobileFrontend extension) + * Hook: EnterMobileMode + * @param MobileContext $context + * @return bool + */ + public static function onEnterMobileMode( $context ) { + global $wgULSEnable, $wgULSMobileWebfontsEnabled; + + // Currently only supported in mobile Beta mode + if ( $wgULSEnable && $wgULSMobileWebfontsEnabled && $context->isBetaGroupMember() ) { + $context->getOutput()->addModules( 'ext.uls.webfonts.mobile' ); + } + + return true; + } } diff --git a/UniversalLanguageSelector.php b/UniversalLanguageSelector.php index c15a3309..d7ebe2f9 100644 --- a/UniversalLanguageSelector.php +++ b/UniversalLanguageSelector.php @@ -104,6 +104,12 @@ $wgULSLanguageDetection = true; */ $wgULSIMEEnabled = true; +/** + * Set whether webfont support is loaded within the mobile interface (via the + * MobileFrontend extension). + */ +$wgULSMobileWebfontsEnabled = false; + /** * The location and the form of the language selection trigger. * The possible values are: @@ -184,6 +190,7 @@ $wgAPIModules['ulslocalization'] = 'ApiULSLocalization'; $wgHooks['UserGetLanguageObject'][] = 'UniversalLanguageSelectorHooks::getLanguage'; $wgHooks['SkinTemplateOutputPageBeforeExec'][] = 'UniversalLanguageSelectorHooks::onSkinTemplateOutputPageBeforeExec'; +$wgHooks['EnterMobileMode'][] = 'UniversalLanguageSelectorHooks::onEnterMobileMode'; $wgDefaultUserOptions['uls-preferences'] = ''; $wgHooks['GetPreferences'][] = 'UniversalLanguageSelectorHooks::onGetPreferences'; diff --git a/resources/js/ext.uls.webfonts.mobile.js b/resources/js/ext.uls.webfonts.mobile.js new file mode 100644 index 00000000..43a6b53b --- /dev/null +++ b/resources/js/ext.uls.webfonts.mobile.js @@ -0,0 +1,49 @@ +/** + * MobileFrontend compatible ULS-Webfonts integration + * + * Copyright (C) 2013 Alolita Sharma, Amir Aharoni, Arun Ganesh, Brandon Harris, + * Niklas Laxström, Pau Giner, Ryan Kaldari, 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'; + + var mediawikiFontRepository; + + mw.webfonts = mw.webfonts || {}; + + mediawikiFontRepository = $.webfonts.repository; + mediawikiFontRepository.base = mw.config.get( 'wgExtensionAssetsPath' ) + + '/UniversalLanguageSelector/data/fontrepo/fonts/'; + + $( document ).ready( function () { + // MediaWiki specific overrides for jquery.webfonts + $.extend( $.fn.webfonts.defaults, { + repository: mediawikiFontRepository, + fontStack: $( 'body' ).css( 'font-family' ).split( /, /g ), + fontSelector: function ( repository, language ) { + var font = repository.defaultFont( language ); + + if ( font === 'system' ) { + // Avoid setting 'system' as a font in css + font = null; + } + + return font; + } + } ); + + $( 'body' ).webfonts(); + } ); +}( jQuery, mediaWiki ) );