-
Notifications
You must be signed in to change notification settings - Fork 0
/
jquery.fontavailable-1.1.js
35 lines (29 loc) · 1.04 KB
/
jquery.fontavailable-1.1.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
/* fontAvailable jQuery Plugin, v1.1
*
* Copyright (c) 2009, Howard Rauscher
* Licensed under the MIT License
*/
(function($) {
var element;
$.fontAvailable = function(fontName) {
var width, height;
// prepare element, and append to DOM
if(!element) {
element = $( document.createElement( 'span' ))
.css( 'visibility', 'hidden' )
.css( 'position', 'absolute' )
.css( 'top', '-10000px' )
.css( 'left', '-10000px' )
.html( 'abcdefghijklmnopqrstuvwxyz' )
.appendTo( document.body );
}
// get the width/height of element after applying a fake font
width = element
.css('font-family', '__FAKEFONT__')
.width();
height = element.height();
// set test font
element.css('font-family', fontName);
return width !== element.width() || height !== element.height();
}
})(jQuery);