', {'id': 'fontSelect-'+this.$original.id, 'class': this.options.style});
this.$arrow = $('
');
this.$select = $('
'+ this.options.placeholder +'');
this.$drop = $('
', {'class': 'fs-drop'});
this.$results = $('
', {'class': 'fs-results'});
this.$original.after(this.$element.append(this.$select.append(this.$arrow)).append(this.$drop));
this.$drop.append(this.$results.append(this.fontsAsHtml())).hide();
};
Fontselect.prototype.fontsAsHtml = function(){
var l = this.options.fonts.length;
var r, s, h = '';
for(var i=0; i'+ r +'';
}
return h;
};
Fontselect.prototype.toReadable = function(font){
return font.replace(/[\+|:]/g, ' ');
};
Fontselect.prototype.toStyle = function(font){
var t = font.split(':');
return {'font-family': this.toReadable(t[0]), 'font-weight': (t[1] || 400)};
};
Fontselect.prototype.getVisibleFonts = function(){
if(this.$results.is(':hidden')) return;
var fs = this;
var top = this.$results.scrollTop();
var bottom = top + this.$results.height();
if(this.options.lookahead){
var li = $('li', this.$results).first().height();
bottom += li*this.options.lookahead;
}
$('li', this.$results).each(function(){
var ft = $(this).position().top+top;
var fb = ft + $(this).height();
if ((fb >= top) && (ft <= bottom)){
var font = $(this).data('value');
fs.addFontLink(font);
}
});
};
Fontselect.prototype.addFontLink = function(font){
var link = this.options.api + font;
if ($("link[href*='" + font + "']").length === 0){
$('link:last').after('');
}
};
return Fontselect;
})();
return this.each(function() {
// If options exist, lets merge them
if (options) $.extend( settings, options );
return new Fontselect(this, settings);
});
};
})(jQuery);