' ).addClass( 'uls-lcd-region-section' ).prop( 'id', regionCode );
+ $section.append( $( '
' ).html( regionCode ) );
+ // FIXME this is regioncode(NA, EU etc). Should be Proper localized region name.
+ $section.append( $( '' ) );
+ that.$element.append( $section );
+ } );
+ },
+
+ empty: function() {
+ this.$element.find( 'div ul' ).remove();
+ this.$element.find( 'div' ).hide();
+ },
+
+ listen: function(){
+ this.$element.scroll( function() {
+ var inviewRegion = $( 'div.uls-lcd-region-section:in-viewport:first' ).attr( 'id' );
+ var inview = $.uls.data.regiongroups[inviewRegion];
+ $( 'div.uls-region' ).removeClass( 'active' );
+ $( 'div#uls-region-' + inview).addClass( 'active' );
+ });
+ }
+
+ };
+
+ $.fn.lcd = function( option ) {
+ return this.each( function() {
+ var $this = $( this ),
+ data = $this.data( 'lcd' ),
+ options = typeof option === 'object' && option;
+
+ if ( !data ) {
+ $this.data( 'lcd', ( data = new LanguageCategoryDisplay( this, options ) ) );
+ }
+ if ( typeof option === 'string') {
+ data[option]();
+ }
+ } );
+ };
+
+ $.fn.lcd.defaults = {
+ languages: null
+ };
+
+ $.fn.lcd.Constructor = LanguageCategoryDisplay;
+
+} )( jQuery );
diff --git a/resources/jquery.viewport.js b/resources/jquery.viewport.js
new file mode 100644
index 00000000..7826000f
--- /dev/null
+++ b/resources/jquery.viewport.js
@@ -0,0 +1,58 @@
+/*
+ * Viewport - jQuery selectors for finding elements in viewport
+ *
+ * Copyright (c) 2008-2009 Mika Tuupola
+ *
+ * Licensed under the MIT license:
+ * http://www.opensource.org/licenses/mit-license.php
+ *
+ * Project home:
+ * http://www.appelsiini.net/projects/viewport
+ *
+ */
+(function($) {
+
+ $.belowthefold = function(element, settings) {
+ var fold = $(window).height() + $(window).scrollTop();
+ return fold <= $(element).offset().top - settings.threshold;
+ };
+
+ $.abovethetop = function(element, settings) {
+ var top = $(window).scrollTop();
+ return top >= $(element).offset().top + $(element).height() - settings.threshold;
+ };
+
+ $.rightofscreen = function(element, settings) {
+ var fold = $(window).width() + $(window).scrollLeft();
+ return fold <= $(element).offset().left - settings.threshold;
+ };
+
+ $.leftofscreen = function(element, settings) {
+ var left = $(window).scrollLeft();
+ return left >= $(element).offset().left + $(element).width() - settings.threshold;
+ };
+
+ $.inviewport = function(element, settings) {
+ return !$.rightofscreen(element, settings) && !$.leftofscreen(element, settings) && !$.belowthefold(element, settings) && !$.abovethetop(element, settings);
+ };
+
+ $.extend($.expr[':'], {
+ "below-the-fold": function(a, i, m) {
+ return $.belowthefold(a, {threshold : 0});
+ },
+ "above-the-top": function(a, i, m) {
+ return $.abovethetop(a, {threshold : 0});
+ },
+ "left-of-screen": function(a, i, m) {
+ return $.leftofscreen(a, {threshold : 0});
+ },
+ "right-of-screen": function(a, i, m) {
+ return $.rightofscreen(a, {threshold : 0});
+ },
+ "in-viewport": function(a, i, m) {
+ return $.inviewport(a, {threshold : 0});
+ }
+ });
+
+
+})(jQuery);
diff --git a/tests/qunit/ext.uls.tests.js b/tests/qunit/ext.uls.tests.js
index c803938f..811fd511 100644
--- a/tests/qunit/ext.uls.tests.js
+++ b/tests/qunit/ext.uls.tests.js
@@ -23,7 +23,7 @@ var orphanScript = function () {
}
return '';
-}
+};
test( "-- Initial check", function() {
expect( 1 );
@@ -31,10 +31,15 @@ test( "-- Initial check", function() {
} );
test( "-- $.uls.data testing", function() {
- expect( 8 );
+ expect( 12 );
- // Unless we actually want some scripts to be in the 'Other' group.
+ // This test assumes that we don't want any scripts to be in the 'Other'
+ // group. Actually, this may become wrong some day.
strictEqual( orphanScript(), '', 'No orphan scripts found.' );
+ strictEqual( $.uls.data.groupOfScript( 'Beng' ), 'SouthAsian', 'Bengali script belongs to the SouthAsian 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' );
deepEqual( $.uls.data.languagesInRegion( 'AU' ), ["en", "en-gb", "hif", "hif-latn", "mi", "na"], "languages of region AU are selected correctly" );
deepEqual( $.uls.data.languagesInRegions( ['NA', 'WW'] ),
@@ -42,8 +47,8 @@ test( "-- $.uls.data testing", function() {
"avk", "cho", "chr", "chy", "cr", "en", "en-ca", "eo", "es",
"haw", "ht", "ia", "ie", "ik", "ike-cans", "ike-latn", "io",
"iu", "jam", "jbo", "kl", "lfn", "mus", "nah", "nov", "nv",
- "pdc", "pdt", "rue", "sei", "simple", "srn", "tokipona",
- "uk", "vo", "yi"
+ "pdc", "pdt", "sei", "simple", "srn", "tokipona",
+ "vo", "yi"
],
"languages of regions NA and WW are selected correctly"
);
@@ -59,6 +64,8 @@ test( "-- $.uls.data testing", function() {
languagesByScriptInNA = $.uls.data.languagesByScriptInRegion( 'NA' );
deepEqual( languagesByScriptInNA['Cans'], ["cr", "ike-cans", "iu"], "correct languages in Cans in NA selected" );
+
+ strictEqual( $.uls.data.autonym( 'pa' ), 'ਪੰਜਾਬੀ', 'Correct autonym of the Punjabi language was selected' );
} );
}() );