iconfont.js
3.09 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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
;(function(window) {
var svgSprite = '<svg>' +
''+
'<symbol id="icon-back" viewBox="0 0 1024 1024">'+
''+
'<path d="M681.789015 313.760446c-75.69745 0-13.89615-229.798443-57.047354-272.145133a146.275266 146.275266 0 0 0-204.273409 0L44.687094 411.399186C17.62617 438.094422 0 491.192343 0 511.963431c0 20.771088 17.553032 73.869009 44.687094 100.564246l375.781158 369.783872c28.231126 27.792301 65.238769 41.615313 102.173274 41.615313s73.942147-13.89615 102.173273-41.615313c43.004928-42.34669-18.723234-272.071995 57.047354-272.071995l161.780444-0.073137c118.775516 0 180.284265 0 180.284265-92.153418v-212.099136c0-99.906007-54.341261-92.153418-180.284265-92.153417H681.789015z" ></path>'+
''+
'</symbol>'+
''+
'</svg>'
var script = function() {
var scripts = document.getElementsByTagName('script')
return scripts[scripts.length - 1]
}()
var shouldInjectCss = script.getAttribute("data-injectcss")
/**
* document ready
*/
var ready = function(fn){
if(document.addEventListener){
document.addEventListener("DOMContentLoaded",function(){
document.removeEventListener("DOMContentLoaded",arguments.callee,false)
fn()
},false)
}else if(document.attachEvent){
IEContentLoaded (window, fn)
}
function IEContentLoaded (w, fn) {
var d = w.document, done = false,
// only fire once
init = function () {
if (!done) {
done = true
fn()
}
}
// polling for no errors
;(function () {
try {
// throws errors until after ondocumentready
d.documentElement.doScroll('left')
} catch (e) {
setTimeout(arguments.callee, 50)
return
}
// no errors, fire
init()
})()
// trying to always fire before onload
d.onreadystatechange = function() {
if (d.readyState == 'complete') {
d.onreadystatechange = null
init()
}
}
}
}
/**
* Insert el before target
*
* @param {Element} el
* @param {Element} target
*/
var before = function (el, target) {
target.parentNode.insertBefore(el, target)
}
/**
* Prepend el to target
*
* @param {Element} el
* @param {Element} target
*/
var prepend = function (el, target) {
if (target.firstChild) {
before(el, target.firstChild)
} else {
target.appendChild(el)
}
}
function appendSvg(){
var div,svg
div = document.createElement('div')
div.innerHTML = svgSprite
svg = div.getElementsByTagName('svg')[0]
if (svg) {
svg.setAttribute('aria-hidden', 'true')
svg.style.position = 'absolute'
svg.style.width = 0
svg.style.height = 0
svg.style.overflow = 'hidden'
prepend(svg,document.body)
}
}
if(shouldInjectCss && !window.__iconfont__svg__cssinject__){
window.__iconfont__svg__cssinject__ = true
try{
document.write("<style>.svgfont {display: inline-block;width: 1em;height: 1em;fill: currentColor;vertical-align: -0.1em;font-size:16px;}</style>");
}catch(e){
console && console.log(e)
}
}
ready(appendSvg)
})(window)