├── demo-files
├── g.css
├── h.css
├── e.js
├── f.js
├── b.js
├── c.js
├── a.js
└── d.js
├── .gitignore
├── in-demo.html
├── README.md
├── in-min.js
├── README
└── in.js
/demo-files/g.css:
--------------------------------------------------------------------------------
1 | body {
2 | background:silver;
3 | }
--------------------------------------------------------------------------------
/demo-files/h.css:
--------------------------------------------------------------------------------
1 | body {
2 | background:gray;
3 | }
--------------------------------------------------------------------------------
/demo-files/e.js:
--------------------------------------------------------------------------------
1 | //$(body).append('test jquery!!!!');
2 | alert('e');
3 | alert('e.js:!!!!'+$);
4 | alert('e end');
--------------------------------------------------------------------------------
/demo-files/f.js:
--------------------------------------------------------------------------------
1 | alert('f');
2 | alert(test);
3 | var me='c rely on f!';
4 | //alert(window.num);
5 | alert('f end');
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | *.iml
2 | .idea/
3 | .ipr
4 | .iws
5 | *~
6 | ~*
7 | *.diff
8 | *.patch
9 | *.bak
10 | .DS_Store
11 | Thumbs.db
12 | .project
13 | .*proj
14 | .svn/
15 | *.swp
16 |
--------------------------------------------------------------------------------
/demo-files/b.js:
--------------------------------------------------------------------------------
1 | alert('b');
2 | var test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';
3 | alert('b end');
--------------------------------------------------------------------------------
/in-demo.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
31 |
32 |
--------------------------------------------------------------------------------
/demo-files/c.js:
--------------------------------------------------------------------------------
1 | alert('c');
2 | alert(me);
3 | var test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';
4 | alert('c end');
--------------------------------------------------------------------------------
/demo-files/a.js:
--------------------------------------------------------------------------------
1 | alert('a');
2 | //alert(inner);
3 | alert(window.inner);
4 | var test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';
5 | alert('a end');
--------------------------------------------------------------------------------
/demo-files/d.js:
--------------------------------------------------------------------------------
1 | alert('d');
2 | //alert(inner);
3 | alert(window.inner);
4 | var test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';test='test';
5 | alert('d end');
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 |
2 | _____
3 | |_ _|
4 | | | _ __
5 | | | | '_ \
6 | _| |_| | | |
7 | |_____|_| |_| v0.2.0 build 110428120728
8 |
9 |
10 | About the author
11 | ---------------------
12 |
13 |
14 | Guokai,1988-08-08
15 | Beijing - Chaoyang
16 | [Benben Blog](http://benben.cc/)
17 |
18 |
19 | Overview the In.js
20 | -----------------------
21 |
22 |
23 | Author: Guokai
24 | Email/Gtalk: badkaikai@gmail.com
25 | Create Datetime: 2011-04-28
26 | Last Update: 2012-07-28
27 | Namespace: window.In
28 | Description: this a light framework that can manage dependency of the modules,
29 | most important,you can load them on-demand,asynchronous and multi-threaded...
30 | License: Apache License,Version 2.0
31 |
32 |
33 | Usage:
34 | -----------
35 |
36 |
37 | In.add('mod1',{path:'url',type:'js',charset:'utf-8',rely:['mod2','mod3']});
38 | In.use('mod1','mod2','mod3',function() {});
39 | In('mod1','mod2','mod3',function() {}); -> short for In.use()
40 | In.ready('mod1','mod2','mod3',function() {});
41 | In.later(3000,'mod1','mod2','mod3',function() {});
42 | In.css(inline-css);
43 | In.config(name,value);
44 |
45 |
46 | Release:
47 | -------------
48 |
49 |
50 | Version: 0.2.0
51 | Build: 110428120728
52 |
53 |
54 | Examples:
55 | --------------
56 |
57 | *1、import In.js to your webpage*
58 |
59 | 例如:底层框架为jQuery 1.5.2-min.js,并引用in时自动加载。
60 |
61 |
62 | <script type="text/javascript" src="in.js" autoload="true" core="jquery 1.5.2-min.js"></script>
63 |
64 |
65 | *2、In.add()*
66 |
67 | 加载三个待执行的javascript模块,分别为mod1、mod2、mod3,其中mod2依赖于mod3.
68 |
69 |
70 | <script type="text/javascript">
71 | In.add('mod1',{path:'mod1.js',type:'js',charset:'utf-8'});
72 | In.add('mod2',{path:'mod2.js',type:'js',charset:'utf-8',rely:['mod3']});
73 | In.add('mod3',{path:'mod3.js',type:'js',charset:'utf-8'});
74 | </script>
75 |
76 |
77 | *3、In() or In.use()*
78 |
79 | 旧版本队列内为顺序加载,如需向后兼容,请事先配置In.config('serial',true)更换为默认串行加载,新版本的队列默认为并行执行,队列中最后一个函数被视为回调函数,下面的代码会并行加载mod1,mod2,function,并立即执行,三者均加载完毕后执行回调函数。
80 |
81 |
82 | <script type="text/javascript">
83 | //真正的加载顺序为 mod1 || mod2 || function -> function[callback]
84 | var demo=In('mod1','mod2',function() {
85 | console.log('我跟mod1和mod2是并行的关系');
86 | },function() {
87 | console.log('我是回调函数,他们都加载完毕才会触发我');
88 | });
89 | </script>
90 |
91 |
92 | *4、In.ready()*
93 |
94 | domReady之后加载队列
95 |
96 |
97 | <script type="text/javascript">
98 | In.ready('mod1','mod2',function() {
99 | console.log($);
100 | });
101 | </script>
102 |
103 |
104 | *5、In.later()*
105 |
106 | 延迟加载队列
107 |
108 |
109 | <script type="text/javascript">
110 | //延迟3秒加载队列
111 | In.later(3000,'mod1','mod2',function() {
112 | console.log($);
113 | });
114 | </script>
115 |
116 |
117 | *6、In.css()*
118 |
119 | 动态注入CSS
120 |
121 |
122 | <script type="text/javascript">
123 | In.css('body {background:yellow}');
124 | </script>
125 |
126 |
127 | *7、In.config()*
128 |
129 | 配置函数
130 |
131 |
132 | <script type="text/javascript">
133 | //设置为串行加载模式,兼容旧的写法
134 | In.config('serial',true);
135 | //设置核心库,核心库会被所有模块依赖
136 | In.config('core','jquery 1.5.2-min.js');
137 | </script>
138 |
139 |
--------------------------------------------------------------------------------
/in-min.js:
--------------------------------------------------------------------------------
1 | ~function(){var __head=document.head||document.getElementsByTagName("head")[0];var __waterfall={};var __loaded={};var __loading={};var __globals=[];var __configure={autoload:false,core:"",serial:false};var __in;var __load=function(url,type,charset,callback){if(__loading[url]){if(callback){setTimeout(function(){__load(url,type,charset,callback);},1);return;}return;}if(__loaded[url]){if(callback){callback();return;}return;}__loading[url]=true;var pureurl=url.split("?")[0];var n,t=type||pureurl.toLowerCase().substring(pureurl.lastIndexOf(".")+1);if(t==="js"){n=document.createElement("script");n.type="text/javascript";n.src=url;n.async="true";if(charset){n.charset=charset;}}else{if(t==="css"){n=document.createElement("link");n.type="text/css";n.rel="stylesheet";n.href=url;__loaded[url]=true;__loading[url]=false;__head.appendChild(n);if(callback){callback();}return;}}n.onload=n.onreadystatechange=function(){if(!this.readyState||this.readyState==="loaded"||this.readyState==="complete"){__loading[url]=false;__loaded[url]=true;if(callback){callback();}n.onload=n.onreadystatechange=null;}};n.onerror=function(){__loading[url]=false;if(callback){callback();}n.onerror=null;};__head.appendChild(n);};var __analyze=function(array){var riverflow=[];for(var i=array.length-1;i>=0;i--){var current=array[i];if(typeof(current)==="string"){if(!__waterfall[current]){console&&console.warn&&console.warn("In Error :: Module not found: "+current);continue;}riverflow.push(current);var relylist=__waterfall[current].rely;if(relylist){riverflow=riverflow.concat(__analyze(relylist));}}else{if(typeof(current)==="function"){riverflow.push(current);}}}return riverflow;};var __stackline=function(blahlist){var o=this;this.stackline=blahlist;this.current=this.stackline[0];this.bag={returns:[],complete:false};this.start=function(){if(typeof(o.current)!="function"&&__waterfall[o.current]){__load(__waterfall[o.current].path,__waterfall[o.current].type,__waterfall[o.current].charset,o.next);}else{o.bag.returns.push(o.current());o.next();}};this.next=function(){if(o.stackline.length==1||o.stackline.length<1){o.bag.complete=true;if(o.bag.oncomplete){o.bag.oncomplete(o.bag.returns);}return;}o.stackline.shift();o.current=o.stackline[0];o.start();};};var __parallel=function(blahlist,callback){var length=blahlist.length;var hook=function(){if(!--length&&callback){callback();}};if(length==0){callback&&callback();return;}for(var i=0;i short for In.use()
33 | In.ready('mod1','mod2','mod3',function() {});
34 | In.later(3000,'mod1','mod2','mod3',function() {});
35 | In.css(inline-css);
36 | In.config(name,value);
37 |
38 | Release:
39 | -------------
40 |
41 | Version: 0.2.0
42 | Build: 110428120728
43 |
44 | Examples:
45 | --------------
46 |
47 | *1、import In.js to your webpage*
48 |
49 | 例如:底层框架为jQuery 1.5.2-min.js,并引用in时自动加载。
50 |
51 |
52 |
53 | *2、In.add()*
54 |
55 | 加载三个待执行的javascript模块,分别为mod1、mod2、mod3,其中mod2依赖于mod3.
56 |
57 |
62 |
63 | *3、In() or In.use()*
64 |
65 | 旧版本队列内为顺序加载,如需向后兼容,请事先配置In.config('serial',true)更换为默认串行加载,新版本的队列默认为并行执行,队列中最后一个函数被视为回调函数,下面的代码会并行加载mod1,mod2,function,并立即执行,三者均加载完毕后执行回调函数。
66 |
67 |
75 |
76 | *4、In.ready()*
77 |
78 | domReady之后加载队列
79 |
80 |
85 |
86 | *5、In.later()*
87 |
88 | 延迟加载队列
89 |
90 |
96 |
97 | *6、In.css()*
98 |
99 | 动态注入CSS
100 |
101 |
104 |
105 | *7、In.config()*
106 |
107 | 配置函数
108 |
109 |
115 |
116 |
117 | --------------------历史文档--------------------
118 |
119 |
120 | _____
121 | |_ _|
122 | | | _ __
123 | | | | '_ \
124 | _| |_| | | |
125 | |_____|_| |_| v0.12 build 110723
126 |
127 | About the author
128 | ---------------------
129 |
130 | Guokai,1988-08-08
131 | Beijing - Chaoyang
132 | http://benben.cc/
133 |
134 | Overview the In.js
135 | -----------------------
136 |
137 | Author: Guokai
138 | Email/Gtalk: badkaikai@gmail.com
139 | Create Datetime: 2011-04-28
140 | Namespace: window.In
141 | Description: this a light framework that can manage dependency of the modules,
142 | most important,you can load them on-demand,asynchronous and multi-threaded...
143 | License: Apache License,Version 2.0
144 |
145 | Usage:
146 | -----------
147 |
148 | In.add('name',{path:'url here',type:'js',charset:'utf-8',rely:['a','b']});
149 | In.exe('name','a','b',function() {...});
150 | In('name','a','b',function() {...}); -> recommended usage equivalent to In.exe()
151 | In.ready('name','a','b',function() {...});
152 | In.watch(o,'p',function(prop,old,new) {...});
153 | In.unwatch(o,'p');
154 |
155 | Release:
156 | -------------
157 |
158 | Version: 0.12
159 | Build: 110723
160 |
161 | **************************************************************************
162 |
163 | 使用示例:
164 | --------------
165 |
166 | 1、import In.js to your webpage
167 |
168 | 例如:底层框架为jQuery 1.5.2-min.js,并引用in时自动加载。
169 |
170 |
171 |
172 | *2、In.add()*
173 |
174 | 加载三个待执行的javascript模块,分别为mod1、mod2、mod3,其中mod2依赖于mod3.
175 |
176 |
181 |
182 | *3、In() or In.exe()*
183 |
184 | 顺序执行mod1,mod2,function,立即执行
185 |
186 |
196 |
197 | *4、In.ready()*
198 |
199 | domReady之后加载队列
200 |
201 |
206 |
207 | *5、In.watch()*
208 |
209 | 监视某一变量值
210 |
211 |
224 |
225 | *6、In.unwatch()*
226 |
227 | 取消对某一变量的监视
228 |
229 |
232 |
--------------------------------------------------------------------------------
/in.js:
--------------------------------------------------------------------------------
1 | /*
2 | ********** In **********
3 | Project Home: http://injs.org
4 |
5 | Author: Guokai
6 | Gtalk: badkaikai@gmail.com
7 | Blog: http://benben.cc
8 | Licence: MIT License
9 | Version: 0.2.0-stable
10 |
11 | Philosophy: Just in time.
12 | Build: 110428120728
13 | */
14 |
15 | ~function() {
16 | var __head = document.head || document.getElementsByTagName('head')[0];
17 | var __waterfall = {};
18 | var __loaded = {};
19 | var __loading = {};
20 | var __globals = [];
21 | var __configure = {autoload: false, core: '', serial: false};
22 | var __in;
23 |
24 | // mapping for `In.load`
25 | // This method used for loading javascript or
26 | // style files asynchronous and non-blocking.
27 |
28 | var __load = function(url, type, charset, callback) {
29 | if(__loading[url]) {
30 | if(callback) {
31 | setTimeout(function() {
32 | __load(url, type, charset, callback);
33 | }, 1);
34 | return;
35 | }
36 | return;
37 | }
38 |
39 | if(__loaded[url]) {
40 | if(callback) {
41 | callback();
42 | return;
43 | }
44 | return;
45 | }
46 |
47 | __loading[url] = true;
48 |
49 | var pureurl = url.split('?')[0];
50 | var n, t = type || pureurl.toLowerCase().substring(pureurl.lastIndexOf('.') + 1);
51 |
52 | if(t === 'js') {
53 | n = document.createElement('script');
54 | n.type = 'text/javascript';
55 | n.src = url;
56 | n.async = 'true';
57 | if(charset) {
58 | n.charset = charset;
59 | }
60 | } else if(t === 'css') {
61 | n = document.createElement('link');
62 | n.type = 'text/css';
63 | n.rel = 'stylesheet';
64 | n.href = url;
65 | __loaded[url] = true;
66 | __loading[url] = false;
67 | __head.appendChild(n);
68 | if(callback) callback();
69 | return;
70 | }
71 |
72 | n.onload = n.onreadystatechange = function() {
73 | if (!this.readyState || this.readyState === 'loaded' || this.readyState === 'complete') {
74 | __loading[url] = false;
75 | __loaded[url] = true;
76 |
77 | if(callback) {
78 | callback();
79 | }
80 |
81 | n.onload = n.onreadystatechange = null;
82 | }
83 | };
84 |
85 | n.onerror = function() {
86 | __loading[url] = false;
87 |
88 | if(callback) {
89 | callback();
90 | }
91 |
92 | n.onerror = null;
93 | }
94 |
95 | __head.appendChild(n);
96 | };
97 |
98 | // private method, analyze the dependency.
99 | // This is the core function for dependency management.
100 |
101 | var __analyze = function(array) {
102 | var riverflow = [];
103 |
104 | for(var i = array.length-1; i >= 0; i--) {
105 | var current = array[i];
106 |
107 | if(typeof(current) === 'string') {
108 | if(!__waterfall[current]) {
109 | console && console.warn && console.warn('In Error :: Module not found: ' + current);
110 | continue;
111 | }
112 |
113 | riverflow.push(current);
114 | var relylist = __waterfall[current].rely;
115 |
116 | if(relylist) {
117 | riverflow = riverflow.concat(__analyze(relylist));
118 | }
119 | } else if(typeof(current) === 'function') {
120 | riverflow.push(current);
121 | }
122 | }
123 |
124 | return riverflow;
125 | };
126 |
127 | // private method, serial process.
128 | // This method used for loading modules in serial.
129 |
130 | var __stackline = function(blahlist) {
131 | var o = this;
132 |
133 | this.stackline = blahlist;
134 | this.current = this.stackline[0];
135 | this.bag = {returns: [], complete: false};
136 |
137 | this.start = function() {
138 | if(typeof(o.current) != 'function' && __waterfall[o.current]) {
139 | __load(__waterfall[o.current].path, __waterfall[o.current].type, __waterfall[o.current].charset, o.next);
140 | } else {
141 | o.bag.returns.push(o.current());
142 | o.next();
143 | }
144 | };
145 |
146 | this.next = function() {
147 | if(o.stackline.length == 1 || o.stackline.length < 1) {
148 | o.bag.complete = true;
149 | if(o.bag.oncomplete) {
150 | o.bag.oncomplete(o.bag.returns);
151 | }
152 | return;
153 | }
154 |
155 | o.stackline.shift();
156 | o.current = o.stackline[0];
157 | o.start();
158 | };
159 | };
160 |
161 | // private method, parallel process.
162 | // This method used for loading modules in parallel.
163 |
164 | var __parallel = function(blahlist, callback) {
165 | var length = blahlist.length;
166 | var hook = function() {
167 | if(!--length && callback) callback();
168 | };
169 |
170 | if(length == 0) {
171 | callback && callback();
172 | return;
173 | };
174 |
175 | for(var i = 0; i < blahlist.length; i++) {
176 | var current = __waterfall[blahlist[i]];
177 |
178 | if(typeof(blahlist[i]) == 'function') {
179 | blahlist[i]();
180 | hook();
181 | continue;
182 | }
183 |
184 | if(typeof(current) === 'undefined') {
185 | console && console.warn && console.warn('In Error :: Module not found: ' + blahlist[i]);
186 | hook();
187 | continue;
188 | }
189 |
190 | if(current.rely && current.rely.length != 0) {
191 | __parallel(current.rely, (function(current) {
192 | return function() {
193 | __load(current.path, current.type, current.charset, hook);
194 | };
195 | })(current));
196 | } else {
197 | __load(current.path, current.type, current.charset, hook);
198 | }
199 | }
200 | };
201 |
202 | // mapping for `In.add`
203 | // This method used for adding module.
204 |
205 | var __add = function(name, config) {
206 | if(!name || !config || !config.path) return;
207 | __waterfall[name] = config;
208 | };
209 |
210 | // mapping for `In.adds`
211 | // This method used for adding modules.
212 |
213 | var __adds = function(config) {
214 | if(!config.modules) return;
215 |
216 | for(var module in config.modules) {
217 | if(config.modules.hasOwnProperty(module)) {
218 | var module_config = config.modules[module];
219 |
220 | if(!config.modules.hasOwnProperty(module)) continue;
221 | if(config.type && !module_config.type) module_config.type = config.type;
222 | if(config.charset && !module_config.charset) module_config.charset = config.charset;
223 | __add.call(this, module, module_config);
224 | }
225 | }
226 | };
227 |
228 | // mapping for `In.config`
229 | // This method used for change the default config.
230 |
231 | var __config = function(name, conf) {
232 | __configure[name] = conf;
233 | };
234 |
235 | // mapping for `In.css`
236 | // This method used for insert inline css to your page dynamically.
237 |
238 | var __css = function(csstext) {
239 | var css = document.getElementById('in-inline-css');
240 |
241 | if(!css) {
242 | css = document.createElement('style');
243 | css.type = 'text/css';
244 | css.id = 'in-inline-css';
245 | __head.appendChild(css);
246 | }
247 |
248 | if(css.styleSheet) {
249 | css.styleSheet.cssText = css.styleSheet.cssText + csstext;
250 | } else {
251 | css.appendChild(document.createTextNode(csstext));
252 | }
253 | };
254 |
255 | // mapping for `In.later`
256 | // This method used for loading modules delay time specified.
257 |
258 | var __later = function() {
259 | var args = [].slice.call(arguments);
260 | var timeout = args.shift();
261 |
262 | window.setTimeout(function() {
263 | __in.apply(this, args);
264 | }, timeout);
265 | };
266 |
267 | // mapping for `In.ready`
268 | // This method used for loading modules while domready.
269 |
270 | var __ready = function() {
271 | var args = arguments;
272 |
273 | __contentLoaded(window, function() {
274 | __in.apply(this, args);
275 | });
276 | };
277 |
278 | var __global = function() {
279 | var args = arguments[0].constructor === Array ? arguments[0] : [].slice.call(arguments);
280 |
281 | __globals = __globals.concat(args);
282 | };
283 |
284 | // mapping for `In`
285 | // This is the main function, also mapping for method `use`.
286 |
287 | var __in = function() {
288 | var args = [].slice.call(arguments);
289 |
290 | if(__globals.length) {
291 | args = __globals.concat(args);
292 | }
293 |
294 | if(__configure.serial) {
295 | if(__configure.core && !__loaded[__configure.core]) {
296 | args = ['__core'].concat(args);
297 | }
298 |
299 | var blahlist = __analyze(args).reverse();
300 | var stack = new __stackline(blahlist);
301 |
302 | stack.start();
303 | return stack.bag;
304 | }
305 |
306 | if(typeof(args[args.length-1]) === 'function') {
307 | var callback = args.pop();
308 | }
309 |
310 | if(__configure.core && !__loaded[__configure.core]) {
311 | __parallel(['__core'], function() {
312 | __parallel(args, callback);
313 | });
314 | } else {
315 | __parallel(args, callback);
316 | }
317 | };
318 |
319 | // private method, contentLoaded.
320 | // This method used for domready.
321 |
322 | var __contentLoaded = function(win,fn) {
323 | var done = false, top=true,
324 | doc = win.document, root = doc.documentElement,
325 | add = doc.addEventListener ? 'addEventListener' : 'attachEvent',
326 | rem = doc.addEventListener ? 'removeEventListener' : 'detachEvent',
327 | pre = doc.addEventListener ? '' : 'on',
328 |
329 | init = function(e) {
330 | if(e.type == 'readystatechange' && doc.readyState != 'complete') return;
331 | (e.type == 'load' ? win : doc)[rem](pre + e.type, init, false);
332 | if(!done && (done=true)) fn.call(win, e.type || e);
333 | },
334 |
335 | poll = function() {
336 | try {root.doScroll('left');} catch(e) {setTimeout(poll, 50);return;}
337 | init('poll');
338 | };
339 |
340 | if(doc.readyState == 'complete') {
341 | fn.call(win, 'lazy');
342 | } else {
343 | if(doc.createEventObject && root.doScroll) {
344 | try {top =! win.frameElement;} catch(e) {}
345 | if(top) poll();
346 | }
347 |
348 | doc[add](pre + 'DOMContentLoaded', init, false);
349 | doc[add](pre + 'readystatechange', init, false);
350 | win[add](pre + 'load', init, false);
351 | }
352 | }
353 |
354 | // private method, initialize.
355 | // This is a self-executing function while in.js loaded.
356 |
357 | void function() {
358 | var myself = (function() {
359 | var scripts = document.getElementsByTagName('script');
360 | return scripts[scripts.length - 1];
361 | })();
362 |
363 | var autoload = myself.getAttribute('autoload');
364 | var core = myself.getAttribute('core');
365 |
366 | if(core) {
367 | __configure['autoload'] = eval(autoload);
368 | __configure['core'] = core;
369 | __add('__core', {path: __configure.core});
370 | }
371 |
372 | // autoload the core files
373 | if(__configure.autoload && __configure.core) {
374 | __in();
375 | }
376 | }();
377 |
378 | // Bind the private method to in.
379 |
380 | __in.add = __add;
381 | __in.adds = __adds;
382 | __in.config = __config;
383 | __in.css = __css;
384 | __in.later = __later;
385 | __in.load = __load;
386 | __in.ready = __ready;
387 | __in.global = __global;
388 | __in.use = __in;
389 |
390 | this.In = __in;
391 | }();
392 |
--------------------------------------------------------------------------------