-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathfont.js
More file actions
99 lines (87 loc) · 2.37 KB
/
font.js
File metadata and controls
99 lines (87 loc) · 2.37 KB
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
var font = function() {
this.name = null;
this.url = null;
this.style = "normal";
this.size = "14px";
this.weight = "normal";
this.variant = "normal";
this.stretch = "normal";
this.setName = function(input) {
this.name = input;
return this;
}
this.setURL = function(input) {
this.url = input;
return this;
}
this.setStyle = function(input) {
this.style = input;
return this;
}
this.setSize = function(input) {
this.size = input;
return this;
}
this.setWeight = function(input) {
this.weight = input;
return this;
}
this.setVariant = function(input) {
this.variant = input;
return this;
}
this.setStrech = function(input) {
this.strech = input;
return this;
}
this.load = function(selector) {
if (!document.getElementById("fontjs-" + this.name)) {
var head = document.getElementsByTagName('head').item(0);
var style = document.createElement("style");
style.setAttribute("type", "text/css");
style.setAttribute("id", "fontjs-" + this.name);
var content = "@font-face {font-family:"
+ this.name
+ "; src:url("
+ this.url
+ ");font-style:"
+ this.style
+ "font-weight:"
+ this.weight
+ "font-stretch:"
+ this.stretch
+ "}";
if (style.styleSheet) {
style.styleSheet.cssText = content;
} else {
style.appendChild(document.createTextNode(content));
head.appendChild(style);
}
} else {
document.getElementById("fontjs-" + this.name)
.innerHTML = "@font-face {font-family:"
+ this.name
+ "; src:url("
+ this.url
+ ");font-style:"
+ this.style
+ "font-weight:"
+ this.weight
+ "font-stretch:"
+ this.stretch
+ "}";
}
var sel = document.querySelectorAll(selector);
for (var i = sel.length - 1; i >= 0; i--) {
sel[i].setAttribute("style", "font-family:"
+ this.name
+ ";font-size:"
+ this.size
+ ";");
}
return this;
}
}
function Font(name) {
return new font().setName(name);
}