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

View File

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

View File

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

View File

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

View File

@@ -44,6 +44,7 @@ class LanguageNameSearch {
$results[$code] = $name;
}
}
return $results;
}
@@ -57,6 +58,7 @@ class LanguageNameSearch {
if ( !isset( $buckets[$bucket] ) ) {
$buckets[$bucket] = array();
}
return $bucket;
}
@@ -73,7 +75,7 @@ class LanguageNameSearch {
$thisValue = ord( $str[$i] );
if ( $thisValue < 128 ) {
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 ) {
// 224 is the lowest non-overlong-encoded codepoint.
$lookingFor = ( $thisValue < 224 ) ? 2 : 3;
@@ -82,6 +84,7 @@ class LanguageNameSearch {
if ( count( $values ) === $lookingFor ) {
// 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 );
return $number;
}
}
@@ -120,7 +123,7 @@ class LanguageNameSearch {
}
$prevRow = $currentRow;
}
return $prevRow[$length2];
}
}

View File

@@ -82,8 +82,7 @@ button.button.down {
button.button:disabled,
button.button.hover:disabled,
button.button.disabled,
button.button.disabled:hover
{
button.button.disabled:hover {
background-color: #F0F0F0;
background-image: -webkit-linear-gradient(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;
line-height: 16pt;
}
@@ -17,11 +17,11 @@
width: auto;
}
.uls-content-fonts,.uls-ui-fonts {
.uls-content-fonts, .uls-ui-fonts {
padding-top: 10px;
}
.uls-content-fonts:hover,.uls-ui-fonts:hover {
.uls-content-fonts:hover, .uls-ui-fonts:hover {
background-color: #F6F6F6;
}

View File

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

View File

@@ -17,39 +17,39 @@
* @licence MIT License
*/
( function( $, mw, undefined ) {
( function ( $, mw, undefined ) {
"use strict";
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="uls-ui-languages eleven columns">'
+ '</div></div>'
+ '<div class="row"><div class="twelve columns"><h4>Font settings</h4></div></div>'
+ '<div class="row">'
+ '<div class="eleven columns">'
+ '<label class="checkbox"><input type="checkbox" id="webfonts-enable-checkbox" />'
+ '<strong>Download fonts automatically when needed</strong> '
+ '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>'
+ '</span></label>'
+ '</div>'
+ '</div>'
+ '<div class="row"><h5 class="twelve columns">Select your preferred fonts</h5></div>'
+ '<div class="row uls-content-fonts">'
+ '<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>'
+ '</div>'
+ '<div class="row uls-ui-fonts">'
+ '<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>'
+ '</div>'
+ '<div class="row"></div>'
+ '<div class="row language-settings-buttons">'
+ '<div class="eleven columns">'
+ '<button class="button uls-settings-close">Cancel</button>'
+ '<button id="uls-displaysettings-apply" class="active blue button">Apply changes</button>'
+ '</div>'
+ '</div>'; // FIXME i18n and too much hardcoding.
+ '<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></div>'
+ '<div class="row"><div class="twelve columns"><h4>Font settings</h4></div></div>'
+ '<div class="row">'
+ '<div class="eleven columns">'
+ '<label class="checkbox"><input type="checkbox" id="webfonts-enable-checkbox" />'
+ '<strong>Download fonts automatically when needed</strong> '
+ '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>'
+ '</span></label>'
+ '</div>'
+ '</div>'
+ '<div class="row"><h5 class="twelve columns">Select your preferred fonts</h5></div>'
+ '<div class="row uls-content-fonts">'
+ '<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>'
+ '</div>'
+ '<div class="row uls-ui-fonts">'
+ '<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>'
+ '</div>'
+ '<div class="row"></div>'
+ '<div class="row language-settings-buttons">'
+ '<div class="eleven columns">'
+ '<button class="button uls-settings-close">Cancel</button>'
+ '<button id="uls-displaysettings-apply" class="active blue button">Apply changes</button>'
+ '</div>'
+ '</div>'; // FIXME i18n and too much hardcoding.
var DisplaySettings = function ( $parent ) {
this.name = "Display";
@@ -236,7 +236,7 @@
$systemFont.attr( 'selected', savedFont === 'system' || !savedFont );
var $fontLabel = this.$template.find( 'label#ui-font-selector-label' );
$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 );
var $fontLabel = this.$template.find( '#content-font-selector-label' );
$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.
* Depending on the context, actions vary.
*/
close: function () {
close: function () {
this.$parent.close();
},

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@@ -18,123 +18,148 @@
*/
( 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
* they belong to the 'Other' group.
*/
var orphanScripts = function () {
var result = [];
/*
* Runs over all script codes mentioned in langdb and checks whether
* they belong to the 'Other' group.
*/
var orphanScripts = function () {
var result = [];
for ( var language in $.uls.data.languages ) {
var script = $.uls.data.script( language );
if ( $.uls.data.groupOfScript( script ) === 'Other' ) {
result.push( script );
for ( var language in $.uls.data.languages ) {
var script = $.uls.data.script( language );
if ( $.uls.data.groupOfScript( script ) === 'Other' ) {
result.push( script );
}
}
}
return result;
};
return result;
};
/*
* Runs over all script codes mentioned in langdb and checks whether
* they have something that looks like an autonym.
*/
var languagesWithoutAutonym = function () {
var result = [];
/*
* Runs over all script codes mentioned in langdb and checks whether
* they have something that looks like an autonym.
*/
var languagesWithoutAutonym = function () {
var result = [];
for ( var language in $.uls.data.languages ) {
if ( typeof $.uls.data.autonym( language ) !== 'string' ) {
result.push( language );
for ( var language in $.uls.data.languages ) {
if ( typeof $.uls.data.autonym( language ) !== 'string' ) {
result.push( language );
}
}
}
return result;
};
return result;
};
test( "-- Initial check", function() {
expect( 1 );
ok( $.fn.uls, "$.fn.uls is defined" );
} );
test( "-- Initial check", function () {
expect( 1 );
ok( $.fn.uls, "$.fn.uls is defined" );
} );
test( "-- $.uls.data testing", function() {
expect( 25 );
test( "-- $.uls.data testing", function () {
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'
// group. Actually, this may become wrong some day.
deepEqual( orphanScripts(), [], 'All scripts belong to script groups.' );
deepEqual( languagesWithoutAutonym(), [], 'All languages have autonyms.' );
// This test assumes that we don't want any scripts to be in the 'Other'
// group. Actually, this may become wrong some day.
deepEqual( orphanScripts(), [], 'All scripts belong to script groups.' );
deepEqual( languagesWithoutAutonym(), [], 'All languages have autonyms.' );
strictEqual(
$.uls.data.groupOfScript( 'Beng' ),
'SouthAsian',
'Bengali script belongs to the SouthAsian group.'
);
strictEqual(
$.uls.data.scriptGroupOfLanguage( 'iu' ),
'NativeAmerican',
'The script of the Inupiaq language belongs to the NativeAmerican group.'
);
strictEqual(
$.uls.data.groupOfScript( 'Beng' ),
'SouthAsian',
'Bengali script belongs to the SouthAsian group.'
);
strictEqual(
$.uls.data.scriptGroupOfLanguage( 'iu' ),
'NativeAmerican',
'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' );
deepEqual( $.uls.data.regions( 'lzz' ), [ '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'" );
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' );
strictEqual( $.uls.data.regions( 'no-such-language' ), 'UNKNOWN', "The region of an invalid language is 'UNKNOWN'" );
var allLanguagesByRegionAndScript = $.uls.data.allLanguagesByRegionAndScript();
deepEqual( allLanguagesByRegionAndScript['4']['AS']['SouthEastAsian']['Bugi'], ['bug'], 'All languages in the Buginese script in Asia were selected' );
var allLanguagesByRegionAndScript = $.uls.data.allLanguagesByRegionAndScript();
deepEqual( allLanguagesByRegionAndScript['4']['AS']['SouthEastAsian']['Bugi'], [
'bug'
], 'All languages in the Buginese script in Asia were selected' );
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",
"to", "tpi", "ty", "wls"],
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",
"to", "tpi", "ty", "wls"
],
"languages of region PA are selected correctly" );
deepEqual( $.uls.data.languagesInRegions( ["AM", "WW"] ),
[
"akz", "arn", "aro", "ase", "avk", "ay", "cho", "chr", "chy", "cr-cans", "cr-latn", "cr",
"en-ca", "en", "eo", "es-419", "es-formal", "es", "esu", "fr",
"gcf", "gn", "guc", "haw", "ht", "ia", "ie", "ik", "ike-cans", "ike-latn", "io", "iu",
"jam", "jbo", "kgp", "kl", "lad", "lfn", "mfe", "mic", "mus", "nah", "nl-informal", "nl", "nov", "nv",
"pap", "pdc", "pdt", "ppl", "pt-br", "pt", "qu", "qug", "rap", "sei", "simple", "srn", "tokipona",
"vo", "yi", "yrl", "yua"
],
"languages of regions AM and WW are selected correctly"
);
deepEqual( $.uls.data.languagesInRegions( ["AM", "WW"] ),
[
"akz", "arn", "aro", "ase", "avk", "ay", "cho", "chr", "chy", "cr-cans", "cr-latn",
"cr", "en-ca", "en", "eo", "es-419", "es-formal", "es", "esu", "fr", "gcf", "gn",
"guc", "haw", "ht", "ia", "ie", "ik", "ike-cans", "ike-latn", "io", "iu", "jam",
"jbo", "kgp", "kl", "lad", "lfn", "mfe", "mic", "mus", "nah", "nl-informal", "nl",
"nov", "nv", "pap", "pdc", "pdt", "ppl", "pt-br", "pt", "qu", "qug", "rap", "sei",
"simple", "srn", "tokipona", "vo", "yi", "yrl", "yua"
],
"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.languagesInScripts( ['Geor', 'Armn'] ),
["hy", "ka", "xmf"],
"languages in scripts Geor and Armn are selected correctly"
);
deepEqual( $.uls.data.languagesInScript( 'Knda' ), [
"kn", "tcy"
], "languages in script Knda 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( 2 ), ["AM"], "regions in group 2 are selected correctly" );
deepEqual( $.uls.data.regionsInGroup( 1 ), ["WW"], "regions in group 1 are selected correctly" );
deepEqual( $.uls.data.regionsInGroup( 3 ), [
"EU", "ME", "AF"
], "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" );
deepEqual( languagesByScriptInAM['Cans'], ["cr-cans", "cr", "ike-cans", "iu"], "correct languages in Cans in AM selected" );
var languagesByScriptInAM = $.uls.data.languagesByScriptInRegion( "AM" );
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 ) );
deepEqual( languagesByScriptGroupInEMEA['WestCaucasian'], ['hy', 'ka', 'xmf'], 'Correct languages in WestCaucasian script group in EMEA selected' );
var languagesByScriptGroupInEMEA = $.uls.data.languagesByScriptGroupInRegions( $.uls.data.regionsInGroup( 3 ) );
deepEqual( languagesByScriptGroupInEMEA['WestCaucasian'], [
'hy', 'ka', 'xmf'
], 'Correct languages in WestCaucasian script group in EMEA selected' );
var allLanguagesByScriptGroup = $.uls.data.allLanguagesByScriptGroup();
deepEqual( allLanguagesByScriptGroup['Greek'], ['el', 'grc', 'pnt', 'ruq-grek', 'tsd'], 'All languages in the Greek script found' );
var allLanguagesByScriptGroup = $.uls.data.allLanguagesByScriptGroup();
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
deepEqual( ['de', 'fi', 'gn', 'hu'].sort( $.uls.data.sortByAutonym ), ['gn', 'de', 'hu', 'fi'], 'Languages are correctly sorted by autonym' );
// 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' );
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( "te" ), false, "Telugu language is not 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>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta charset="utf-8"/>
<!-- Always force latest IE rendering engine (even in intranet) & Chrome Frame
Remove this if you use the .htaccess -->
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
<!-- Always force latest IE rendering engine (even in intranet) & Chrome Frame
Remove this if you use the .htaccess -->
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"/>
<title>jQuery WebFonts Example</title>
<meta name="description" content="" />
<meta name="author" content="Santhosh Thottingal" />
<!-- 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="apple-touch-icon" href="/apple-touch-icon.png" />
<script src="../lib/jquery.uls/examples/resources/jquery.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.utils.js"></script>
<script src="../resources/js/ext.uls.webfonts.repository.js"></script>
<script>
$( document ).ready(
function() {
$( 'div#webfonts-preview-area' ).webfonts( {
repository : $.webfonts.repository
} );
// get an instance of WebFonts
var $webfonts = $( 'div#webfonts-preview-area' ).data(
'webfonts' );
// Get a list of all fonts provided by WebFonts
var fonts = $webfonts.list();
var languages = $webfonts.languages();
// Also test system fonts.
var $fontSelector = $( 'select#fontselector' );
var $langselector = $( 'select#language' );
<title>jQuery WebFonts Example</title>
<meta name="description" content=""/>
<meta name="author" content="Santhosh Thottingal"/>
<!-- 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="apple-touch-icon" href="/apple-touch-icon.png"/>
<script src="../lib/jquery.uls/examples/resources/jquery.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.utils.js"></script>
<script src="../resources/js/ext.uls.webfonts.repository.js"></script>
<script>
$( document ).ready(
function () {
$( 'div#webfonts-preview-area' ).webfonts( {
repository: $.webfonts.repository
} );
// get an instance of WebFonts
var $webfonts = $( 'div#webfonts-preview-area' ).data(
'webfonts' );
// Get a list of all fonts provided by WebFonts
var fonts = $webfonts.list();
var languages = $webfonts.languages();
// Also test system fonts.
var $fontSelector = $( 'select#fontselector' );
var $langselector = $( 'select#language' );
function listFonts(fonts) {
$.merge( fonts, [ 'Sans', 'Serif' ] );
$fontSelector.find('option').remove();
$.each( fonts, function(key, font) {
$fontSelector.append( $( "<option></option>" ).attr(
"value", font ).text( font ) );
} );
$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;
}
function listFonts ( fonts ) {
$.merge( fonts, ['Sans', 'Serif'] );
$fontSelector.find( 'option' ).remove();
$.each( fonts, function ( key, font ) {
$fontSelector.append( $( "<option></option>" ).attr(
"value", font ).text( font ) );
} );
$fontSelector.trigger( 'change' );
}
div#webfonts-preview-area {
border: 1px solid #CCCCCC;
border-radius: 0 0 4px 4px;
height: 150px;
langselector line-height: 1.5em;
overflow: auto;
padding: 10px 5px;
text-align: left;
font-size: 16px;
}
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;
}
select {
width: 200px;
height: 25px;
}
div#webfonts-preview-area {
border: 1px solid #CCCCCC;
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 {
float: left;
display: block;
}
</style>
select {
width: 200px;
height: 25px;
}
.langselector, .fontselector {
float: left;
display: block;
}
</style>
</head>
<body>
<div>
<header>
<h1>jQuery WebFonts example</h1>
</header>
<div id='container'>
<div id="webfonts-preview-toolbar">
<div class='langselector'>
Language: <select name="language" id="language">
</select>
</div>
<div class='fontselector'>
Font : <select id="fontselector"></select>
</div>
</div>
<div contenteditable="true" id="webfonts-preview-area">The quick brown fox jumps over the
lazy dog</div>
</div>
</div>
<div>
<header>
<h1>jQuery WebFonts example</h1>
</header>
<div id='container'>
<div id="webfonts-preview-toolbar">
<div class='langselector'>
Language: <select name="language" id="language">
</select>
</div>
<div class='fontselector'>
Font : <select id="fontselector"></select>
</div>
</div>
<div contenteditable="true" id="webfonts-preview-area">The quick brown fox jumps over the
lazy dog
</div>
</div>
</div>
</body>
</html>