r95858 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r95857‎ | r95858 | r95859 >
Date:12:30, 31 August 2011
Author:dantman
Status:ok
Tags:
Comment:
Use a fontID function that cleans up font names into a format that is acceptable to be located in an id="". Previously fonts with spaces would have spaces in the id resulting in jQuery selects that had a space breaking the select and not checking off the radio button.
Modified paths:
  • /trunk/extensions/WebFonts/js/webfonts.js (modified) (history)

Diff [purge]

Index: trunk/extensions/WebFonts/js/webfonts.js
@@ -1,5 +1,12 @@
22 (function($){
33
 4+ function fontID(font) {
 5+ if ( typeof font !== 'string' ) {
 6+ return font;
 7+ }
 8+ return "webfont-"+font.toLowerCase().replace(/[_ ]/g, '-').replace(/[^-a-z]/g, '');
 9+ }
 10+
411 $.webfonts = {
512
613 oldconfig: false,
@@ -163,7 +170,7 @@
164171 if (cookie_font && cookie_font !== 'none') {
165172 $.webfonts.set(cookie_font);
166173 //mark it as checked
167 - $('#webfont-'+cookie_font).attr('checked', 'checked');
 174+ $('#'+fontID(cookie_font)).attr('checked', 'checked');
168175 }
169176
170177 //if there are tags with font-family style definition, get a list of fonts to be loaded
@@ -197,11 +204,11 @@
198205 });
199206 for ( var scheme in config ) {
200207 var $fontLink = $( '<input type="radio" name="font" />' )
201 - .attr("id","webfont-"+config[scheme])
 208+ .attr("id",fontID(config[scheme]))
202209 .val( config[scheme] );
203210
204211 var $fontLabel = $( '<label />' )
205 - .attr("for","webfont-"+config[scheme])
 212+ .attr("for",fontID(config[scheme]))
206213 .append( $fontLink )
207214 .append( config[scheme] );
208215

Status & tagging log