1+ (
2+
3+ function ( ) {
4+ var __ = function ( args ) {
5+ return new lib ( args ) ;
6+ } ;
7+
8+ var lib = function ( args ) {
9+ var selector = [ ] ;
10+ if ( typeof args === 'object' ) {
11+ selector . push ( args ) ;
12+ } else if ( typeof args === 'string' ) {
13+ selector = document . querySelectorAll ( args ) ;
14+ }
15+ this . length = selector . length ;
16+ if ( typeof this . length === 'undefined' ) { this . length = 1 ; }
17+ this . version = '0.0.1' ;
18+
19+ for ( i = 0 ; i < this . length ; i ++ ) {
20+ this [ i ] = selector [ i ] ;
21+ }
22+
23+ return this ;
24+ } ;
25+
26+ __ . func = lib . prototype = {
27+ /* general */
28+ hide : function ( ) {
29+ var len = this . length ;
30+ while ( len -- ) {
31+ this [ len ] . style . display = 'none' ;
32+ }
33+ return this ;
34+ } ,
35+ show : function ( ) {
36+ var len = this . length ;
37+ while ( len -- ) {
38+ this [ len ] . style . display = 'inherit' ;
39+ }
40+ return this ;
41+ } ,
42+ /* class and id */
43+ toggleClass : function ( oldC , newC ) {
44+ var len = this . length ;
45+ while ( len -- ) {
46+ this [ len ] . className = this [ len ] . className . replace ( oldC , newC ) ;
47+ }
48+ return this ;
49+ } ,
50+ getClass : function ( ) {
51+ var len = this . length ;
52+ if ( len === 1 ) {
53+ return this [ 0 ] . className ;
54+ } else {
55+ var classes = [ ] ;
56+ while ( len -- ) {
57+ classes . push ( this [ len ] . className ) ;
58+ }
59+ return classes ;
60+ }
61+ } ,
62+ getId : function ( ) {
63+ var len = this . length ;
64+ if ( len === 1 ) {
65+ return this [ 0 ] . getAttribute ( 'id' ) ;
66+ } else {
67+ var ids = [ ] ;
68+ while ( len -- ) {
69+ ids . push ( this [ len ] . getAttribute ( 'id' ) ) ;
70+ }
71+ return ids ;
72+ }
73+ } ,
74+ addClass : function ( _class ) {
75+ var len = this . length ;
76+ while ( len -- ) {
77+ if ( this [ len ] . className !== '' ) {
78+ this [ len ] . className += ( ' ' + _class ) ;
79+ } else {
80+ this [ len ] . className += _class ;
81+ }
82+ }
83+ return this ;
84+ } ,
85+ removeClass : function ( _class ) {
86+ var len = this . length ;
87+ while ( len -- ) {
88+ this [ len ] . className = this [ len ] . className . replace ( _class , '' ) ;
89+ }
90+ return this ;
91+ } ,
92+ /* events */
93+ onEvent : function ( evnt , fun ) {
94+ var len = this . length ;
95+ while ( len -- ) {
96+ this [ len ] . addEventListener ( evnt , fun ) ;
97+ }
98+ return this ;
99+ } ,
100+ /* external */
101+ loadScriptFile : function ( url ) {
102+ var x = document . createElement ( 'script' ) ;
103+ x . setAttribute ( 'src' , url ) ;
104+ document . head . appendChild ( x ) ;
105+ return this ;
106+ } ,
107+ loadCSSFile : function ( url ) {
108+ var x = document . createElement ( 'link' ) ;
109+ x . setAttribute ( 'rel' , 'stylesheet' ) ;
110+ x . setAttribute ( 'href' , url ) ;
111+ document . head . appendChild ( x ) ;
112+ return this ;
113+ }
114+ } ;
115+
116+ if ( ! window . __ ) {
117+ window . __ = __ ;
118+ }
119+ }
120+
121+ ) ( ) ;
0 commit comments