r102754 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r102753‎ | r102754 | r102755 >
Date:05:15, 11 November 2011
Author:santhosh
Status:resolved
Tags:
Comment:
Better the css construction using array of fontformats and then joining.
Add the css using mw.util.addCSS, also adding mediawiki.util as dependency.
Modified paths:
  • /trunk/extensions/WebFonts/WebFonts.php (modified) (history)
  • /trunk/extensions/WebFonts/resources/ext.webfonts.js (modified) (history)

Diff [purge]

Index: trunk/extensions/WebFonts/resources/ext.webfonts.js
@@ -103,8 +103,9 @@
104104 loadCSS: function( fontFamily ) {
105105 var fontconfig = $.webfonts.config.fonts[fontFamily];
106106 var base = mw.config.get( 'wgExtensionAssetsPath' ) + '/WebFonts/fonts/';
 107+ var fontFormats = [];
107108 var styleString =
108 - "<style type='text/css'>\n@font-face {\n"
 109+ "@font-face {\n"
109110 + "\tfont-family: '"+fontFamily+"';\n";
110111
111112 if ( 'eot' in fontconfig ) {
@@ -121,22 +122,22 @@
122123 }
123124
124125 if ( 'woff' in fontconfig ) {
125 - styleString += "\t\turl('"+base+fontconfig.woff+"') format('woff'),";
 126+ fontFormats.push( "\t\turl('"+base+fontconfig.woff+"') format('woff')" );
126127 }
127128
128129 if ( 'svg' in fontconfig ) {
129 - styleString += "\t\turl('"+base+fontconfig.svg+"#"+fontFamily+"') format('svg'),";
 130+ fontFormats.push( "\t\turl('"+base+fontconfig.svg+"#"+fontFamily+"') format('svg')" );
130131 }
131132
132133 if ( 'ttf' in fontconfig ) {
133 - styleString += "\t\turl('"+base+fontconfig.ttf+"') format('truetype');\n";
 134+ fontFormats.push( "\t\turl('"+base+fontconfig.ttf+"') format('truetype')" );
134135 }
 136+
 137+ styleString += fontFormats.join() + ";\n"
 138+ styleString += "\tfont-weight: normal;\n}\n";
135139
136 - styleString += "\tfont-weight: normal;\n}\n</style>\n";
137 -
138140 //inject the css to the head of the page.
139 - $( styleString ).appendTo( 'head' );
140 -
 141+ mw.util.addCSS( styleString );
141142 },
142143
143144 /**
Index: trunk/extensions/WebFonts/WebFonts.php
@@ -46,7 +46,7 @@
4747 'localBasePath' => $dir,
4848 'remoteExtPath' => 'WebFonts',
4949 'messages' => array( 'webfonts-load', 'webfonts-reset' ),
50 - 'dependencies' => array( 'jquery.cookie', 'ext.webfonts.fontlist'),
 50+ 'dependencies' => array( 'mediawiki.util', 'jquery.cookie', 'ext.webfonts.fontlist'),
5151 );
5252
5353 $wgResourceModules['ext.webfonts.fontlist'] = array(

Follow-up revisions

RevisionCommit summaryAuthorDate
r102759mw.util.addCSS will not work for IE if the css is font-face style. IE crashes....santhosh07:21, 11 November 2011

Status & tagging log