After training the PHPStorm code formatter.

See https://github.com/siebrand/MediaWiki-PHPStorm

Issue remains with anonymous functions in JavaScript.

Change-Id: I2b520f8df127452acf02deb659277a6465e6ca59
This commit is contained in:
Siebrand Mazeland
2012-09-17 17:10:59 -07:00
parent 569b09712c
commit e1a4f7f0cb
17 changed files with 336 additions and 298 deletions

View File

@@ -32,6 +32,7 @@ class UniversalLanguageSelectorHooks {
if ( $wgULSGeoService ) { if ( $wgULSGeoService ) {
$out->addModules( 'ext.uls.geoclient' ); $out->addModules( 'ext.uls.geoclient' );
} }
return true; return true;
} }
@@ -48,6 +49,7 @@ class UniversalLanguageSelectorHooks {
'localBasePath' => __DIR__, 'localBasePath' => __DIR__,
'remoteExtPath' => 'UniversalLanguageSelector', 'remoteExtPath' => 'UniversalLanguageSelector',
); );
return true; return true;
} }
@@ -57,17 +59,21 @@ class UniversalLanguageSelectorHooks {
*/ */
static function addTrigger( array &$personal_urls, &$title ) { static function addTrigger( array &$personal_urls, &$title ) {
global $wgLang; global $wgLang;
$personal_urls = array( 'uls' => array( $personal_urls = array(
'text' => $wgLang->getLanguageName( $wgLang->getCode() ), 'uls' => array(
'href' => '#', 'text' => $wgLang->getLanguageName( $wgLang->getCode() ),
'class' => 'uls-trigger', 'href' => '#',
'active' => true 'class' => 'uls-trigger',
) ) + $personal_urls; 'active' => true
)
) + $personal_urls;
return true; return true;
} }
protected static function isSupportedLanguage( $language ) { protected static function isSupportedLanguage( $language ) {
$supported = Language::fetchLanguageNames( null, 'mwfile' ); $supported = Language::fetchLanguageNames( null, 'mwfile' );
return isset( $supported[$language] ); return isset( $supported[$language] );
} }
@@ -93,6 +99,7 @@ class UniversalLanguageSelectorHooks {
return $code; return $code;
} }
} }
return ""; return "";
} }
@@ -151,6 +158,7 @@ class UniversalLanguageSelectorHooks {
public static function addConfig( &$vars ) { public static function addConfig( &$vars ) {
global $wgULSGeoService; global $wgULSGeoService;
$vars['wgULSGeoService'] = $wgULSGeoService; $vars['wgULSGeoService'] = $wgULSGeoService;
return true; return true;
} }
@@ -160,8 +168,11 @@ class UniversalLanguageSelectorHooks {
* @return bool * @return bool
*/ */
public static function addVariables( &$vars, OutputPage $out ) { public static function addVariables( &$vars, OutputPage $out ) {
$vars['wgULSLanguages'] = Language::fetchLanguageNames( $out->getLanguage()->getCode(), 'mwfile' ); $vars['wgULSLanguages'] = Language::fetchLanguageNames(
$out->getLanguage()->getCode(), 'mwfile'
);
$vars['wgULSAcceptLanguageList'] = array_keys( $out->getRequest()->getAcceptLang() ); $vars['wgULSAcceptLanguageList'] = array_keys( $out->getRequest()->getAcceptLang() );
return true; return true;
} }
} }

View File

@@ -31,7 +31,7 @@ $messages['en'] = array(
); );
/** /**
* Message documentation * Message documentation
* @author santhosh * @author santhosh
*/ */
$messages['qqq'] = array( $messages['qqq'] = array(
'UniversalLanguageSelector' => 'Extension name', 'UniversalLanguageSelector' => 'Extension name',

View File

@@ -63,7 +63,7 @@ $wgULSGeoService = 'http://freegeoip.net/json/';
*/ */
$wgULSLanguageDetection = true; $wgULSLanguageDetection = true;
$dir = __DIR__ ; $dir = __DIR__;
// Internationalization // Internationalization
$wgExtensionMessagesFiles['UniversalLanguageSelector'] = "$dir/UniversalLanguageSelector.i18n.php"; $wgExtensionMessagesFiles['UniversalLanguageSelector'] = "$dir/UniversalLanguageSelector.i18n.php";

View File

@@ -67,8 +67,8 @@ class ApiLanguageSearch extends ApiBase {
'api.php?action=languagesearch&search=ഫി&typos=1', 'api.php?action=languagesearch&search=ഫി&typos=1',
); );
} }
public function getVersion() { public function getVersion() {
return __CLASS__ . ': ' . ULS_VERSION; return __CLASS__ . ': ' . ULS_VERSION;
} }
} }

View File

