Skip to content

Commit

Permalink
fixes #1186
Browse files Browse the repository at this point in the history
  • Loading branch information
aristath committed May 20, 2017
1 parent 3d38a75 commit 33598be
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions modules/postmessage/postmessage.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,11 +93,27 @@

cssArray[ i ] = '';
_.each( newval, function( subValueValue, subValueKey ) {

// Simple tweak for background-image properties.
if ( 'background-image' === subValueKey && 0 > subValueValue.indexOf( 'url(' ) ) {
subValueValue = 'url("' + subValueValue + '")';
}

// Dirty hack to make google-fonts work.
if ( 'font-family' === subValueKey ) {
if ( _.isUndefined( newval.variant ) ) {
newval.variant = 400;
}
jQuery( 'head' ).append( '<script>if(!_.isUndefined(WebFont)){WebFont.load({google:{families:[\'' + subValueValue + ':' + kirkiGetFontWeight( newval.variant ) + '\']}});}</script>' );
cssArray[ i ] += args.element + '{font-weight:' + kirkiGetFontWeight( newval.variant ) + '}';
}

// Tweak for variants.
if ( 'variant' === subValueKey && ! _.isUndefined( newval['font-family'] ) ) {
jQuery( 'head' ).append( '<script>if(!_.isUndefined(WebFont)){WebFont.load({google:{families:[\'' + subValueValue + ':' + kirkiGetFontWeight( newval.variant ) + '\']}});}</script>' );
cssArray[ i ] += args.element + '{font-weight:' + kirkiGetFontWeight( newval.variant ) + '}';
}

if ( ! _.isUndefined( args.choice ) ) {
if ( args.choice === subValueKey ) {
cssArray[ i ] += args.element + '{' + args.property + ':' + args.prefix + subValueValue + args.units + args.suffix + ';}';
Expand Down Expand Up @@ -147,4 +163,18 @@

});

function kirkiGetFontWeight( value ) {
var numericVal = 400,
calculated;

if ( ! _.isString( value ) ) {
return numericVal;
}
calculated = value.match( /\d/g );
if ( ! _.isObject( calculated ) ) {
return numericVal;
}
return calculated.join( '' );
}

})( jQuery );

0 comments on commit 33598be

Please sign in to comment.