OSDN Git Service

Fix the bug of X.NodeAnime.
[pettanr/clientJs.git] / 0.6.x / js / 02_dom / 00_XDoc.js
1 /**
2  * document をラップする
3  * @namespace X.Doc
4  * @alias X.Doc
5  */
6 X[ 'Doc' ] = {
7         /**
8          * EventDispatcher.prototype.listen 参照
9          * @alias X.Doc.listen
10          */
11         'listen' : function( type, arg1, arg2, arg3 ){
12                 var f;
13                 
14                 if( type <= X_ViewPort_readyState && type === 'DOMContentLoaded' ){
15                         /*
16                          * X.Event.XDOM_READY 以後に listen した場合の対策
17                          */
18                         X_ViewPort_document[ 'asyncDispatch' ]( type );
19                 };
20                 
21                 f = X_Closure_classifyCallbackArgs( arg1, arg2, arg3 );
22                 if( !f.cbKind ){
23                         X_ViewPort_document[ 'listen' ]( type, this, arg1 );
24                 } else
25                 if( f.cbKind === X_CLOSURE_FUNC_ONLY ){
26                         X_ViewPort_document[ 'listen' ]( type, this, f.func, f.supplement );
27                 } else {
28                         X_ViewPort_document[ 'listen' ]( type, arg1, arg2, arg3 );
29                 };
30                 return X[ 'Doc' ];
31         },
32         
33         /**
34          * EventDispatcher.prototype.listenOnce 参照
35          * @alias X.Doc.listenOnce
36          */
37         'listenOnce' : function( type, arg1, arg2, arg3 ){
38                 var f;
39                 
40                 if( type <= X_ViewPort_readyState && type === 'DOMContentLoaded' ){
41                         /*
42                          * X.Event.XDOM_READY 以後に listen した場合の対策
43                          */
44                         X_ViewPort_document[ 'asyncDispatch' ]( type );
45                 };
46                 
47                 f = X_Closure_classifyCallbackArgs( arg1, arg2, arg3 );
48                 if( !f.cbKind ){
49                         X_ViewPort_document[ 'listenOnce' ]( type, this, arg1 );
50                 } else
51                 if( f.cbKind === X_CLOSURE_FUNC_ONLY ){
52                         X_ViewPort_document[ 'listenOnce' ]( type, this, f.func, f.supplement );
53                 };
54                 X_ViewPort_document[ 'listenOnce' ]( type, arg1, arg2, arg3 );
55                 return X[ 'Doc' ];
56         },
57
58         /**
59          * EventDispatcher.prototype.unlisten 参照
60          * @alias X.Doc.unlisten
61          */     
62         'unlisten' : function( type, arg1, arg2, arg3 ){
63                 var f = X_Closure_classifyCallbackArgs( arg1, arg2, arg3 );
64                 
65                 if( !f.cbKind ){
66                         X_ViewPort_document[ 'unlisten' ]( type, this, arg1 );
67                 } else
68                 if( f.cbKind === X_CLOSURE_FUNC_ONLY ){
69                         X_ViewPort_document[ 'unlisten' ]( type, this, f.func, f.supplement );
70                 } else {
71                         X_ViewPort_document[ 'unlisten' ]( type, arg1, arg2, arg3 );
72                 };
73                 return X[ 'Doc' ];
74         },
75
76         /**
77          * EventDispatcher.prototype.listening 参照
78          * @alias X.Doc.listening
79          */     
80         'listening' : function( type, arg1, arg2, arg3 ){
81                 var f = X_Closure_classifyCallbackArgs( arg1, arg2, arg3 );
82                 
83                 if( !f.cbKind ){
84                         return X_ViewPort_document[ 'listening' ]( type, this, arg1 );
85                 } else
86                 if( f.cbKind === X_CLOSURE_FUNC_ONLY ){
87                         return X_ViewPort_document[ 'listening' ]( type, this, f.func, f.supplement );
88                 };
89                 return X_ViewPort_document[ 'listening' ]( type, arg1, arg2, arg3 );
90         },
91         
92         'create'     : X_Doc_create,
93         
94         'createText' : X_Doc_createText
95
96 };
97
98 /**
99  * X.Node 要素を作成する。この時点でツリーには追加されない。
100  * @alias X.Doc.create
101  * @param {string} tag タグ名
102  * @param {object} opt_attrs 属性
103  * @param {object} opt_css スタイル
104  * @return {Node}
105  */
106 function X_Doc_create( tag, opt_attrs, opt_css ){
107         var list, i;
108         switch( X_Node_getType( tag ) ){
109                 case X_NodeType_STRING :
110                         X_Node_newByTag = true;
111                         return new Node( tag, opt_attrs, opt_css );
112                 case X_NodeType_HTML_STRING :
113                         list = X_HtmlParser_parse( tag, true );
114                         for( i = list.length; 1 < i; ){
115                                 list[ --i ][ 'kill' ]();
116                         };
117                         return list[ 0 ];
118         };
119 };
120
121 /**
122  * X.Node テキストを作成する。この時点でツリーには追加されない。
123  * @alias X.Doc.createText
124  * @param {string} textContent
125  * @return {Node}
126  */
127 function X_Doc_createText( text ){
128         X_Node_newByText = true;
129         return new Node( text );
130 };