@@ -44,6 +44,7 @@ class LanguageNameSearch {
$results[$code] = $name; $results[$code] = $name;
} }
} }
return $results; return $results;
} }
@@ -57,6 +58,7 @@ class LanguageNameSearch {
if ( !isset( $buckets[$bucket] ) ) { if ( !isset( $buckets[$bucket] ) ) {
$buckets[$bucket] = array(); $buckets[$bucket] = array();
} }
return $bucket; return $bucket;
} }
@@ -73,7 +75,7 @@ class LanguageNameSearch {
$thisValue = ord( $str[$i] ); $thisValue = ord( $str[$i] );
if ( $thisValue < 128 ) { if ( $thisValue < 128 ) {
return $thisValue; return $thisValue;
} else {// Codepoints larger than 127 are represented by multi-byte sequences, } else { // Codepoints larger than 127 are represented by multi-byte sequences,
if ( count( $values ) === 0 ) { if ( count( $values ) === 0 ) {
// 224 is the lowest non-overlong-encoded codepoint. // 224 is the lowest non-overlong-encoded codepoint.
$lookingFor = ( $thisValue < 224 ) ? 2 : 3; $lookingFor = ( $thisValue < 224 ) ? 2 : 3;
@@ -82,6 +84,7 @@ class LanguageNameSearch {
if ( count( $values ) === $lookingFor ) { if ( count( $values ) === $lookingFor ) {
// Refer http://en.wikipedia.org/wiki/UTF-8#Description // Refer http://en.wikipedia.org/wiki/UTF-8#Description
$number = ( $lookingFor === 3 ) ? ( ( $values[0] % 16 ) * 4096 ) + ( ( $values[1] % 64 ) * 64 ) + ( $values[2] % 64 ) : ( ( $values[0] % 32 ) * 64 ) + ( $values[1] % 64 ); $number = ( $lookingFor === 3 ) ? ( ( $values[0] % 16 ) * 4096 ) + ( ( $values[1] % 64 ) * 64 ) + ( $values[2] % 64 ) : ( ( $values[0] % 32 ) * 64 ) + ( $values[1] % 64 );
return $number; return $number;
} }
} }
@@ -120,7 +123,7 @@ class LanguageNameSearch {
} }
$prevRow = $currentRow; $prevRow = $currentRow;
} }
return $prevRow[$length2]; return $prevRow[$length2];
} }
} }

View File

@@ -82,8 +82,7 @@ button.button.down {
button.button:disabled, button.button:disabled,
button.button.hover:disabled, button.button.hover:disabled,
button.button.disabled, button.button.disabled,
button.button.disabled:hover button.button.disabled:hover {
{
background-color: #F0F0F0; background-color: #F0F0F0;
background-image: -webkit-linear-gradient(top, #f0f0f0, #f0f0f0); background-image: -webkit-linear-gradient(top, #f0f0f0, #f0f0f0);
background-image: -moz-linear-gradient(center top, #F0F0F0, #F0F0F0); background-image: -moz-linear-gradient(center top, #F0F0F0, #F0F0F0);

View File

@@ -1,4 +1,4 @@
.uls-font-label,.uls-font-select { .uls-font-label, .uls-font-select {
font-size: 10pt; font-size: 10pt;
line-height: 16pt; line-height: 16pt;
} }
@@ -17,11 +17,11 @@
width: auto; width: auto;
} }
.uls-content-fonts,.uls-ui-fonts { .uls-content-fonts, .uls-ui-fonts {
padding-top: 10px; padding-top: 10px;
} }
.uls-content-fonts:hover,.uls-ui-fonts:hover { .uls-content-fonts:hover, .uls-ui-fonts:hover {
background-color: #F6F6F6; background-color: #F6F6F6;
} }

View File

@@ -1,6 +1,5 @@
#uls-current-language-nav { /* @embed */ #uls-current-language-nav { /* @embed */
background: url('../images/cog-16x16-ltr.png') no-repeat scroll right background: url('../images/cog-16x16-ltr.png') no-repeat scroll right top transparent;
top transparent;
cursor: pointer; cursor: pointer;
} }
@@ -93,7 +92,6 @@
border-left-color: #3366BB; border-left-color: #3366BB;
} }
#languagesettings-panels div#settings-block { #languagesettings-panels div#settings-block {
border-left: 1px solid #C9C9C9; border-left: 1px solid #C9C9C9;
padding-left: 10px; padding-left: 10px;

View File

