r95835 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r95834‎ | r95835 | r95836 >
Date:06:37, 31 August 2011
Author:santhosh
Status:ok (Comments)
Tags:
Comment:
Add support for font-family style definition if any. Check whether the defined font is present with us, if yes, load it.
Modified paths:
  • /trunk/extensions/WebFonts/js/webfonts.js (modified) (history)

Diff [purge]

Index: trunk/extensions/WebFonts/js/webfonts.js
@@ -191,46 +191,65 @@
192192
193193 $fontsmenu.append($resetlinkitem);
194194
195 - if ( !haveSchemes ) {
196 - // No schemes available, don't show the tool
197 - return;
198 - }
 195+ if (haveSchemes ) {
199196
200 - var $menudiv = $( '<div />' ).attr('id','webfonts-fonts')
201 - .addClass( 'menu' )
202 - .append( $fontsmenu )
203 - .append();
 197+ var $menudiv = $( '<div />' ).attr('id','webfonts-fonts')
 198+ .addClass( 'menu' )
 199+ .append( $fontsmenu )
 200+ .append();
204201
205 - var $div = $( '<div />' ).attr('id','webfonts-menu')
206 - .addClass( 'webfontMenu' )
207 - .append( "<a href='#'>"+ mw.msg("webfonts-load")+"</a>")
208 - .append( $menudiv );
 202+ var $div = $( '<div />' ).attr('id','webfonts-menu')
 203+ .addClass( 'webfontMenu' )
 204+ .append( "<a href='#'>"+ mw.msg("webfonts-load")+"</a>")
 205+ .append( $menudiv );
209206
210 - //this is the fonts link
211 - var $li = $( '<li />' ).attr('id','pt-webfont')
212 - .append( $div );
 207+ //this is the fonts link
 208+ var $li = $( '<li />' ).attr('id','pt-webfont')
 209+ .append( $div );
213210
214 - //if rtl, add to the right of top personal links. Else, to the left
215 - if($('body').hasClass('rtl')){
216 - $($('#p-personal ul')[0]).append( $li );
217 - }
218 - else{
219 - $($('#p-personal ul')[0]).prepend( $li );
220 - }
221 - //see if there is a font in cookie
222 - cookie_font = $.cookie('webfonts-font');
223 - if(cookie_font == null){
224 - $.webfonts.set( config[0]);
225 - //mark it as checked
226 - $('#webfont-'+config[0]).attr('checked', 'checked');
227 - }
228 - else{
229 - if (cookie_font !=='none'){
230 - $.webfonts.set( cookie_font);
 211+ //if rtl, add to the right of top personal links. Else, to the left
 212+ if($('body').hasClass('rtl')){
 213+ $($('#p-personal ul')[0]).append( $li );
 214+ }
 215+ else{
 216+ $($('#p-personal ul')[0]).prepend( $li );
 217+ }
 218+ //see if there is a font in cookie
 219+ cookie_font = $.cookie('webfonts-font');
 220+ if(cookie_font == null){
 221+ $.webfonts.set( config[0]);
231222 //mark it as checked
232 - $('#webfont-'+cookie_font).attr('checked', 'checked');
 223+ $('#webfont-'+config[0]).attr('checked', 'checked');
233224 }
234 - }
 225+ else{
 226+ if (cookie_font !=='none'){
 227+ $.webfonts.set( cookie_font);
 228+ //mark it as checked
 229+ $('#webfont-'+cookie_font).attr('checked', 'checked');
 230+ }
 231+ }
 232+ }
 233+ //if there are tags with font-family style definition, get a list of fonts to be loaded
 234+ var fontFamilies = new Array();
 235+ $('body').find('*[style]').each(function(index){
 236+ if( this.style.fontFamily){
 237+ var fontFamilyItems = this.style.fontFamily.split(",");
 238+ $.each(fontFamilyItems, function(index, value) {
 239+ fontFamilies.push(value );
 240+ });
 241+ }
 242+ });
 243+ //get unique list
 244+ fontFamilies = $.unique(fontFamilies);
 245+ //load css for each of the item in fontfamily list
 246+ $.each(fontFamilies, function(index, fontFamily) {
 247+ //remove the ' characters if any.
 248+ fontFamily = fontFamily.replace(/'/g,'');
 249+ if ( fontFamily in $.webfonts.config.fonts ) {
 250+ $.webfonts.loadcss(fontFamily);
 251+ }
 252+ });
 253+
235254 }
236255
237256 }

Comments

#Comment by Nikerabbit (talk | contribs)   13:01, 31 August 2011

This code has been stylized in subsequent commits today.

Status & tagging log