diff --git a/UniversalLanguageSelector.hooks.php b/UniversalLanguageSelector.hooks.php index 015ae9dd..ce7e52ee 100644 --- a/UniversalLanguageSelector.hooks.php +++ b/UniversalLanguageSelector.hooks.php @@ -28,6 +28,8 @@ class UniversalLanguageSelectorHooks { */ public static function addModules( $out, $skin ) { $out->addModules( 'ext.uls.init' ); + $out->addModules( 'ext.uls.languagesettings' ); + $out->addModules( 'ext.uls.displaysettings' ); return true; } /** diff --git a/UniversalLanguageSelector.php b/UniversalLanguageSelector.php index 40cb79a5..583fbc2a 100644 --- a/UniversalLanguageSelector.php +++ b/UniversalLanguageSelector.php @@ -75,6 +75,22 @@ $wgResourceModules['ext.uls.init'] = array( 'position' => 'top', ); +$wgResourceModules['ext.uls.languagesettings'] = array( + 'scripts' => 'resources/js/ext.uls.languagesettings.js', + 'styles' => 'resources/css/ext.languagesettings.css', + 'localBasePath' => $dir, + 'remoteExtPath' => 'UniversalLanguageSelector', +); + +$wgResourceModules['ext.uls.displaysettings'] = array( + 'scripts' => 'resources/js/ext.uls.displaysettings.js', + 'localBasePath' => $dir, + 'dependencies' => array( + 'ext.uls.languagesettings', + ), + 'remoteExtPath' => 'UniversalLanguageSelector', +); + $wgResourceModules['jquery.uls'] = array( 'scripts' => array( 'lib/jquery.uls/src/jquery.uls.core.js', diff --git a/lib/jquery.uls/src/jquery.uls.core.js b/lib/jquery.uls/src/jquery.uls.core.js index edab8bc6..74f939b7 100644 --- a/lib/jquery.uls/src/jquery.uls.core.js +++ b/lib/jquery.uls/src/jquery.uls.core.js @@ -91,7 +91,9 @@ }, listen: function() { - var that = this, lcd; + var lcd, + that = this; + // Register all event listeners to the ULS here. that.$element.on( 'click', $.proxy( that.click, that ) ); diff --git a/resources/css/ext.languagesettings.css b/resources/css/ext.languagesettings.css new file mode 100644 index 00000000..77036921 --- /dev/null +++ b/resources/css/ext.languagesettings.css @@ -0,0 +1,89 @@ +#uls-current-language-nav { + /* @embed */ + background: url('../images/cog-16x16-ltr.png') no-repeat scroll right top transparent; + cursor: pointer; +} + +#language-settings-dialog { + display: none; /* hidden initially */ + + /* XXX pretty random position values, just to make it visible */ + bottom: 100px; + left: 200px; + + /* From here on - from .uls-menu */ + position: fixed; + z-index: 1000; + display: none; + min-width: 800px; /* changed */ + margin-top: 1px; + width: 45%; + /* Styling */ + background-color: #ffffff; + border: 1px solid #ccc; + border: 1px solid rgba(0, 0, 0, 0.2); + *border-right-width: 2px; + *border-bottom-width: 2px; + -webkit-border-radius: 5px; + -moz-border-radius: 5px; + border-radius: 5px; + -webkit-box-shadow: 0 5px 10px rgba(0, 0, 0, 0.2); + -moz-box-shadow: 0 5px 10px rgba(0, 0, 0, 0.2); + box-shadow: 0 5px 10px rgba(0, 0, 0, 0.2); + -webkit-background-clip: padding-box; + -moz-background-clip: padding; + background-clip: padding-box; +} + +/* From uls-menu, unchanged */ +#uls-current-language-nav a { + color: #0088CC; +} +#uls-current-language-nav h1 { + font-weight: normal; + padding-top: 1.25em; + border: none; + padding-bottom: 3px; + font-size: 18pt; + line-height: 1.25em; + padding-left: 15px; + color: #777; +} +#uls-current-language-nav h2 { + font-size: 16pt; + line-height: 1.5em; + padding-left: 6px; + margin-top: 0px; + margin-bottom: 15px; + border-bottom: none; + color: #777; +} +.uls-menu h3 { + font-size: 14pt; + line-height: 1.5em; + padding-left: 0px; + margin-top: 0px; + margin-bottom: 10px; + border-bottom: none; +} + +.language-settings-buttons { + text-align: right; +} + +/* Buttons in the selector panel */ +.menu-section { + color: #777; + padding: 5px 0 5px 50px; + border-left: 3px solid transparent; + display: block; + font-size: 12pt; + background: url(http://dl.dropbox.com/u/30377416/i18n/icons/WMF-Agora-Display_settings-grey.png) no-repeat scroll 15px center transparent; +} + +.menu-section.active{ + color: black; + background-color: #F6F6F6; + border-left-color: #3366BB; + background-image: url(http://dl.dropbox.com/u/30377416/i18n/icons/WMF-Agora-Display_settings-blue.svg); +} diff --git a/resources/images/cog-16x16-ltr.png b/resources/images/cog-16x16-ltr.png new file mode 100644 index 00000000..a51668fa Binary files /dev/null and b/resources/images/cog-16x16-ltr.png differ diff --git a/resources/images/cog-16x16-rtl.png b/resources/images/cog-16x16-rtl.png new file mode 100644 index 00000000..e6e6e6d9 Binary files /dev/null and b/resources/images/cog-16x16-rtl.png differ diff --git a/resources/js/ext.uls.displaysettings.js b/resources/js/ext.uls.displaysettings.js new file mode 100644 index 00000000..ea2f4fc8 --- /dev/null +++ b/resources/js/ext.uls.displaysettings.js @@ -0,0 +1,51 @@ +/** + * ULS-based display settings panel + * + * 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( $ ) { + "use strict"; + var template = '

