-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathimport.min.js
41 lines (41 loc) · 2.93 KB
/
import.min.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
36
37
38
39
40
41
/**
* JavaScript/CSS/LESS files $import utility
*
* Usage: $import (src[, srcN, ...][, callback])
*
* Where "src" is: "[name:type] url"
* OR: "[name] url"
* OR: "[:type] url"
* OR: "url"
*
* Where "type" is: "js" or "css" or "less"
*
* https://github.com/w3core/import.js/
* @version 1.0.0
* @license BSD License
* @author Max Chuhryaev
*/
!new function(e,n){function t(e,n,t,r){n.addEventListener(e,t,r)}function r(e,n,t,r){n.removeEventListener(e,t,r)}function a(n){return n&&"object"==typeof n&&"number"==typeof n.length&&!n.nodeName&&n!=e}function u(e,t){var r=n.createEvent("HTMLEvents")
return r.data=t,r.initEvent(e,!0,!0),!n.dispatchEvent(r)}function o(e){var n=/^(\s*\[\s*(\!?)\s*([a-zA-Z0-9\.\-_]*)\s*\:?\s*([a-zA-Z]*)\s*\])?\s*([^\s]+)\s*$/g.exec(e),t=/^[^#?]+\.([a-zA-Z0-9]+)([?#].*)?$/g.exec(e)
return n?{reload:!!n[2],name:n[3]?[n[3]]:[],type:n[4]||t?(n[4]||t[1]).toLowerCase():null,url:n[5]}:null}function l(e,n){var n="string"==typeof n?o(n):n
if(n){for(var t,r=0;r<e.length;r++)if(e[r].url==n.url){if(n.reload&&(e[r].reload=!0),n.type&&!e[r].type&&(e[r].type=n.type),n.name.length)for(var a=0;a<n.name.length;a++)e[r].name.indexOf(n.name[a])<0&&e[r].name.push(n.name[a])
t=!0
break}t||e.push(n)}}function f(e){var n,t=[],r=[]
if("function"==typeof e)t.push(e)
else if("string"==typeof e){n=e.split(",")
for(var u=0;u<n.length;u++)l(r,n[u])}else if(e&&"object"==typeof e){var o=a(e)
for(var u in e){n=f(e[u])
for(var i=0;i<n.src.length;i++)o||n.src[i].name.push(u),l(r,n.src[i])
for(var s=0;s<n.callback.length;s++)t.push(n.callback[s])}}return{src:r,callback:t}}function i(e){return!e||"js"==e}function s(e){return i(e)?"script":"link"}function c(e){return i(e)?"src":"href"}function p(e,u){var o=n.createElement("img"),l="load",f="error",p=i(e.type),h=n.createElement(s(e.type))
h.queue=[u],h[c(e.type)]=e.url,h[p?"type":"rel"]=p?"text/javascript":"less"==e.type?"stylesheet/less":"stylesheet"
var v=function(n){if(r(l,h,v),r(f,h,v),a(h.queue)&&h.queue.length)for(;h.queue.length>0;){var t=h.queue.shift()
"function"==typeof t&&t(h,e,n)}}
return t(l,p?h:o,v),t(f,p?h:o,v),m.push(h),y.appendChild(h),p||(o.src=e.url),h}function h(e,t){for(var r=c(e),a=n.getElementsByTagName(s(e)),u=0;u<a.length;u++)if(a[u][r]==t)return a[u]}function v(e,n){var t=h(e,n)
if(t)return a(t.queue)||(t.queue=[],m.push(t)),t
for(var r=c(e),u=0;u<m.length;u++)if(m[u][r]==n)return m[u]}function g(e,n){var t=f([].slice.call(arguments)),e=t.src,n=t.callback,r=0,a=function(e){return e.parentNode||y.appendChild(e),e},o=function(){for(var t=0;t<n.length;t++)n[t](e)
for(var t=0;t<e.length;t++){u("@import",e[t])
for(var r=0;r<e[t].name.length;r++)u("@import:"+e[t].name[r],e[t])}}
if(!e.length)return o()
for(var l=function(){r++,r==e.length&&o()},i=0;i<e.length;i++){var s=e[i].type,c=e[i].url,h=v(s,c)
h?(e[i].node=a(h),h.queue.length?h.queue.push(l):l()):e[i].node=p(e[i],l)}}var m=[],y=n.getElementsByTagName("head")[0]
e.$import=g}(window,document);