1/* 2 * jQuery.fontselect - A font selector for the Google Web Fonts api 3 * Tom Moor, http://tommoor.com 4 * Copyright (c) 2011 Tom Moor 5 * MIT Licensed 6 * @version 0.1 7*/ 8 9(function($){ 10 11 $.fn.fontselect = function(options) { 12 13 var __bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; }; 14 15 var fonts = [ 16 "Aclonica", 17 "Allan", 18 "Annie+Use+Your+Telescope", 19 "Anonymous+Pro", 20 "Allerta+Stencil", 21 "Allerta", 22 "Amaranth", 23 "Anton", 24 "Architects+Daughter", 25 "Arimo", 26 "Artifika", 27 "Arvo", 28 "Asset", 29 "Astloch", 30 "Bangers", 31 "Bentham", 32 "Bevan", 33 "Bigshot+One", 34 "Bowlby+One", 35 "Bowlby+One+SC", 36 "Brawler", 37 "Buda:300", 38 "Cabin", 39 "Calligraffitti", 40 "Candal", 41 "Cantarell", 42 "Cardo", 43 "Carter One", 44 "Caudex", 45 "Cedarville+Cursive", 46 "Cherry+Cream+Soda", 47 "Chewy", 48 "Coda", 49 "Coming+Soon", 50 "Copse", 51 "Corben:700", 52 "Cousine", 53 "Covered+By+Your+Grace", 54 "Crafty+Girls", 55 "Crimson+Text", 56 "Crushed", 57 "Cuprum", 58 "Damion", 59 "Dancing+Script", 60 "Dawning+of+a+New+Day", 61 "Didact+Gothic", 62 "Droid+Sans", 63 "Droid+Sans+Mono", 64 "Droid+Serif", 65 "EB+Garamond", 66 "Expletus+Sans", 67 "Fontdiner+Swanky", 68 "Forum", 69 "Francois+One", 70 "Geo", 71 "Give+You+Glory", 72 "Goblin+One", 73 "Goudy+Bookletter+1911", 74 "Gravitas+One", 75 "Gruppo", 76 "Hammersmith+One", 77 "Holtwood+One+SC", 78 "Homemade+Apple", 79 "Inconsolata", 80 "Indie+Flower", 81 "IM+Fell+DW+Pica", 82 "IM+Fell+DW+Pica+SC", 83 "IM+Fell+Double+Pica", 84 "IM+Fell+Double+Pica+SC", 85 "IM+Fell+English", 86 "IM+Fell+English+SC", 87 "IM+Fell+French+Canon", 88 "IM+Fell+French+Canon+SC", 89 "IM+Fell+Great+Primer", 90 "IM+Fell+Great+Primer+SC", 91 "Irish+Grover", 92 "Irish+Growler", 93 "Istok+Web", 94 "Josefin+Sans", 95 "Josefin+Slab", 96 "Judson", 97 "Jura", 98 "Jura:500", 99 "Jura:600", 100 "Just+Another+Hand", 101 "Just+Me+Again+Down+Here", 102 "Kameron", 103 "Kenia", 104 "Kranky", 105 "Kreon", 106 "Kristi", 107 "La+Belle+Aurore", 108 "Lato:100", 109 "Lato:100italic", 110 "Lato:300", 111 "Lato", 112 "Lato:bold", 113 "Lato:900", 114 "League+Script", 115 "Lekton", 116 "Limelight", 117 "Lobster", 118 "Lobster Two", 119 "Lora", 120 "Love+Ya+Like+A+Sister", 121 "Loved+by+the+King", 122 "Luckiest+Guy", 123 "Maiden+Orange", 124 "Mako", 125 "Maven+Pro", 126 "Maven+Pro:500", 127 "Maven+Pro:700", 128 "Maven+Pro:900", 129 "Meddon", 130 "MedievalSharp", 131 "Megrim", 132 "Merriweather", 133 "Metrophobic", 134 "Michroma", 135 "Miltonian Tattoo", 136 "Miltonian", 137 "Modern Antiqua", 138 "Monofett", 139 "Molengo", 140 "Mountains of Christmas", 141 "Muli:300", 142 "Muli", 143 "Neucha", 144 "Neuton", 145 "News+Cycle", 146 "Nixie+One", 147 "Nobile", 148 "Nova+Cut", 149 "Nova+Flat", 150 "Nova+Mono", 151 "Nova+Oval", 152 "Nova+Round", 153 "Nova+Script", 154 "Nova+Slim", 155 "Nova+Square", 156 "Nunito:light", 157 "Nunito", 158 "OFL+Sorts+Mill+Goudy+TT", 159 "Old+Standard+TT", 160 "Open+Sans:300", 161 "Open+Sans", 162 "Open+Sans:600", 163 "Open+Sans:800", 164 "Open+Sans+Condensed:300", 165 "Orbitron", 166 "Orbitron:500", 167 "Orbitron:700", 168 "Orbitron:900", 169 "Oswald", 170 "Over+the+Rainbow", 171 "Reenie+Beanie", 172 "Pacifico", 173 "Patrick+Hand", 174 "Paytone+One", 175 "Permanent+Marker", 176 "Philosopher", 177 "Play", 178 "Playfair+Display", 179 "Podkova", 180 "PT+Sans", 181 "PT+Sans+Narrow", 182 "PT+Sans+Narrow:regular,bold", 183 "PT+Serif", 184 "PT+Serif Caption", 185 "Puritan", 186 "Quattrocento", 187 "Quattrocento+Sans", 188 "Radley", 189 "Raleway:100", 190 "Redressed", 191 "Rock+Salt", 192 "Rokkitt", 193 "Ruslan+Display", 194 "Schoolbell", 195 "Shadows+Into+Light", 196 "Shanti", 197 "Sigmar+One", 198 "Six+Caps", 199 "Slackey", 200 "Smythe", 201 "Sniglet:800", 202 "Special+Elite", 203 "Stardos+Stencil", 204 "Sue+Ellen+Francisco", 205 "Sunshiney", 206 "Swanky+and+Moo+Moo", 207 "Syncopate", 208 "Tangerine", 209 "Tenor+Sans", 210 "Terminal+Dosis+Light", 211 "The+Girl+Next+Door", 212 "Tinos", 213 "Ubuntu", 214 "Ultra", 215 "Unkempt", 216 "UnifrakturCook:bold", 217 "UnifrakturMaguntia", 218 "Varela", 219 "Varela Round", 220 "Vibur", 221 "Vollkorn", 222 "VT323",
223 "Waiting+for+the+Sunrise", 224 "Wallpoet", 225 "Walter+Turncoat", 226 "Wire+One", 227 "Yanone+Kaffeesatz", 228 "Yanone+Kaffeesatz:300", 229 "Yanone+Kaffeesatz:400", 230 "Yanone+Kaffeesatz:700", 231 "Yeseva+One", 232 "Zeyada"]; 233 234 var settings = { 235 style: 'font-select', 236 placeholder: 'Select a font', 237 lookahead: 2, 238 api: '//fonts.googleapis.com/css?family=' 239 }; 240 241 var Fontselect = (function(){ 242 243 function Fontselect(original, o){ 244 this.$original = $(original); 245 this.options = o; 246 this.active = false; 247 this.setupHtml(); 248 this.getVisibleFonts(); 249 this.bindEvents(); 250 251 var font = this.$original.val(); 252 if (font) { 253 this.updateSelected(); 254 this.addFontLink(font); 255 } 256 } 257 258 Fontselect.prototype.bindEvents = function(){ 259 260 $('li', this.$results) 261 .click(__bind(this.selectFont, this)) 262 .mouseenter(__bind(this.activateFont, this)) 263 .mouseleave(__bind(this.deactivateFont, this)); 264 265 $('span', this.$select).click(__bind(this.toggleDrop, this)); 266 this.$arrow.click(__bind(this.toggleDrop, this)); 267 }; 268 269 Fontselect.prototype.toggleDrop = function(ev){ 270 271 if(this.active){ 272 this.$element.removeClass('font-select-active'); 273 this.$drop.hide(); 274 clearInterval(this.visibleInterval); 275 276 } else { 277 this.$element.addClass('font-select-active'); 278 this.$drop.show(); 279 this.moveToSelected(); 280 this.visibleInterval = setInterval(__bind(this.getVisibleFonts, this), 500); 281 } 282 283 this.active = !this.active; 284 }; 285 286 Fontselect.prototype.selectFont = function(){ 287 288 var font = $('li.active', this.$results).data('value'); 289 this.$original.val(font).change(); 290 this.updateSelected(); 291 this.toggleDrop(); 292 }; 293 294 Fontselect.prototype.moveToSelected = function(){ 295 296 var $li, font = this.$original.val(); 297 298 if (font){ 299 $li = $("li[data-value='"+ font +"']", this.$results); 300 } else { 301 $li = $("li", this.$results).first(); 302 } 303 304 this.$results.scrollTop($li.addClass('active').position().top); 305 }; 306 307 Fontselect.prototype.activateFont = function(ev){ 308 $('li.active', this.$results).removeClass('active'); 309 $(ev.currentTarget).addClass('active'); 310 }; 311 312 Fontselect.prototype.deactivateFont = function(ev){ 313 314 $(ev.currentTarget).removeClass('active'); 315 }; 316 317 Fontselect.prototype.updateSelected = function(){ 318 319 var font = this.$original.val(); 320 $('span', this.$element).text(this.toReadable(font)).css(this.toStyle(font)); 321 }; 322 323 Fontselect.prototype.setupHtml = function(){ 324 325 this.$original.empty().hide(); 326 this.$element = $('<div>', {'class': this.options.style}); 327 this.$arrow = $('<div><b></b></div>'); 328 this.$select = $('<a><span>'+ this.options.placeholder +'</span></a>'); 329 this.$drop = $('<div>', {'class': 'fs-drop'}); 330 this.$results = $('<ul>', {'class': 'fs-results'}); 331 this.$original.after(this.$element.append(this.$select.append(this.$arrow)).append(this.$drop)); 332 this.$drop.append(this.$results.append(this.fontsAsHtml())).hide(); 333 }; 334 335 Fontselect.prototype.fontsAsHtml = function(){ 336 337 var l = fonts.length; 338 var r, s, h = ''; 339 340 for(var i=0; i<l; i++){ 341 r = this.toReadable(fonts[i]); 342 s = this.toStyle(fonts[i]); 343 h += '<li data-value="'+ fonts[i] +'" style="font-family: '+s['font-family'] +'; font-weight: '+s['font-weight'] +'">'+ r +'</li>'; 344 } 345 346 return h; 347 }; 348 349 Fontselect.prototype.toReadable = function(font){ 350 return font.replace(/[\+|:]/g, ' '); 351 }; 352 353 Fontselect.prototype.toStyle = function(font){ 354 var t = font.split(':'); 355 return {'font-family': this.toReadable(t[0]), 'font-weight': (t[1] || 400)}; 356 }; 357 358 Fontselect.prototype.getVisibleFonts = function(){ 359 360 if(this.$results.is(':hidden')) return; 361 362 var fs = this; 363 var top = this.$results.scrollTop(); 364 var bottom = top + this.$results.height(); 365 366 if(this.options.lookahead){ 367 var li = $('li', this.$results).first().height();
368 bottom += li*this.options.lookahead; 369 } 370 371 $('li', this.$results).each(function(){ 372 373 var ft = $(this).position().top+top; 374 var fb = ft + $(this).height(); 375 376 if ((fb >= top) && (ft <= bottom)){ 377 var font = $(this).data('value'); 378 fs.addFontLink(font); 379 } 380 381 }); 382 }; 383 384 Fontselect.prototype.addFontLink = function(font){ 385 386 var link = this.options.api + font; 387 388 if ($("link[href*='" + font + "']").length === 0){ 389 $('link:last').after('<link href="' + link + '" rel="stylesheet" type="text/css">'); 390 } 391 }; 392 393 return Fontselect; 394 })(); 395 396 return this.each(function(options) { 397 // If options exist, lets merge them 398 if (options) $.extend( settings, options ); 399 400 return new Fontselect(this, settings); 401 }); 402 403 }; 404})(jQuery);
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.