Display Settings

' + + '

Select Language

' + + '
' + + '' + + '' + + '' + + '' + + '
' + + '

Font Settings

' + + '
' + + '' + + '' + + '
' + + '
Select your preferred fonts to use
' + + '
Fonts for English
' + + '
Fonts for Spanish
' + + '
'; + + var displaySettings = { + render: function() { + return template; + }, + name: "Display", + description: "Set the fonts for languages" + }; + + $.fn.languagesettings.modules = $.extend( $.fn.languagesettings.modules, { + display: displaySettings + } ); +} ) ( jQuery ); diff --git a/resources/js/ext.uls.languagesettings.js b/resources/js/ext.uls.languagesettings.js new file mode 100644 index 00000000..b6f6e517 --- /dev/null +++ b/resources/js/ext.uls.languagesettings.js @@ -0,0 +1,161 @@ +/** + * ULS-based language settings dialog for MediaWiki. + * + * 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( $ ) { + "use strict"; + + var closeRow = '
' + + '' + + '
'; + var settingsMenu = '
' + + '

Language settings

' + // TODO i18n + '
' + + '
' + + '
'; + var settingsPanel = '
' + + '
'; + var panelsRow = '
' + + settingsMenu + + settingsPanel + + '
'; + var windowTemplate = '
' + + closeRow + + panelsRow + + '
'; + + var LanguageSettings = function ( element, options ) { + this.$element = $( element ); + this.options = $.extend( {}, $.fn.languagesettings.defaults, options ); + this.$window = $( this.options.template ); + this.shown = false; + this.initialized = false; + this.init(); + this.listen(); + }; + + LanguageSettings.prototype = { + constructor: LanguageSettings, + + init: function(){ + $( "body" ).append( this.$window ); + this.hide(); + }, + + listen: function() { + var that = this; + // Register all event listeners to the ULS here. + that.$element.on( "click", $.proxy( that.click, that ) ); + $( ".icon-close" ).on( "click", $.proxy( that.click, that ) ); + }, + + render: function() { + // Get the name of all registered modules and list them in left side menu. + var modules = $.fn.languagesettings.modules; + var firstModuleName = this.options.defaultModule; + for ( var moduleName in modules ) { + if ( modules.hasOwnProperty( moduleName ) ) { + if ( !firstModuleName ) { + firstModuleName = moduleName; + } + // Call render function on the current setting module. + this.renderModule( moduleName ); + } + } + + // Show the default module + $( "#languagesettings-settings-panel" ).html( + $.fn.languagesettings.modules[firstModuleName].render() + ); + }, + + renderModule: function( moduleName ) { + var $settingsMenuItems = this.$window.find( ".settings-menu-items" ); + var $settingsPanel = this.$window.find( "#languagesettings-settings-panel" ); + var module = $.fn.languagesettings.modules[moduleName]; + var $settingsTitle = $( "
" ) + .addClass( "settings-title" ) + .text( module.name ); + var $settingsText = $( "" ) + .addClass( "settings-text" ) + .text( module.description ); + var $settingsLink = $( "
" ) + .addClass( moduleName + "-settings-block" ) + .prop( "id", moduleName + "-settings-block" ) + .data( "module", module ) + .append( $settingsTitle ) + .append( $settingsText ); + + $settingsMenuItems.append( $settingsLink ); + + $settingsLink.on( "click", function() { + $settingsPanel.html( $( this ).data( "module" ).render() ); + } ); + }, + + show: function() { + if ( !this.initialized ) { + this.render(); + this.initialized = true; + } + this.shown = true; + this.$window.show(); + }, + + hide: function() { + this.shown = false; + this.$window.hide(); + }, + + click: function( e ) { + e.stopPropagation(); + e.preventDefault(); + if ( !this.shown ) { + this.show(); + } else { + this.hide(); + } + } + }; + + $.fn.languagesettings = function( option ) { + return this.each( function() { + var $this = $( this ), + data = $this.data( "languagesettings" ), + options = typeof option === "object" && option; + + if ( !data ) { + $this.data( "languagesettings", ( data = new LanguageSettings( this, options ) ) ); + } + if ( typeof option === "string" ) { + data[option](); + } + } ); + }; + + $.fn.languagesettings.modules = {}; + $.fn.languagesettings.defaults = { + settings: {}, + template: windowTemplate, + modules: {}, + defaultModule: false + }; + + $.fn.languagesettings.Constructor = LanguageSettings; + +} )( jQuery ); diff --git a/tests/language_settings.html b/tests/language_settings.html new file mode 100644 index 00000000..32c7245e --- /dev/null +++ b/tests/language_settings.html @@ -0,0 +1,36 @@ + + + + + + + + + Universal Language Selector + + + + + + + + + + + + + + + + + + Language Settings + +