r102766 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r102765‎ | r102766 | r102767 >
Date:09:31, 11 November 2011
Author:santhosh
Status:ok
Tags:
Comment:
Moving $.webfonts into the mw object instead of the jQuery object.
As per https://www.mediawiki.org/wiki/User:Krinkle/Extension_review/WebFonts
Modified paths:
  • /trunk/extensions/WebFonts/resources/ext.webfonts.fontlist.js (modified) (history)
  • /trunk/extensions/WebFonts/resources/ext.webfonts.js (modified) (history)

Diff [purge]

Index: trunk/extensions/WebFonts/resources/ext.webfonts.js
@@ -7,31 +7,31 @@
88 return 'webfont-' + font.toLowerCase().replace(/[_ ]/g, '-' ).replace(/[^-a-z]/g, '' );
99 }
1010
11 - $.webfonts = {
 11+ mw.webfonts = {
1212
1313 oldconfig: false,
14 - config: $.webfonts.config,
 14+ config: mw.webfonts.config,
1515 version: '0.1.2',
1616 fonts : [],
1717 set: function( font ) {
1818 if ( !font || font === 'none' ) {
19 - $.webfonts.reset();
 19+ mw.webfonts.reset();
2020 return;
2121 }
2222
23 - if ( !( font in $.webfonts.config.fonts ) ) {
 23+ if ( !( font in mw.webfonts.config.fonts ) ) {
2424 mw.log( 'Requested unknown font', font );
2525 return;
2626 }
27 - var config = $.webfonts.config.fonts[font];
 27+ var config = mw.webfonts.config.fonts[font];
2828
2929 // Load the style sheet for the font
30 - $.webfonts.addFont( font );
 30+ mw.webfonts.addFont( font );
3131
3232 // Save the current font and its size. Used for reset.
33 - if ( !$.webfonts.oldconfig ) {
 33+ if ( !mw.webfonts.oldconfig ) {
3434 var $body = $( 'body' );
35 - $.webfonts.oldconfig = {
 35+ mw.webfonts.oldconfig = {
3636 fontFamily: $body.css( 'font-family' ),
3737 fontSize: $body.css( 'font-size' )
3838 };
@@ -42,14 +42,14 @@
4343
4444 if ( 'normalization' in config ) {
4545 $( document ).ready( function() {
46 - $.webfonts.normalize( config.normalization );
 46+ mw.webfonts.normalize( config.normalization );
4747 } );
4848 }
4949 // Store the font choise in cookie
5050 $.cookie( 'webfonts-font', font, { 'path': '/', 'expires': 30 } );
5151
5252 // If we had reset the fonts for tags with lang attribute, apply the fonts again.
53 - $.webfonts.loadFontsForLangAttr();
 53+ mw.webfonts.loadFontsForLangAttr();
5454 },
5555
5656 /**
@@ -57,11 +57,11 @@
5858 */
5959 reset: function() {
6060 $( 'body' ).css( {
61 - fontFamily: $.webfonts.oldconfig.fontFamily,
62 - fontSize: $.webfonts.oldconfig.fontSize
 61+ fontFamily: mw.webfonts.oldconfig.fontFamily,
 62+ fontSize: mw.webfonts.oldconfig.fontSize
6363 });
6464 // We need to reset the font family of Input and Select explicitly.
65 - $( 'input, select' ).css( 'font-family', $.webfonts.oldconfig.fontFamily );
 65+ $( 'input, select' ).css( 'font-family', mw.webfonts.oldconfig.fontFamily );
6666
6767 // Reset the fonts applied for tags with lang attribute.
6868 $( '.webfonts-lang-attr' ).css( 'font-family', 'none' ).removeClass( 'webfonts-lang-attr' );
@@ -101,7 +101,7 @@
102102 * @param fontFamily The font-family name
103103 */
104104 loadCSS: function( fontFamily ) {
105 - var fontconfig = $.webfonts.config.fonts[fontFamily];
 105+ var fontconfig = mw.webfonts.config.fonts[fontFamily];
106106 var base = mw.config.get( 'wgExtensionAssetsPath' ) + '/WebFonts/fonts/';
107107 var fontFormats = [];
108108 var styleString =
@@ -148,11 +148,11 @@
149149 */
150150 addFont: function( fontFamilyName ) {
151151 // Avoid duplicate loading
152 - if ( $.inArray( fontFamilyName, $.webfonts.fonts ) === -1 ) {
 152+ if ( $.inArray( fontFamilyName, mw.webfonts.fonts ) === -1 ) {
153153 // Check whether the requested font is available.
154 - if ( fontFamilyName in $.webfonts.config.fonts ) {
155 - $.webfonts.loadCSS( fontFamilyName );
156 - $.webfonts.fonts.push( fontFamilyName );
 154+ if ( fontFamilyName in mw.webfonts.config.fonts ) {
 155+ mw.webfonts.loadCSS( fontFamilyName );
 156+ mw.webfonts.fonts.push( fontFamilyName );
157157 }
158158 }
159159 },
@@ -163,7 +163,7 @@
164164 */
165165 setup: function() {
166166 var config = [];
167 - var languages = $.webfonts.config.languages;
 167+ var languages = mw.webfonts.config.languages;
168168 var requested = [mw.config.get( 'wgUserVariant' ), mw.config.get( 'wgContentLanguage' ), mw.config.get( 'wgUserLanguage' )];
169169
170170 for ( var i = 0; i < requested.length; i++ ) {
@@ -178,7 +178,7 @@
179179 }
180180
181181 // Build font dropdown
182 - $.webfonts.buildMenu( config );
 182+ mw.webfonts.buildMenu( config );
183183 // See if there is a font in cookie if not first font is default font.
184184 var cookieFont = $.cookie( 'webfonts-font' );
185185 var selectedFont = null;
@@ -192,18 +192,18 @@
193193 selectedFont = config[0];
194194 }
195195 if ( selectedFont && selectedFont !== 'none' ) {
196 - $.webfonts.set( selectedFont );
 196+ mw.webfonts.set( selectedFont );
197197 // Mark it as checked
198198 $( '#'+fontID( selectedFont ) ).prop( 'checked', true );
199199 }
200200
201 - $.webfonts.loadFontsForFontFamilyStyle();
202 - $.webfonts.loadFontsForLangAttr();
 201+ mw.webfonts.loadFontsForFontFamilyStyle();
 202+ mw.webfonts.loadFontsForLangAttr();
203203
204204 if ( $( '.webfonts-lang-attr' ).length && !$( '#webfonts-fontsmenu' ).length ) {
205205 // We need to show the reset option even if there is no font to show
206206 // for the language, if there is lang attr based font embedding.
207 - $.webfonts.buildMenu( config );
 207+ mw.webfonts.buildMenu( config );
208208 }
209209 },
210210
@@ -212,13 +212,13 @@
213213 * for that language if available.
214214 */
215215 loadFontsForLangAttr: function() {
216 - var languages = $.webfonts.config.languages;
 216+ var languages = mw.webfonts.config.languages;
217217 // If there are tags with lang attribute,
218218 $( 'body' ).find( '*[lang]' ).each( function( index ) {
219219 // .. check the availability of font, add a font-family style if it does not have any
220220 if( languages[this.lang] && ( !this.style.fontFamily || this.style.fontFamily === 'none' ) ) {
221221 fontFamily = languages[this.lang][0];
222 - $.webfonts.addFont( fontFamily );
 222+ mw.webfonts.addFont( fontFamily );
223223 $(this).css( 'font-family', fontFamily ).addClass( 'webfonts-lang-attr' );
224224 }
225225 });
@@ -230,7 +230,7 @@
231231 * If that font is available, embed it.
232232 */
233233 loadFontsForFontFamilyStyle: function() {
234 - var languages = $.webfonts.config.languages;
 234+ var languages = mw.webfonts.config.languages;
235235 // If there are tags with font-family style definition, get a list of fonts to be loaded
236236 $( 'body' ).find( '*[style]' ).each( function( index ) {
237237 if( this.style.fontFamily ) {
@@ -238,7 +238,7 @@
239239 $.each( fontFamilyItems, function( index, fontFamily ) {
240240 // Remove the ' characters if any.
241241 fontFamily = fontFamily.replace( /'/g, '' );
242 - $.webfonts.addFont( fontFamily );
 242+ mw.webfonts.addFont( fontFamily );
243243 });
244244 }
245245 });
@@ -254,7 +254,7 @@
255255 // Build font dropdown
256256 var $fontsMenu = $( '<ul>' ).attr( 'id', 'webfonts-fontsmenu' );
257257 $fontsMenu.delegate( 'input:radio', 'change', function( e ) {
258 - $.webfonts.set( $(this).val() );
 258+ mw.webfonts.set( $(this).val() );
259259 } );
260260 for ( var scheme in config ) {
261261 var $fontLink = $( '<input type="radio" />' )
@@ -288,7 +288,7 @@
289289 .attr( 'value', 'webfont-none' )
290290 .attr( 'id', 'webfont-none' )
291291 .click( function( e ) {
292 - $.webfonts.set( 'none' );
 292+ mw.webfonts.set( 'none' );
293293 });
294294
295295 var $resetLabel = $( '<label>' )
@@ -336,7 +336,7 @@
337337 };
338338
339339 $( document ).ready( function() {
340 - $.webfonts.setup();
 340+ mw.webfonts.setup();
341341 } );
342342
343343 } ) ( jQuery );
Index: trunk/extensions/WebFonts/resources/ext.webfonts.fontlist.js
@@ -4,9 +4,9 @@
55 */
66
77 ( function ( $ ) {
8 - $.webfonts = {};
 8+ mw.webfonts = {};
99
10 - $.webfonts.config = {
 10+ mw.webfonts.config = {
1111 fonts: {
1212 RufScript: {
1313 eot: "Latn/Rufscript.eot",

Status & tagging log