diff options
Diffstat (limited to 'point/libs/require-css/css.min.js')
-rw-r--r-- | point/libs/require-css/css.min.js | 63 |
1 files changed, 63 insertions, 0 deletions
diff --git a/point/libs/require-css/css.min.js b/point/libs/require-css/css.min.js new file mode 100644 index 0000000..1be578e --- /dev/null +++ b/point/libs/require-css/css.min.js | |||
@@ -0,0 +1,63 @@ | |||
1 | define(function () { | ||
2 | if (typeof window == "undefined")return{load: function (n, r, load) { | ||
3 | load() | ||
4 | }}; | ||
5 | var head = document.getElementsByTagName("head")[0]; | ||
6 | var engine = window.navigator.userAgent.match(/Trident\/([^ ;]*)|AppleWebKit\/([^ ;]*)|Opera\/([^ ;]*)|rv\:([^ ;]*)(.*?)Gecko\/([^ ;]*)|MSIE\s([^ ;]*)/) || 0; | ||
7 | var useImportLoad = false; | ||
8 | var useOnload = true; | ||
9 | if (engine[1] || engine[7])useImportLoad = parseInt(engine[1]) < 6 || parseInt(engine[7]) <= 9; else if (engine[2])useOnload = false; else if (engine[4])useImportLoad = parseInt(engine[4]) < 18; | ||
10 | var cssAPI = {}; | ||
11 | cssAPI.pluginBuilder = "./css-builder"; | ||
12 | var curStyle; | ||
13 | var createStyle = function () { | ||
14 | curStyle = document.createElement("style"); | ||
15 | head.appendChild(curStyle) | ||
16 | }; | ||
17 | var importLoad = function (url, callback) { | ||
18 | createStyle(); | ||
19 | var curSheet = curStyle.styleSheet || curStyle.sheet; | ||
20 | if (curSheet && curSheet.addImport) { | ||
21 | curSheet.addImport(url); | ||
22 | curStyle.onload = callback | ||
23 | } else { | ||
24 | curStyle.textContent = '@import "' + url + '";'; | ||
25 | var loadInterval = setInterval(function () { | ||
26 | try { | ||
27 | curStyle.sheet.cssRules; | ||
28 | clearInterval(loadInterval); | ||
29 | callback() | ||
30 | } catch (e) { | ||
31 | } | ||
32 | }, 10) | ||
33 | } | ||
34 | }; | ||
35 | var linkLoad = function (url, callback) { | ||
36 | var link = document.createElement("link"); | ||
37 | link.type = "text/css"; | ||
38 | link.rel = "stylesheet"; | ||
39 | if (useOnload)link.onload = function () { | ||
40 | link.onload = function () { | ||
41 | }; | ||
42 | setTimeout(callback, 7) | ||
43 | }; else var loadInterval = setInterval(function () { | ||
44 | for (var i = 0; i < document.styleSheets.length; i++) { | ||
45 | var sheet = document.styleSheets[i]; | ||
46 | if (sheet.href == link.href) { | ||
47 | clearInterval(loadInterval); | ||
48 | return callback() | ||
49 | } | ||
50 | } | ||
51 | }, 10); | ||
52 | link.href = url; | ||
53 | head.appendChild(link) | ||
54 | }; | ||
55 | cssAPI.normalize = function (name, normalize) { | ||
56 | if (name.substr(name.length - 4, 4) == ".css")name = name.substr(0, name.length - 4); | ||
57 | return normalize(name) | ||
58 | }; | ||
59 | cssAPI.load = function (cssId, req, load, config) { | ||
60 | (useImportLoad ? importLoad : linkLoad)(req.toUrl(cssId + ".css"), load) | ||
61 | }; | ||
62 | return cssAPI | ||
63 | }); \ No newline at end of file | ||