@@ -17,39 +17,39 @@
* @licence MIT License * @licence MIT License
*/ */
( function( $, mw, undefined ) { ( function ( $, mw, undefined ) {
"use strict"; "use strict";
var template = '<div class="row"><div class="twelve columns"><h3>Display settings</h3></div></div>' var template = '<div class="row"><div class="twelve columns"><h3>Display settings</h3></div></div>'
+ '<div class="row"><div class="eleven columns"><h4>Language used for menus</h4></div></div>' + '<div class="row"><div class="eleven columns"><h4>Language used for menus</h4></div></div>'
+ '<div class="row"><div class="uls-ui-languages eleven columns">' + '<div class="row"><div class="uls-ui-languages eleven columns">'
+ '</div></div>' + '</div></div>'
+ '<div class="row"><div class="twelve columns"><h4>Font settings</h4></div></div>' + '<div class="row"><div class="twelve columns"><h4>Font settings</h4></div></div>'
+ '<div class="row">' + '<div class="row">'
+ '<div class="eleven columns">' + '<div class="eleven columns">'
+ '<label class="checkbox"><input type="checkbox" id="webfonts-enable-checkbox" />' + '<label class="checkbox"><input type="checkbox" id="webfonts-enable-checkbox" />'
+ '<strong>Download fonts automatically when needed</strong> ' + '<strong>Download fonts automatically when needed</strong> '
+ 'Web fonts will be downloaded when text in special scripts is displayed. ' + 'Web fonts will be downloaded when text in special scripts is displayed. '
+ '<a target="_blank" href="//www.mediawiki.org/wiki/Special:MyLanguage/Help:Extension:WebFonts">More information</a>' + '<a target="_blank" href="//www.mediawiki.org/wiki/Special:MyLanguage/Help:Extension:WebFonts">More information</a>'
+ '</span></label>' + '</span></label>'
+ '</div>' + '</div>'
+ '</div>' + '</div>'
+ '<div class="row"><h5 class="twelve columns">Select your preferred fonts</h5></div>' + '<div class="row"><h5 class="twelve columns">Select your preferred fonts</h5></div>'
+ '<div class="row uls-content-fonts">' + '<div class="row uls-content-fonts">'
+ '<div class="six columns"><label class="uls-font-label" id="content-font-selector-label"></label></div>' + '<div class="six columns"><label class="uls-font-label" id="content-font-selector-label"></label></div>'
+ '<select id="content-font-selector" class="four columns end uls-font-select"></select>' + '<select id="content-font-selector" class="four columns end uls-font-select"></select>'
+ '</div>' + '</div>'
+ '<div class="row uls-ui-fonts">' + '<div class="row uls-ui-fonts">'
+ '<div class="six columns"><label class="uls-font-label" id="ui-font-selector-label"></label></div>' + '<div class="six columns"><label class="uls-font-label" id="ui-font-selector-label"></label></div>'
+ '<select id="ui-font-selector" class="four columns end uls-font-select"></select>' + '<select id="ui-font-selector" class="four columns end uls-font-select"></select>'
+ '</div>' + '</div>'
+ '<div class="row"></div>' + '<div class="row"></div>'
+ '<div class="row language-settings-buttons">' + '<div class="row language-settings-buttons">'
+ '<div class="eleven columns">' + '<div class="eleven columns">'
+ '<button class="button uls-settings-close">Cancel</button>' + '<button class="button uls-settings-close">Cancel</button>'
+ '<button id="uls-displaysettings-apply" class="active blue button">Apply changes</button>' + '<button id="uls-displaysettings-apply" class="active blue button">Apply changes</button>'
+ '</div>' + '</div>'
+ '</div>'; // FIXME i18n and too much hardcoding. + '</div>'; // FIXME i18n and too much hardcoding.
var DisplaySettings = function ( $parent ) { var DisplaySettings = function ( $parent ) {
this.name = "Display"; this.name = "Display";
@@ -236,7 +236,7 @@
$systemFont.attr( 'selected', savedFont === 'system' || !savedFont ); $systemFont.attr( 'selected', savedFont === 'system' || !savedFont );
var $fontLabel = this.$template.find( 'label#ui-font-selector-label' ); var $fontLabel = this.$template.find( 'label#ui-font-selector-label' );
$fontLabel.html( "<strong>Select font for " + $.uls.data.autonym( this.uiLanguage ) $fontLabel.html( "<strong>Select font for " + $.uls.data.autonym( this.uiLanguage )
+ "</strong><div>Used for menus</div>" ); + "</strong><div>Used for menus</div>" );
}, },
/** /**
@@ -264,7 +264,7 @@
$systemFont.attr( 'selected', savedFont === 'system' || !savedFont ); $systemFont.attr( 'selected', savedFont === 'system' || !savedFont );
var $fontLabel = this.$template.find( '#content-font-selector-label' ); var $fontLabel = this.$template.find( '#content-font-selector-label' );
$fontLabel.html( "<strong>Select font for " + $.uls.data.autonym( this.contentLanguage ) $fontLabel.html( "<strong>Select font for " + $.uls.data.autonym( this.contentLanguage )
+ "</strong><div>Used for content</div>" ); + "</strong><div>Used for content</div>" );
}, },
/** /**
@@ -326,7 +326,7 @@
* Close the language settings window. * Close the language settings window.
* Depending on the context, actions vary. * Depending on the context, actions vary.
*/ */
close: function () { close: function () {
this.$parent.close(); this.$parent.close();
}, },

View File

@@ -17,7 +17,7 @@
* @licence MIT License * @licence MIT License
*/ */
( function( mw, $ ) { ( function ( mw, $ ) {
"use strict"; "use strict";
mw.uls = mw.uls || {}; mw.uls = mw.uls || {};

View File

@@ -26,7 +26,6 @@
searchAPI: mw.util.wikiScript( 'api' ) + "?action=languagesearch" searchAPI: mw.util.wikiScript( 'api' ) + "?action=languagesearch"
} ); } );
var currentLang = mw.config.get( 'wgUserLanguage' ); var currentLang = mw.config.get( 'wgUserLanguage' );
mw.uls = mw.uls || {}; mw.uls = mw.uls || {};
mw.uls.previousLanguagesCookie = 'uls-previous-languages'; mw.uls.previousLanguagesCookie = 'uls-previous-languages';
@@ -65,9 +64,11 @@
mw.uls.getFrequentLanguageList = function () { mw.uls.getFrequentLanguageList = function () {
var unique = [], var unique = [],
list = [ mw.config.get( 'wgUserLanguage' ), list = [
mw.config.get( 'wgUserLanguage' ),
mw.config.get( 'wgContentLanguage' ), mw.config.get( 'wgContentLanguage' ),
mw.uls.getBrowserLanguage() ] mw.uls.getBrowserLanguage()
]
.concat( mw.uls.getPreviousLanguages() ) .concat( mw.uls.getPreviousLanguages() )
.concat( mw.uls.getAcceptLanguageList() ); .concat( mw.uls.getAcceptLanguageList() );
if ( window.GEO ) { if ( window.GEO ) {
@@ -85,12 +86,12 @@
return unique; return unique;
}; };
$( document ).ready( function() { $( document ).ready( function () {
var $ulsTrigger = $( '.uls-trigger' ), var $ulsTrigger = $( '.uls-trigger' ),
previousLanguages = mw.uls.getPreviousLanguages() || [], previousLanguages = mw.uls.getPreviousLanguages() || [],
previousLang = previousLanguages.slice( -1 )[0]; previousLang = previousLanguages.slice( -1 )[0];
function displaySettings() { function displaySettings () {
var $displaySettingsTitle = $( '<div>' ) var $displaySettingsTitle = $( '<div>' )
.addClass( 'settings-title' ) .addClass( 'settings-title' )
.text( 'Display settings' ), .text( 'Display settings' ),
@@ -105,7 +106,7 @@
return $displaySettings; return $displaySettings;
} }
function addDisplaySettings( uls ) { function addDisplaySettings ( uls ) {
var $displaySettings = displaySettings(); var $displaySettings = displaySettings();
uls.$menu.find( "div#settings-block" ).append( $displaySettings ); uls.$menu.find( "div#settings-block" ).append( $displaySettings );
var position = uls.position(); var position = uls.position();
@@ -136,7 +137,6 @@
} }
} ); } );
if ( !previousLang ) { if ( !previousLang ) {
previousLanguages.push( currentLang ); previousLanguages.push( currentLang );
mw.uls.setPreviousLanguages( previousLanguages ); mw.uls.setPreviousLanguages( previousLanguages );
@@ -171,7 +171,7 @@
// Show the tipsy tooltip on page load. // Show the tipsy tooltip on page load.
$ulsTrigger.tipsy( 'show' ); $ulsTrigger.tipsy( 'show' );
tipsyTimer = window.setTimeout( function () { tipsyTimer = window.setTimeout( function () {
$ulsTrigger.tipsy('hide'); $ulsTrigger.tipsy( 'hide' );
}, },
// The timeout after page reloading is longer, // The timeout after page reloading is longer,
// to give the user a better chance to see it. // to give the user a better chance to see it.

View File

@@ -17,7 +17,7 @@
* @licence MIT License * @licence MIT License
*/ */
( function( $ ) { ( function ( $ ) {
"use strict"; "use strict";
var closeRow = '<div class="row">' + var closeRow = '<div class="row">' +
@@ -34,10 +34,10 @@
settingsMenu + settingsMenu +
settingsPanel + settingsPanel +
'</div>'; '</div>';
var windowTemplate = '<div style="display: block;" id="language-settings-dialog" class="uls-menu">' + var windowTemplate = '<div style="display: block;" id="language-settings-dialog" class="uls-menu">'
closeRow + + closeRow
panelsRow + + panelsRow
'</div>'; + '</div>';
var LanguageSettings = function ( element, options ) { var LanguageSettings = function ( element, options ) {
this.$element = $( element ); this.$element = $( element );
@@ -144,7 +144,7 @@
* Will be used when moving to a different context and * Will be used when moving to a different context and
* need coming back. * need coming back.
*/ */
hide: function() { hide: function () {
this.shown = false; this.shown = false;
this.$window.hide(); this.$window.hide();
}, },
@@ -153,14 +153,14 @@
* Close this language settings window, and * Close this language settings window, and
* call onClose if defined from the previous context. * call onClose if defined from the previous context.
*/ */
close: function() { close: function () {
this.hide(); this.hide();
if ( this.options.onClose ) { if ( this.options.onClose ) {
this.options.onClose(); this.options.onClose();
} }
}, },
click: function( e ) { click: function ( e ) {
if ( !this.shown ) { if ( !this.shown ) {
this.show(); this.show();
} }

View File

@@ -19,7 +19,7 @@
( function ( $, mw, document, undefined ) { ( function ( $, mw, document, undefined ) {
"use strict"; "use strict";
$( document ).ready( function() { $( document ).ready( function () {
var mediawikiFontRepository = $.webfonts.repository; var mediawikiFontRepository = $.webfonts.repository;
var webfontsPreferences = mw.uls.preferences( 'webfonts' ); var webfontsPreferences = mw.uls.preferences( 'webfonts' );
mediawikiFontRepository.base = mw.config.get( 'wgExtensionAssetsPath' ) mediawikiFontRepository.base = mw.config.get( 'wgExtensionAssetsPath' )
@@ -43,7 +43,7 @@
} }
return font; return font;
}, },
exclude: function() { exclude: function () {
if ( mw.user.options.get( 'editfont' ) ) { if ( mw.user.options.get( 'editfont' ) ) {
// Exclude textboxes from webfonts if user has edit area font option // Exclude textboxes from webfonts if user has edit area font option
// set using 'Preferences' page // set using 'Preferences' page

View File

@@ -1,38 +1,38 @@
<!DOCTYPE html> <!DOCTYPE html>
<html lang="en" dir="ltr"> <html lang="en" dir="ltr">
<head> <head>
<meta charset="utf-8"/> <meta charset="utf-8"/>
<!-- <!--
Always force latest IE rendering engine (even in intranet) & Chrome Frame Always force latest IE rendering engine (even in intranet) & Chrome Frame
Remove this if you use the .htaccess Remove this if you use the .htaccess
--> -->
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"/> <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"/>
<title>Universal Language Selector</title> <title>Universal Language Selector</title>
<!-- <link rel="shortcut icon" href="/favicon.ico"/> --> <!-- <link rel="shortcut icon" href="/favicon.ico"/> -->
<!-- <link rel="apple-touch-icon" href="/apple-touch-icon.png"/> --> <!-- <link rel="apple-touch-icon" href="/apple-touch-icon.png"/> -->
<!-- <meta name="description" content=""/> --> <!-- <meta name="description" content=""/> -->
<meta name="author" content="Santhosh Thottingal"/> <meta name="author" content="Santhosh Thottingal"/>
<link href="../lib/jquery.uls/css/jquery.uls.grid.css" rel="stylesheet"/> <link href="../lib/jquery.uls/css/jquery.uls.grid.css" rel="stylesheet"/>
<link href="../lib/jquery.uls/css/jquery.uls.css" rel="stylesheet"/> <link href="../lib/jquery.uls/css/jquery.uls.css" rel="stylesheet"/>
<link href="../resources/css/ext.uls.css" rel="stylesheet"/> <link href="../resources/css/ext.uls.css" rel="stylesheet"/>
<!-- Libs --> <!-- Libs -->
<script src="../lib/jquery.uls/examples/resources/jquery.js"></script> <script src="../lib/jquery.uls/examples/resources/jquery.js"></script>
<script src="../lib/jquery.webfonts.js"></script> <script src="../lib/jquery.webfonts.js"></script>
<!-- Source --> <!-- Source -->
<link href="../resources/css/ext.languagesettings.css" rel="stylesheet"/> <link href="../resources/css/ext.languagesettings.css" rel="stylesheet"/>
<script src="../resources/js/ext.uls.languagesettings.js"></script> <script src="../resources/js/ext.uls.languagesettings.js"></script>
<script src="../resources/js/ext.uls.displaysettings.js"></script> <script src="../resources/js/ext.uls.displaysettings.js"></script>
<script src="../resources/js/ext.uls.webfonts.js"></script> <script src="../resources/js/ext.uls.webfonts.js"></script>
<script> <script>
$( document ).ready( function() { $( document ).ready( function () {
$( '.uls-languagesettings-trigger' ).languagesettings(); $( '.uls-languagesettings-trigger' ).languagesettings();
} ); } );
</script> </script>
</head> </head>
<body> <body>
<a href="#" class="uls-languagesettings-trigger">Language Settings</a> <a href="#" class="uls-languagesettings-trigger">Language Settings</a>
</body> </body>
</html> </html>

View File

@@ -24,7 +24,7 @@ class LanguageSearchTest extends PHPUnit_Framework_TestCase {
* @dataProvider searchDataProvider * @dataProvider searchDataProvider
*/ */
public function testSearch( $searchKey, $result ) { public function testSearch( $searchKey, $result ) {
$this->assertEquals( $result, LanguageNameSearch::search( $searchKey, 1 ) ); $this->assertEquals( $result, LanguageNameSearch::search( $searchKey, 1 ) );
} }
public function searchDataProvider() { public function searchDataProvider() {

View File

@@ -18,123 +18,148 @@
*/ */
( function () { ( function () {
"use strict"; "use strict";
module( "ext.uls", QUnit.newMwEnvironment() ); module( "ext.uls", QUnit.newMwEnvironment() );
/* /*
* Runs over all script codes mentioned in langdb and checks whether * Runs over all script codes mentioned in langdb and checks whether
* they belong to the 'Other' group. * they belong to the 'Other' group.
*/ */
var orphanScripts = function () { var orphanScripts = function () {
var result = []; var result = [];
for ( var language in $.uls.data.languages ) { for ( var language in $.uls.data.languages ) {
var script = $.uls.data.script( language ); var script = $.uls.data.script( language );
if ( $.uls.data.groupOfScript( script ) === 'Other' ) { if ( $.uls.data.groupOfScript( script ) === 'Other' ) {
result.push( script ); result.push( script );
}
} }
}
return result; return result;
}; };
/* /*
* Runs over all script codes mentioned in langdb and checks whether * Runs over all script codes mentioned in langdb and checks whether
* they have something that looks like an autonym. * they have something that looks like an autonym.
*/ */
var languagesWithoutAutonym = function () { var languagesWithoutAutonym = function () {
var result = []; var result = [];
for ( var language in $.uls.data.languages ) { for ( var language in $.uls.data.languages ) {
if ( typeof $.uls.data.autonym( language ) !== 'string' ) { if ( typeof $.uls.data.autonym( language ) !== 'string' ) {
result.push( language ); result.push( language );
}
} }
}
return result; return result;
}; };
test( "-- Initial check", function() { test( "-- Initial check", function () {
expect( 1 ); expect( 1 );
ok( $.fn.uls, "$.fn.uls is defined" ); ok( $.fn.uls, "$.fn.uls is defined" );
} ); } );
test( "-- $.uls.data testing", function() { test( "-- $.uls.data testing", function () {
expect( 25 ); expect( 25 );
strictEqual( $.uls.data.autonyms()['he'], 'עברית', 'Correct autonym is returned for Hebrew using autonyms().' ); strictEqual( $.uls.data.autonyms()['he'], 'עברית', 'Correct autonym is returned for Hebrew using autonyms().' );
// This test assumes that we don't want any scripts to be in the 'Other' // This test assumes that we don't want any scripts to be in the 'Other'
// group. Actually, this may become wrong some day. // group. Actually, this may become wrong some day.
deepEqual( orphanScripts(), [], 'All scripts belong to script groups.' ); deepEqual( orphanScripts(), [], 'All scripts belong to script groups.' );
deepEqual( languagesWithoutAutonym(), [], 'All languages have autonyms.' ); deepEqual( languagesWithoutAutonym(), [], 'All languages have autonyms.' );
strictEqual( strictEqual(
$.uls.data.groupOfScript( 'Beng' ), $.uls.data.groupOfScript( 'Beng' ),
'SouthAsian', 'SouthAsian',
'Bengali script belongs to the SouthAsian group.' 'Bengali script belongs to the SouthAsian group.'
); );
strictEqual( strictEqual(
$.uls.data.scriptGroupOfLanguage( 'iu' ), $.uls.data.scriptGroupOfLanguage( 'iu' ),
'NativeAmerican', 'NativeAmerican',
'The script of the Inupiaq language belongs to the NativeAmerican group.' 'The script of the Inupiaq language belongs to the NativeAmerican group.'
); );
strictEqual( $.uls.data.script( 'ii' ), 'Yiii', 'Correct script of the Yi language was selected' ); strictEqual( $.uls.data.script( 'ii' ), 'Yiii', 'Correct script of the Yi language was selected' );
deepEqual( $.uls.data.regions( 'lzz' ), [ 'EU', 'ME' ], 'Correct regions of the Laz language were selected' ); deepEqual( $.uls.data.regions( 'lzz' ), [
strictEqual( $.uls.data.regions( 'no-such-language' ), 'UNKNOWN', "The region of an invalid language is 'UNKNOWN'" ); 'EU', 'ME'
], 'Correct regions of the Laz language were selected' );
strictEqual( $.uls.data.regions( 'no-such-language' ), 'UNKNOWN', "The region of an invalid language is 'UNKNOWN'" );
var allLanguagesByRegionAndScript = $.uls.data.allLanguagesByRegionAndScript(); var allLanguagesByRegionAndScript = $.uls.data.allLanguagesByRegionAndScript();
deepEqual( allLanguagesByRegionAndScript['4']['AS']['SouthEastAsian']['Bugi'], ['bug'], 'All languages in the Buginese script in Asia were selected' ); deepEqual( allLanguagesByRegionAndScript['4']['AS']['SouthEastAsian']['Bugi'], [
'bug'
], 'All languages in the Buginese script in Asia were selected' );
deepEqual( $.uls.data.languagesInRegion( "PA" ), deepEqual( $.uls.data.languagesInRegion( "PA" ),
["ace", "bi", "ch", "en-gb", "en", "fj", "haw", "hif-latn", "hif", "ho", "jv", [
"mh", "mi", "na", "niu", "pih", "pis", "pt", "rtm", "sm", "tet", "ace", "bi", "ch", "en-gb", "en", "fj", "haw", "hif-latn", "hif", "ho", "jv",
"to", "tpi", "ty", "wls"], "mh", "mi", "na", "niu", "pih", "pis", "pt", "rtm", "sm", "tet",
"to", "tpi", "ty", "wls"
],
"languages of region PA are selected correctly" ); "languages of region PA are selected correctly" );
deepEqual( $.uls.data.languagesInRegions( ["AM", "WW"] ), deepEqual( $.uls.data.languagesInRegions( ["AM", "WW"] ),
[ [
"akz", "arn", "aro", "ase", "avk", "ay", "cho", "chr", "chy", "cr-cans", "cr-latn", "cr", "akz", "arn", "aro", "ase", "avk", "ay", "cho", "chr", "chy", "cr-cans", "cr-latn",
"en-ca", "en", "eo", "es-419", "es-formal", "es", "esu", "fr", "cr", "en-ca", "en", "eo", "es-419", "es-formal", "es", "esu", "fr", "gcf", "gn",
"gcf", "gn", "guc", "haw", "ht", "ia", "ie", "ik", "ike-cans", "ike-latn", "io", "iu", "guc", "haw", "ht", "ia", "ie", "ik", "ike-cans", "ike-latn", "io", "iu", "jam",
"jam", "jbo", "kgp", "kl", "lad", "lfn", "mfe", "mic", "mus", "nah", "nl-informal", "nl", "nov", "nv", "jbo", "kgp", "kl", "lad", "lfn", "mfe", "mic", "mus", "nah", "nl-informal", "nl",
"pap", "pdc", "pdt", "ppl", "pt-br", "pt", "qu", "qug", "rap", "sei", "simple", "srn", "tokipona", "nov", "nv", "pap", "pdc", "pdt", "ppl", "pt-br", "pt", "qu", "qug", "rap", "sei",
"vo", "yi", "yrl", "yua" "simple", "srn", "tokipona", "vo", "yi", "yrl", "yua"
], ],
"languages of regions AM and WW are selected correctly" "languages of regions AM and WW are selected correctly"
); );
deepEqual( $.uls.data.languagesInScript( 'Knda' ), ["kn", "tcy"], "languages in script Knda are selected correctly" ); deepEqual( $.uls.data.languagesInScript( 'Knda' ), [
deepEqual( $.uls.data.languagesInScripts( ['Geor', 'Armn'] ), "kn", "tcy"
["hy", "ka", "xmf"], ], "languages in script Knda are selected correctly" );
"languages in scripts Geor and Armn are selected correctly" deepEqual( $.uls.data.languagesInScripts( ['Geor', 'Armn'] ),
); ["hy", "ka", "xmf"],
"languages in scripts Geor and Armn are selected correctly"
);
deepEqual( $.uls.data.regionsInGroup( 3 ), ["EU", "ME", "AF"], "regions in group 2 are selected correctly" ); deepEqual( $.uls.data.regionsInGroup( 3 ), [
deepEqual( $.uls.data.regionsInGroup( 2 ), ["AM"], "regions in group 2 are selected correctly" ); "EU", "ME", "AF"
deepEqual( $.uls.data.regionsInGroup( 1 ), ["WW"], "regions in group 1 are selected correctly" ); ], "regions in group 2 are selected correctly" );
deepEqual( $.uls.data.regionsInGroup( 2 ), [
"AM"
], "regions in group 2 are selected correctly" );
deepEqual( $.uls.data.regionsInGroup( 1 ), [
"WW"
], "regions in group 1 are selected correctly" );
var languagesByScriptInAM = $.uls.data.languagesByScriptInRegion( "AM" ); var languagesByScriptInAM = $.uls.data.languagesByScriptInRegion( "AM" );
deepEqual( languagesByScriptInAM['Cans'], ["cr-cans", "cr", "ike-cans", "iu"], "correct languages in Cans in AM selected" ); deepEqual( languagesByScriptInAM['Cans'], [
"cr-cans", "cr", "ike-cans", "iu"
], "correct languages in Cans in AM selected" );
strictEqual( $.uls.data.autonym( 'pa' ), 'ਪੰਜਾਬੀ', 'Correct autonym of the Punjabi language was selected' ); strictEqual( $.uls.data.autonym( 'pa' ), 'ਪੰਜਾਬੀ', 'Correct autonym of the Punjabi language was selected' );
var languagesByScriptGroupInEMEA = $.uls.data.languagesByScriptGroupInRegions( $.uls.data.regionsInGroup( 3 ) ); var languagesByScriptGroupInEMEA = $.uls.data.languagesByScriptGroupInRegions( $.uls.data.regionsInGroup( 3 ) );
deepEqual( languagesByScriptGroupInEMEA['WestCaucasian'], ['hy', 'ka', 'xmf'], 'Correct languages in WestCaucasian script group in EMEA selected' ); deepEqual( languagesByScriptGroupInEMEA['WestCaucasian'], [
'hy', 'ka', 'xmf'
], 'Correct languages in WestCaucasian script group in EMEA selected' );
var allLanguagesByScriptGroup = $.uls.data.allLanguagesByScriptGroup(); var allLanguagesByScriptGroup = $.uls.data.allLanguagesByScriptGroup();
deepEqual( allLanguagesByScriptGroup['Greek'], ['el', 'grc', 'pnt', 'ruq-grek', 'tsd'], 'All languages in the Greek script found' ); deepEqual( allLanguagesByScriptGroup['Greek'], [
'el', 'grc', 'pnt', 'ruq-grek', 'tsd'
], 'All languages in the Greek script found' );
deepEqual( $.uls.data.allRegions(), ["WW", "AM", "EU", "ME", "AF", "AS", "PA"], "All regions found" ); deepEqual( $.uls.data.allRegions(), [
"WW", "AM", "EU", "ME", "AF", "AS", "PA"
], "All regions found" );
// autonyms: gn: avañe'ẽ, de: deutsch, hu: magyar, fi: suomi // autonyms: gn: avañe'ẽ, de: deutsch, hu: magyar, fi: suomi
deepEqual( ['de', 'fi', 'gn', 'hu'].sort( $.uls.data.sortByAutonym ), ['gn', 'de', 'hu', 'fi'], 'Languages are correctly sorted by autonym' ); deepEqual( ['de', 'fi', 'gn', 'hu'].sort( $.uls.data.sortByAutonym ), [
'gn', 'de', 'hu', 'fi'
], 'Languages are correctly sorted by autonym' );
strictEqual( $.uls.data.isRtl( "te" ), false, "Telugu language is not RTL" ); strictEqual( $.uls.data.isRtl( "te" ), false, "Telugu language is not RTL" );
strictEqual( $.uls.data.isRtl( "dv" ), true, "Divehi language is RTL" ); strictEqual( $.uls.data.isRtl( "dv" ), true, "Divehi language is RTL" );
ok( $.inArray( "sah", $.uls.data.languagesInTerritory( "RU" ) ) > -1, "Sakha language is spoken in Russia" ); ok( $.inArray( "sah", $.uls.data.languagesInTerritory( "RU" ) )
} ); > -1, "Sakha language is spoken in Russia" );
} );
}() ); }() );

View File

@@ -1,117 +1,119 @@
<!DOCTYPE html> <!DOCTYPE html>
<html lang="en"> <html lang="en">
<head> <head>
<meta charset="utf-8" /> <meta charset="utf-8"/>
<!-- Always force latest IE rendering engine (even in intranet) & Chrome Frame <!-- Always force latest IE rendering engine (even in intranet) & Chrome Frame
Remove this if you use the .htaccess --> Remove this if you use the .htaccess -->
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" /> <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"/>
<title>jQuery WebFonts Example</title> <title>jQuery WebFonts Example</title>
<meta name="description" content="" /> <meta name="description" content=""/>
<meta name="author" content="Santhosh Thottingal" /> <meta name="author" content="Santhosh Thottingal"/>
<!-- Replace favicon.ico & apple-touch-icon.png in the root of your domain and delete these references --> <!-- Replace favicon.ico & apple-touch-icon.png in the root of your domain and delete these references -->
<link rel="shortcut icon" href="/favicon.ico" /> <link rel="shortcut icon" href="/favicon.ico"/>
<link rel="apple-touch-icon" href="/apple-touch-icon.png" /> <link rel="apple-touch-icon" href="/apple-touch-icon.png"/>
<script src="../lib/jquery.uls/examples/resources/jquery.js"></script> <script src="../lib/jquery.uls/examples/resources/jquery.js"></script>
<script src="../lib/jquery.webfonts.js"></script> <script src="../lib/jquery.webfonts.js"></script>
<script src="../lib/jquery.uls/src/jquery.uls.data.js"></script> <script src="../lib/jquery.uls/src/jquery.uls.data.js"></script>
<script src="../lib/jquery.uls/src/jquery.uls.data.utils.js"></script> <script src="../lib/jquery.uls/src/jquery.uls.data.utils.js"></script>
<script src="../resources/js/ext.uls.webfonts.repository.js"></script> <script src="../resources/js/ext.uls.webfonts.repository.js"></script>
<script> <script>
$( document ).ready( $( document ).ready(
function() { function () {
$( 'div#webfonts-preview-area' ).webfonts( { $( 'div#webfonts-preview-area' ).webfonts( {
repository : $.webfonts.repository repository: $.webfonts.repository
} ); } );
// get an instance of WebFonts // get an instance of WebFonts
var $webfonts = $( 'div#webfonts-preview-area' ).data( var $webfonts = $( 'div#webfonts-preview-area' ).data(
'webfonts' ); 'webfonts' );
// Get a list of all fonts provided by WebFonts // Get a list of all fonts provided by WebFonts
var fonts = $webfonts.list(); var fonts = $webfonts.list();
var languages = $webfonts.languages(); var languages = $webfonts.languages();
// Also test system fonts. // Also test system fonts.
var $fontSelector = $( 'select#fontselector' ); var $fontSelector = $( 'select#fontselector' );
var $langselector = $( 'select#language' ); var $langselector = $( 'select#language' );
function listFonts(fonts) { function listFonts ( fonts ) {
$.merge( fonts, [ 'Sans', 'Serif' ] ); $.merge( fonts, ['Sans', 'Serif'] );
$fontSelector.find('option').remove(); $fontSelector.find( 'option' ).remove();
$.each( fonts, function(key, font) { $.each( fonts, function ( key, font ) {
$fontSelector.append( $( "<option></option>" ).attr( $fontSelector.append( $( "<option></option>" ).attr(
"value", font ).text( font ) ); "value", font ).text( font ) );
} ); } );
$fontSelector.trigger( 'change' ); $fontSelector.trigger( 'change' );
} }
listFonts(fonts);
$.each( languages, function(lang, language) {
$langselector.append( $( "<option></option>" ).attr(
"value", language ).text(language+ " - "+
$.uls.data.autonym( language ) ) );
} );
$fontSelector.on( 'change', function() {
var font = $fontSelector.find( 'option:selected' ).val();
$webfonts.apply( font );
} );
$langselector.on( 'change', function() {
var language = $langselector.find( 'option:selected' )
.val();
listFonts($webfonts.list(language));
$( '#webfonts-preview-area' ).text( $.uls.data.autonym( language ) );
} );
} )
</script>
<style>
div#webfonts-preview-toolbar {
background-color: #F9F9F9;
border: 1px solid #CCCCCC;
border-radius: 4px 4px 0 0;
overflow: hidden;
padding: 2px;
position: relative;
}
div#webfonts-preview-area { listFonts( fonts );
border: 1px solid #CCCCCC; $.each( languages, function ( lang, language ) {
border-radius: 0 0 4px 4px; $langselector.append( $( "<option></option>" ).attr(
height: 150px; "value", language ).text( language + " - " +
langselector line-height: 1.5em; $.uls.data.autonym( language ) ) );
overflow: auto; } );
padding: 10px 5px; $fontSelector.on( 'change', function () {
text-align: left; var font = $fontSelector.find( 'option:selected' ).val();
font-size: 16px; $webfonts.apply( font );
} } );
$langselector.on( 'change', function () {
var language = $langselector.find( 'option:selected' )
.val();
listFonts( $webfonts.list( language ) );
$( '#webfonts-preview-area' ).text( $.uls.data.autonym( language ) );
} );
} )
</script>
<style>
div#webfonts-preview-toolbar {
background-color: #F9F9F9;
border: 1px solid #CCCCCC;
border-radius: 4px 4px 0 0;
overflow: hidden;
padding: 2px;
position: relative;
}
select { div#webfonts-preview-area {
width: 200px; border: 1px solid #CCCCCC;
height: 25px; border-radius: 0 0 4px 4px;
} height: 150px;
langselector line-height: 1.5em;
overflow: auto;
padding: 10px 5px;
text-align: left;
font-size: 16px;
}
.langselector,.fontselector { select {
float: left; width: 200px;
display: block; height: 25px;
} }
</style>
.langselector, .fontselector {
float: left;
display: block;
}
</style>
</head> </head>
<body> <body>
<div> <div>
<header> <header>
<h1>jQuery WebFonts example</h1> <h1>jQuery WebFonts example</h1>
</header> </header>
<div id='container'> <div id='container'>
<div id="webfonts-preview-toolbar"> <div id="webfonts-preview-toolbar">
<div class='langselector'> <div class='langselector'>
Language: <select name="language" id="language"> Language: <select name="language" id="language">
</select> </select>
</div> </div>
<div class='fontselector'> <div class='fontselector'>
Font : <select id="fontselector"></select> Font : <select id="fontselector"></select>
</div> </div>
</div> </div>
<div contenteditable="true" id="webfonts-preview-area">The quick brown fox jumps over the <div contenteditable="true" id="webfonts-preview-area">The quick brown fox jumps over the
lazy dog</div> lazy dog
</div> </div>
</div> </div>
</div>
</body> </body>
</html> </html>