http://www.mediawiki.org/wiki/Special:Code/MediaWiki/95835
Revision: 95835
Author: santhosh
Date: 2011-08-31 06:37:51 +0000 (Wed, 31 Aug 2011)
Log Message:
-----------
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: trunk/extensions/WebFonts/js/webfonts.js
===================================================================
--- trunk/extensions/WebFonts/js/webfonts.js 2011-08-31 05:43:53 UTC (rev
95834)
+++ trunk/extensions/WebFonts/js/webfonts.js 2011-08-31 06:37:51 UTC (rev
95835)
@@ -191,46 +191,65 @@
$fontsmenu.append($resetlinkitem);
- if ( !haveSchemes ) {
- // No schemes available, don't show the tool
- return;
- }
+ if (haveSchemes ) {
- var $menudiv = $( '<div />'
).attr('id','webfonts-fonts')
- .addClass( 'menu' )
- .append( $fontsmenu )
- .append();
+ var $menudiv = $( '<div />'
).attr('id','webfonts-fonts')
+ .addClass( 'menu' )
+ .append( $fontsmenu )
+ .append();
- var $div = $( '<div />' ).attr('id','webfonts-menu')
- .addClass( 'webfontMenu' )
- .append( "<a href='#'>"+ mw.msg("webfonts-load")+"</a>")
- .append( $menudiv );
+ var $div = $( '<div />'
).attr('id','webfonts-menu')
+ .addClass( 'webfontMenu' )
+ .append( "<a href='#'>"+
mw.msg("webfonts-load")+"</a>")
+ .append( $menudiv );
- //this is the fonts link
- var $li = $( '<li />' ).attr('id','pt-webfont')
- .append( $div );
+ //this is the fonts link
+ var $li = $( '<li />' ).attr('id','pt-webfont')
+ .append( $div );
- //if rtl, add to the right of top personal links. Else,
to the left
- if($('body').hasClass('rtl')){
- $($('#p-personal ul')[0]).append( $li );
- }
- else{
- $($('#p-personal ul')[0]).prepend( $li );
- }
- //see if there is a font in cookie
- cookie_font = $.cookie('webfonts-font');
- if(cookie_font == null){
- $.webfonts.set( config[0]);
- //mark it as checked
- $('#webfont-'+config[0]).attr('checked',
'checked');
- }
- else{
- if (cookie_font !=='none'){
- $.webfonts.set( cookie_font);
+ //if rtl, add to the right of top personal
links. Else, to the left
+ if($('body').hasClass('rtl')){
+ $($('#p-personal ul')[0]).append( $li );
+ }
+ else{
+ $($('#p-personal ul')[0]).prepend( $li
);
+ }
+ //see if there is a font in cookie
+ cookie_font = $.cookie('webfonts-font');
+ if(cookie_font == null){
+ $.webfonts.set( config[0]);
//mark it as checked
-
$('#webfont-'+cookie_font).attr('checked', 'checked');
+
$('#webfont-'+config[0]).attr('checked', 'checked');
}
- }
+ else{
+ if (cookie_font !=='none'){
+ $.webfonts.set( cookie_font);
+ //mark it as checked
+
$('#webfont-'+cookie_font).attr('checked', 'checked');
+ }
+ }
+ }
+ //if there are tags with font-family style definition,
get a list of fonts to be loaded
+ var fontFamilies = new Array();
+ $('body').find('*[style]').each(function(index){
+ if( this.style.fontFamily){
+ var fontFamilyItems =
this.style.fontFamily.split(",");
+ $.each(fontFamilyItems, function(index,
value) {
+ fontFamilies.push(value );
+ });
+ }
+ });
+ //get unique list
+ fontFamilies = $.unique(fontFamilies);
+ //load css for each of the item in fontfamily list
+ $.each(fontFamilies, function(index, fontFamily) {
+ //remove the ' characters if any.
+ fontFamily = fontFamily.replace(/'/g,'');
+ if ( fontFamily in $.webfonts.config.fonts ) {
+ $.webfonts.loadcss(fontFamily);
+ }
+ });
+
}
}
_______________________________________________
MediaWiki-CVS mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs