-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathjquery.fontselect.min.js
8 lines (8 loc) · 6.61 KB
/
jquery.fontselect.min.js
1
2
3
4
5
6
7
8
/*
* jQuery.fontselect - A font selector for the Google Web Fonts api
* Tom Moor, http://tommoor.com
* Copyright (c) 2011 Tom Moor
* MIT Licensed
* @version 0.1
*/
!function(t){t.fn.fontselect=function(e){var i=function(t,e){return function(){return t.apply(e,arguments)}},o={style:"font-select",placeholder:"Select a font",lookahead:2,api:"https://fonts.googleapis.com/css?family=",fonts:["Aclonica","Allan","Annie+Use+Your+Telescope","Anonymous+Pro","Allerta+Stencil","Allerta","Amaranth","Anton","Architects+Daughter","Arimo","Artifika","Arvo","Asset","Astloch","Bangers","Bentham","Bevan","Bigshot+One","Bowlby+One","Bowlby+One+SC","Brawler","Buda:300","Cabin","Calligraffitti","Candal","Cantarell","Cardo","Carter One","Caudex","Cedarville+Cursive","Cherry+Cream+Soda","Chewy","Coda","Coming+Soon","Copse","Corben:700","Cousine","Covered+By+Your+Grace","Crafty+Girls","Crimson+Text","Crushed","Cuprum","Damion","Dancing+Script","Dawning+of+a+New+Day","Didact+Gothic","Droid+Sans","Droid+Sans+Mono","Droid+Serif","EB+Garamond","Expletus+Sans","Fontdiner+Swanky","Forum","Francois+One","Geo","Give+You+Glory","Goblin+One","Goudy+Bookletter+1911","Gravitas+One","Gruppo","Hammersmith+One","Holtwood+One+SC","Homemade+Apple","Inconsolata","Indie+Flower","IM+Fell+DW+Pica","IM+Fell+DW+Pica+SC","IM+Fell+Double+Pica","IM+Fell+Double+Pica+SC","IM+Fell+English","IM+Fell+English+SC","IM+Fell+French+Canon","IM+Fell+French+Canon+SC","IM+Fell+Great+Primer","IM+Fell+Great+Primer+SC","Irish+Grover","Irish+Growler","Istok+Web","Josefin+Sans","Josefin+Slab","Judson","Jura","Jura:500","Jura:600","Just+Another+Hand","Just+Me+Again+Down+Here","Kameron","Kenia","Kranky","Kreon","Kristi","La+Belle+Aurore","Lato:100","Lato:100italic","Lato:300","Lato","Lato:bold","Lato:900","League+Script","Lekton","Limelight","Lobster","Lobster Two","Lora","Love+Ya+Like+A+Sister","Loved+by+the+King","Luckiest+Guy","Maiden+Orange","Mako","Maven+Pro","Maven+Pro:500","Maven+Pro:700","Maven+Pro:900","Meddon","MedievalSharp","Megrim","Merriweather","Metrophobic","Michroma","Miltonian Tattoo","Miltonian","Modern Antiqua","Monofett","Molengo","Mountains of Christmas","Muli:300","Muli","Neucha","Neuton","News+Cycle","Nixie+One","Nobile","Nova+Cut","Nova+Flat","Nova+Mono","Nova+Oval","Nova+Round","Nova+Script","Nova+Slim","Nova+Square","Nunito:light","Nunito","OFL+Sorts+Mill+Goudy+TT","Old+Standard+TT","Open+Sans:300","Open+Sans","Open+Sans:600","Open+Sans:800","Open+Sans+Condensed:300","Orbitron","Orbitron:500","Orbitron:700","Orbitron:900","Oswald","Over+the+Rainbow","Reenie+Beanie","Pacifico","Patrick+Hand","Paytone+One","Permanent+Marker","Philosopher","Play","Playfair+Display","Podkova","PT+Sans","PT+Sans+Narrow","PT+Sans+Narrow:regular,bold","PT+Serif","PT+Serif Caption","Puritan","Quattrocento","Quattrocento+Sans","Radley","Raleway:100","Redressed","Rock+Salt","Rokkitt","Ruslan+Display","Schoolbell","Shadows+Into+Light","Shanti","Sigmar+One","Six+Caps","Slackey","Smythe","Sniglet:800","Special+Elite","Stardos+Stencil","Sue+Ellen+Francisco","Sunshiney","Swanky+and+Moo+Moo","Syncopate","Tangerine","Tenor+Sans","Terminal+Dosis+Light","The+Girl+Next+Door","Tinos","Ubuntu","Ultra","Unkempt","UnifrakturCook:bold","UnifrakturMaguntia","Varela","Varela Round","Vibur","Vollkorn","VT323","Waiting+for+the+Sunrise","Wallpoet","Walter+Turncoat","Wire+One","Yanone+Kaffeesatz","Yanone+Kaffeesatz:300","Yanone+Kaffeesatz:400","Yanone+Kaffeesatz:700","Yeseva+One","Zeyada"]},a=function(){function e(e,i){this.$original=t(e),this.options=i,this.active=!1,this.setupHtml(),this.getVisibleFonts(),this.bindEvents();var o=this.$original.val();o&&(this.updateSelected(),this.addFontLink(o))}return e.prototype.bindEvents=function(){var e=this;t(document).click(function(i){e.active&&!t(i.target).parents("#fontSelect-"+e.$original.id).length&&e.toggleDrop()}),t("li",this.$results).click(i(this.selectFont,this)).mouseenter(i(this.activateFont,this)).mouseleave(i(this.deactivateFont,this)),t("span",this.$select).click(i(this.toggleDrop,this)),this.$arrow.click(i(this.toggleDrop,this))},e.prototype.toggleDrop=function(t){this.active?(this.$element.removeClass("font-select-active"),this.$drop.hide(),clearInterval(this.visibleInterval)):(this.$element.addClass("font-select-active"),this.$drop.show(),this.moveToSelected(),this.visibleInterval=setInterval(i(this.getVisibleFonts,this),500)),this.active=!this.active},e.prototype.selectFont=function(){var e=t("li.active",this.$results).data("value");this.$original.val(e).change(),this.updateSelected(),this.toggleDrop()},e.prototype.moveToSelected=function(){var e,i=this.$original.val();e=i?t("li[data-value='"+i+"']",this.$results):t("li",this.$results).first(),this.$results.scrollTop(e.addClass("active")[0].offsetTop)},e.prototype.activateFont=function(e){t("li.active",this.$results).removeClass("active"),t(e.currentTarget).addClass("active")},e.prototype.deactivateFont=function(e){t(e.currentTarget).removeClass("active")},e.prototype.updateSelected=function(){var e=this.$original.val();t("span",this.$element).text(this.toReadable(e)).css(this.toStyle(e))},e.prototype.setupHtml=function(){this.$original.empty().hide(),this.$element=t("<div>",{id:"fontSelect-"+this.$original.id,class:this.options.style}),this.$arrow=t("<div><b></b></div>"),this.$select=t("<a><span>"+this.options.placeholder+"</span></a>"),this.$drop=t("<div>",{class:"fs-drop"}),this.$results=t("<ul>",{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()},e.prototype.fontsAsHtml=function(){for(var t,e,i=this.options.fonts.length,o="",a=0;a<i;a++)t=this.toReadable(this.options.fonts[a]),e=this.toStyle(this.options.fonts[a]),o+='<li data-value="'+this.options.fonts[a]+'" style="font-family: '+e["font-family"]+"; font-weight: "+e["font-weight"]+'">'+t+"</li>";return o},e.prototype.toReadable=function(t){return t.replace(/[\+|:]/g," ")},e.prototype.toStyle=function(t){var e=t.split(":");return{"font-family":this.toReadable(e[0]),"font-weight":e[1]||400}},e.prototype.getVisibleFonts=function(){if(!this.$results.is(":hidden")){var e=this,i=this.$results.scrollTop(),o=i+this.$results.height();if(this.options.lookahead){var a=t("li",this.$results).first().height();o+=a*this.options.lookahead}t("li",this.$results).each(function(){var a=t(this).position().top+i;if(a+t(this).height()>=i&&a<=o){var n=t(this).data("value");e.addFontLink(n)}})}},e.prototype.addFontLink=function(e){var i=this.options.api+e;0===t("link[href*='"+e+"']").length&&t("link:last").after('<link href="'+i+'" rel="stylesheet" type="text/css">')},e}();return this.each(function(){return e&&t.extend(o,e),new a(this,o)})}}(jQuery);