Santhosh has uploaded a new change for review. https://gerrit.wikimedia.org/r/125701
Change subject: Update jquery.webfonts to 372aad1 ...................................................................... Update jquery.webfonts to 372aad1 Introduce overridable font family option Font stacks given in overridableFontFamilies will be overridden as as exception to the general policy of not altering elements with explicit font family styles Change-Id: I579c3ccb6e0c1ad39d434651a4689e8c595e5a84 --- A lib/jquery.i18n/.directory A lib/jquery.uls/src/.directory M lib/jquery.webfonts.js 3 files changed, 64 insertions(+), 19 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/UniversalLanguageSelector refs/changes/01/125701/1 diff --git a/lib/jquery.i18n/.directory b/lib/jquery.i18n/.directory new file mode 100644 index 0000000..03e1705 --- /dev/null +++ b/lib/jquery.i18n/.directory @@ -0,0 +1,6 @@ +[Dolphin] +SortOrder=1 +SortRole=size +Timestamp=2014,1,23,2,41,46 +Version=3 +ViewMode=1 diff --git a/lib/jquery.uls/src/.directory b/lib/jquery.uls/src/.directory new file mode 100644 index 0000000..2318bfc --- /dev/null +++ b/lib/jquery.uls/src/.directory @@ -0,0 +1,4 @@ +[Dolphin] +Timestamp=2013,11,25,9,40,39 +Version=3 +VisibleRoles=Icons_text,Icons_size,Icons_date diff --git a/lib/jquery.webfonts.js b/lib/jquery.webfonts.js index acacaa6..1fb59d4 100644 --- a/lib/jquery.webfonts.js +++ b/lib/jquery.webfonts.js @@ -174,8 +174,7 @@ * different language than what the element itself has. */ parse: function() { - var append, - webfonts = this, + var webfonts = this, // Fonts can be added indirectly via classes, but also with // style attributes. For lang attributes we will use our font // if they don't have explicit font already. @@ -186,12 +185,18 @@ // Object keys are the font family, values are list of plain elements. elementQueue = {}; - // Append function that keeps the array as a set (no dupes) - append = function( array, value ) { - if ( $.inArray( value, array ) < 0 ) { - array.push( value ); + // Add to the font queue(no dupes) + function addToFontQueue( value ) { + if ( $.inArray( value, fontQueue ) < 0 ) { + fontQueue.push( value ); } - }; + } + + // Add to the font queue + function addToElementQueue( element, fontFamily ) { + elementQueue[fontFamily] = elementQueue[fontFamily] || []; + elementQueue[fontFamily].push( element ); + } $elements.each( function( i, element ) { var fontFamilyStyle, fontFamily, @@ -207,18 +212,28 @@ // Note: It is unclear whether this can ever be falsy. Maybe also // browser specific. if ( fontFamilyStyle ) { - fontFamily = fontFamilyStyle.split( ',' )[0]; - - // Remove the ' and " characters if any. - fontFamily = $.trim( fontFamily.replace( /["']/g, '' ) ); - - append( fontQueue, fontFamily ); + // if it is overridable, override. always. + if ( webfonts.isOverridable( fontFamilyStyle ) ) { + fontFamily = webfonts.getFont( element.lang || webfonts.language ); + // We do not have fonts for all languages + if ( fontFamily ) { + addToFontQueue( fontFamily ); + addToElementQueue( element, fontFamily ); + } + return; + } else { + fontFamily = fontFamilyStyle.split( ',' )[0]; + // Remove the ' and " characters if any. + fontFamily = $.trim( fontFamily.replace( /["']/g, '' ) ); + addToFontQueue( fontFamily ); + } } // Load and apply fonts for other language tagged elements (batched) if ( element.lang && element.lang !== webfonts.language ) { // language differs. We may want to apply a different font. - if ( webfonts.hasExplicitFontStyle ( $element ) ) { + if ( webfonts.hasExplicitFontStyle ( $element ) && + !webfonts.isOverridable( fontFamilyStyle ) ) { // respect the explicit font family style. Do not override. // This style may be from css, inheritance, or even from // browser settings. @@ -246,9 +261,8 @@ // We do not have fonts for all languages if ( fontFamily ) { - append( fontQueue, fontFamily ); - elementQueue[fontFamily] = elementQueue[fontFamily] || []; - elementQueue[fontFamily].push( element ); + addToFontQueue( fontFamily ); + addToElementQueue( element, fontFamily ); } } } ); @@ -275,7 +289,27 @@ return this.$element.css( 'fontFamily' ) !== elementFontFamily // whether the element has generic font family && ( $.inArray( elementFontFamily, - ['monospace', 'serif', 'cursive','fantasy', 'sans-serif'] ) < 0 ); + [ 'monospace', 'serif', 'cursive', 'fantasy', 'sans-serif' ] ) < 0 ); + }, + + /** + * Check whether the give font family is overridable or not. jquey.webfonts + * by default does not override any font-family styles other than generic + * font family styles(See hasExplicitFontStyle method) + * @param {string} fontFamily + * @return {boolean} Whether the given fontFamily is overridable or not. + */ + isOverridable: function( fontFamily ) { + var overridableFontFamilies = [ 'monospace', 'serif', 'cursive', 'fantasy', 'sans-serif' ]; + $.merge( overridableFontFamilies, this.options.overridableFontFamilies ); + // Browsers like FF put space after comma in font stack. Chrome does not. + // Normalise it by removing the spaces and quotes + overridableFontFamilies = $.map( overridableFontFamilies, function( item ) { + return item.replace( /[\s'"]/g, '' ); + } ); + fontFamily = fontFamily.replace( /[\s'"]/g, '' ); + console.log(fontFamily+':'+overridableFontFamilies); + return $.inArray( fontFamily, overridableFontFamilies ) >= 0; }, /** @@ -448,7 +482,8 @@ $.fn.webfonts.defaults = { repository: WebFonts.repository, // Default font repository fontStack: [ 'Helvetica', 'Arial', 'sans-serif' ], // Default font fallback - exclude: '' // jQuery selectors to exclude + exclude: '', // jQuery selectors to exclude + overridableFontFamilies: [] }; $.fn.webfonts.Constructor = WebFonts; -- To view, visit https://gerrit.wikimedia.org/r/125701 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I579c3ccb6e0c1ad39d434651a4689e8c595e5a84 Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/UniversalLanguageSelector Gerrit-Branch: master Gerrit-Owner: Santhosh <santhosh.thottin...@gmail.com> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits