Skip to content

Commit 61253eb

Browse files
committed
Draft.
0 parents  commit 61253eb

File tree

5 files changed

+106
-0
lines changed

5 files changed

+106
-0
lines changed

.gitignore

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
Thumbs.db
2+
ehthumbs.db
3+
[Dd]esktop.ini
4+
$RECYCLE.BIN/
5+
.DS_Store
6+
.klive
7+
.dropbox.cache
8+
9+
*.tmp
10+
*.bak
11+
*.swp
12+
13+
.svn
14+
.idea

LICENSE.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# License
2+
3+
[MIT License](http://www.opensource.org/licenses/mit-license.php)

README.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# Tiny.js
2+
3+
A tiny JavaScript utility library.
4+
5+
## 简介
6+
7+
一个非常小巧的 JavaScript 工具库,适用于用户脚本(userscript)、演示案例等比较紧凑的场景。
8+
9+
因为使用了一些较先进的 JavaScript/DOM API,仅适用于现代浏览器。
10+
11+
**注意**:仍在开发中,API 仍不稳定。
12+
13+
## License
14+
15+
[MIT License](http://www.opensource.org/licenses/mit-license.php)

dist/tiny.js

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/*! Tiny.js v0.1.0 **/
2+
var $ = function(s){return document.querySelectorAll(s);};
3+
$.id = function(s){return document.getElementById(s);};
4+
$.cls = function(s){return document.getElementsByClassName(s);};
5+
$.tag = function(s,eWrapper){return (eWrapper || document).getElementsByTagName(s);};
6+
$.crE = function(s){return document.createElement(s);};
7+
$.crT = function(s){return document.createTextNode(s);};
8+
$.insBfr = function(eW,e){eW.insertBefore(e,eW.firstChild);};
9+
$.rmv = function (e) {e.parentNode.removeChild(e);};
10+
$.getT = function(e){return e.firstChild.data;};
11+
$.setT = function(e,s){e.firstChild.data=s;};
12+
$.hide = function(e){e.style.visibility='hidden';};
13+
$.show = function(e){e.style.visibility='visible';};
14+
$.off = function(e){e.style.display='none';};
15+
$.on = function(e){e.style.display='';};
16+
$.style = function(e,p,v){
17+
if (v) {
18+
e.style[p] = v;
19+
} else {
20+
e.style.cssText = p;
21+
}
22+
};
23+
$.addEv = function(e,sEv,fn){e.addEventListener(sEv,fn,false);};
24+
$.rmvEv = function(e,sEv,fn){e.removeEventListener(sEv,fn,false);};
25+
$.each = function (a,fn){for(var i=0,l=a.length;i<l;++i){fn(a[i]);}};
26+
$.hasT = function(so,s){return so.indexOf(s)>-1;};
27+
$.hasCls = function(so,s){return $.hasT(' '+so+' ',' '+s+' ');};
28+
$.addCls = function(e,s){var so=e.className;if(!$.hasCls(so,s))e.className+=(' '+s);};
29+
$.rmvCls = function(e,s){var so=e.className;if($.hasCls(so,s))e.className=(' '+so+' ').replace(' '+s+' ',' ').trim();};
30+
$.css = function (s) {
31+
var css = $.crE('style');
32+
css.innerHTML = s;
33+
console.log(css);
34+
$.tag('head')[0].appendChild(css);
35+
};
36+
$.cssText = '';
37+

src/tiny.js

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/*! Tiny.js v0.1.0 **/
2+
var $ = function(s){return document.querySelectorAll(s);};
3+
$.id = function(s){return document.getElementById(s);};
4+
$.cls = function(s){return document.getElementsByClassName(s);};
5+
$.tag = function(s,eWrapper){return (eWrapper || document).getElementsByTagName(s);};
6+
$.crE = function(s){return document.createElement(s);};
7+
$.crT = function(s){return document.createTextNode(s);};
8+
$.insBfr = function(eW,e){eW.insertBefore(e,eW.firstChild);};
9+
$.rmv = function (e) {e.parentNode.removeChild(e);};
10+
$.getT = function(e){return e.firstChild.data;};
11+
$.setT = function(e,s){e.firstChild.data=s;};
12+
$.hide = function(e){e.style.visibility='hidden';};
13+
$.show = function(e){e.style.visibility='visible';};
14+
$.off = function(e){e.style.display='none';};
15+
$.on = function(e){e.style.display='';};
16+
$.style = function(e,p,v){
17+
if (v) {
18+
e.style[p] = v;
19+
} else {
20+
e.style.cssText = p;
21+
}
22+
};
23+
$.addEv = function(e,sEv,fn){e.addEventListener(sEv,fn,false);};
24+
$.rmvEv = function(e,sEv,fn){e.removeEventListener(sEv,fn,false);};
25+
$.each = function (a,fn){for(var i=0,l=a.length;i<l;++i){fn(a[i]);}};
26+
$.hasT = function(so,s){return so.indexOf(s)>-1;};
27+
$.hasCls = function(so,s){return $.hasT(' '+so+' ',' '+s+' ');};
28+
$.addCls = function(e,s){var so=e.className;if(!$.hasCls(so,s))e.className+=(' '+s);};
29+
$.rmvCls = function(e,s){var so=e.className;if($.hasCls(so,s))e.className=(' '+so+' ').replace(' '+s+' ',' ').trim();};
30+
$.css = function (s) {
31+
var css = $.crE('style');
32+
css.innerHTML = s;
33+
console.log(css);
34+
$.tag('head')[0].appendChild(css);
35+
};
36+
$.cssText = '';
37+

0 commit comments

Comments
 (0)