OSDN Git Service

Version 0.6.23, remove AbstractBox(AbstractDisplayContainer), working ie-filter-fix.
[pettanr/clientJs.git] / 0.6.x / js / ui / 08_Box.js
1 \r
2 var _Box = _AbstractUINode.inherits(\r
3         '_Box',\r
4         X.Class.PRIVATE_DATA,\r
5         {\r
6                 layout        : null,\r
7                 nodes         : null,\r
8                 forContainer  : false,\r
9                 tmpCss        : null,\r
10                 Constructor : function( layout, args ){\r
11                         if( !this.User.instanceOf( Box ) ){\r
12                                 //throw new Error( 'Box を継承したインスタンスだけが _Box のオーナーになれます' );\r
13                         };\r
14                         var i     = 0,\r
15                                 l     = args.length,\r
16                                 nodes = [],\r
17                                 arg, _data;\r
18                         for( ; i < l; ++i ){\r
19                                 arg = args[ i ];\r
20                                 if( arg.instanceOf && arg.instanceOf( AbstractUINode ) ){\r
21                                         _data = X.Class._getPrivate( arg );\r
22                                         nodes[ nodes.length ] = _data;\r
23                                         if( _data.parent ){\r
24                                                 //throw new Error( 'インスタンスはすでに親に追加されています ' + arg );\r
25                                         };\r
26                                 } else\r
27                                 if( arg.instanceOf && arg.instanceOf( LayoutManagerBase ) ){\r
28                                         layout = arg;\r
29                                 } else\r
30                                 if( X.Type.isObject( arg ) === true ){\r
31                                         this.tmpCss = arg;\r
32                                 } else {\r
33                                         //throw new Error( 'AbstractUINode を継承したインスタンスを渡してください ' + arg );\r
34                                 };\r
35                         };\r
36                         this.layout = layout;\r
37                         this.nodes = nodes;\r
38                 },\r
39         /* Rellay */\r
40                 initialize : function( root, rootData, parent, parentData ){\r
41                         var nodes = this.nodes,\r
42                                 i     = nodes.length;\r
43                         this.root       = root;\r
44                         this.rootData   = rootData;\r
45                         this.parent     = parent;\r
46                         this.parentData = parentData;\r
47                         this.rawElement = X.Dom.Node.create( 'div' );\r
48                         \r
49                         for( ; i; ){\r
50                                 nodes[ --i ].initialize( root, rootData, this.User, this );\r
51                         };\r
52                         \r
53                         this.styleData.initialize();\r
54                         \r
55                         this.phase = 1;\r
56                         this.User.dispatch( { type : X.UI.Event.INIT } );\r
57                 },\r
58                 \r
59                 addToParent : function( parentElement ){\r
60                         var nodes = this.nodes,\r
61                                 l     = nodes.length,\r
62                                 i     = 0;\r
63 \r
64                         parentElement && parentElement.append( this.rawElement );\r
65                         \r
66                         for( ; i < l; ++i ){\r
67                                 nodes[ i ].addToParent( this.rawElement );\r
68                         };\r
69                         \r
70                         this.phase = 2;\r
71                         this.User.dispatch( { type : X.UI.Event.ADDED } );\r
72                 },\r
73                 \r
74         /* Rellay */\r
75                 afterAddition : function(){\r
76                         var nodes = this.nodes,\r
77                                 i = nodes.length;\r
78                         for( ; i; ){\r
79                                 nodes[ --i ].afterAddition();\r
80                         };\r
81                         this.styleData.afterAddition();\r
82                         \r
83                         this.phase = 3;\r
84                         this.User.dispatch( { type : X.UI.Event.CREATION_COMPLETE } );\r
85                 },\r
86                 \r
87                 calculate : function( x, y, w, h ){\r
88                         this.layout.calculate( this, x, y, w, h );                      \r
89                         this.phase = 4;\r
90                 },\r
91                 \r
92                 commitUpdate : function(){\r
93                         \r
94                 },\r
95                 \r
96                 addAt : function( index, _nodes ){\r
97                         //console.log( '# AddAt ' + this.phase )\r
98                         var nodes = this.nodes,\r
99                                 num   = nodes.length,\r
100                                 p1    = 1 <= this.phase,\r
101                                 p2    = 2 <= this.phase,\r
102                                 p3    = 3 <= this.phase,\r
103                                 _p1, _p2,\r
104                                 i = 0, l, data;\r
105 \r
106                         //console.log( '### AddAt ' + this.phase )\r
107                         for( l = _nodes.length; i < l; ++i ){\r
108                                 data = X.Class._getPrivate( _nodes[ i ] );\r
109                                 _p1  = p1 && data.phase < 1;\r
110                                 _p2  = p2 && data.phase < 2;\r
111                                 _p1 && data.initialize( this.root, this.rootData, this.User, this );\r
112                                 if( index <= num ){\r
113                                         // _p2 && this.rawElement.insertBefore( data.rawElement, nodes[ index + i ].rawElement );\r
114                                         _p2 && nodes[ index + i ].rawElement.before( data.rawElement );\r
115                                         _p2 && data.addToParent( null );\r
116                                         nodes.splice( index + i, 0, data );\r
117                                 } else {\r
118                                         _p2 && data.addToParent( this.rawElement );\r
119                                         nodes[ nodes.length ] = data;   \r
120                                 };\r
121                                 p3 && data.phase < 3 && data.afterAddition();\r
122                                 p3 && data.phase < 4 && data.creationComplete();\r
123                         };\r
124                         4 <= this.phase && this.rootData.reserveCalc();\r
125                 },\r
126                 \r
127                 remove : function( _nodes ){\r
128                         //console.log( '# AddAt ' + this.phase )\r
129                         var nodes = this.nodes,\r
130                                 i     = _nodes.length,\r
131                                 n, node;\r
132 \r
133                         //console.log( '### AddAt ' + this.phase )\r
134                         for( ; i; ){\r
135                                 node = X.Class._getPrivate( _nodes[ --i ] );\r
136                                 if( ( n = nodes.indexOf( node ) ) !== -1 ){\r
137                                         nodes.splice( n, 1 );\r
138                                         node._remove();\r
139                                 };\r
140                         };\r
141                         4 <= this.phase && this.rootData.reserveCalc();\r
142                 },\r
143                 \r
144                 removeAt : function( from, length ){\r
145                         var nodes = this.nodes,\r
146                                 i     = nodes.length,\r
147                                 to    = from + ( X.Type.isNumber( length ) && 1 <= length ? length : 1 ),\r
148                                 node;\r
149                         for( ; i; ){\r
150                                 node = nodes[ --i ];\r
151                                 if( from <= i && i < to ){\r
152                                         nodes.splice( i, 1 );\r
153                                         node._remove();\r
154                                 };\r
155                         };\r
156                         4 <= this.phase && this.rootData.reserveCalc();\r
157                 },\r
158                 \r
159                 _remove : function(){\r
160                         var nodes = this.nodes,\r
161                                 i     = nodes.length;\r
162                         for( ; i; ){ nodes[ --i ]._remove(); };\r
163                                         \r
164                         switch( this.phase ){\r
165                                 case 4:\r
166                                 case 3:\r
167                                         //this.styleData.afterAddition();\r
168                                 case 2:\r
169                                         //this.styleData.initialize();\r
170                                         this.rawElement.remove();\r
171                                 case 1:\r
172                                         delete this.root;\r
173                                         delete this.rootData;\r
174                                         delete this.parent;\r
175                                         delete this.parentData;\r
176                                         delete this.rawElement;\r
177                         };\r
178                         delete this.phase;\r
179                 }\r
180         }\r
181 );\r
182 \r
183 var BasicLayoutManager = ( new LayoutManagerBase() ).define( {\r
184         allowForSelf : {\r
185                 childW  : false,\r
186                 childH  : false,\r
187                 gapX    : false,\r
188                 gapY    : false,\r
189                 padding : false\r
190         },\r
191         allowForChild : {\r
192                 x  : true,\r
193                 y  : true,\r
194                 w  : true,\r
195                 h  : true\r
196         },\r
197         calculate : function( data, x, y, w, h ){\r
198                 var nodes = data.nodes,\r
199                         i = 0, l = nodes.length, node;\r
200                 for( ; i < l; ++i ){\r
201                         node = nodes[ i ];\r
202                         if( node.instanceOf( _Box ) ){\r
203                                 node.calculate( x, y, w, h );\r
204                         } else {\r
205                                 //node.styleData.layout( x, y, w, h );\r
206                         };\r
207                 };\r
208                 data.styleData.layout( x, y, w, h );\r
209         }\r
210 });\r
211 \r
212 var Box = AbstractUINode.inherits(\r
213         'Box',\r
214         X.Class.SUPER_ACCESS,\r
215         _Box,\r
216         {\r
217                 Constructor : function(){\r
218                         this.style = DisplayNodeStyle( this, X.Class._newPrivate( this, BasicLayoutManager, arguments ) );\r
219                         this.style.addName( 'Box' );\r
220                 },\r
221                 \r
222                 add : function( node /* , node, node ... */ ){\r
223                         X.Class._getPrivate( this ).addAt( this.numNodes() + 1, Array.prototype.slice.call( arguments ) );\r
224                         return this;\r
225                 },\r
226                 addAt : function( index, node /* , node, node ... */ ){\r
227                         if( index < 0 ) index = 0;\r
228                         X.Class._getPrivate( this ).addAt( arguments[ 0 ], Array.prototype.slice.call( arguments, 1 ) );\r
229                         return this;\r
230                 },\r
231                 remove : function( node /* , node, node ... */ ){\r
232                         X.Class._getPrivate( this ).remove( Array.prototype.slice.call( arguments ) );\r
233                         return this;\r
234                 },\r
235                 removeAt : function( from, length ){\r
236                         X.Class._getPrivate( this ).removeAt( from, length );\r
237                         return this;\r
238                 },\r
239                 getNodesByClass : function( klass ){\r
240                         var ret   = [],\r
241                                 nodes = X.Class._getPrivate( this ).nodes,\r
242                                 i, l, node;\r
243                         if( !nodes || nodes.length === 0 ) return ret;\r
244                         for( i = 0, l = nodes.length; i < l; ++i ){\r
245                                 node = nodes[ i ].User;\r
246                                 if( node.instanceOf( klass ) ) ret[ ret.length ] = node;\r
247                         };\r
248                         return ret;\r
249                 },\r
250                 getFirstChild : function(){\r
251                         return this.getNodeAt( 0 );\r
252                 },\r
253                 getLastChild : function(){\r
254                         var nodes = X.Class._getPrivate( this ).nodes;\r
255                         return nodes && nodes.length && nodes[ nodes.length - 1 ].User || null;\r
256                 },\r
257                 getNodeByUID : function( uid ){\r
258                 },\r
259                 getNodeAt : function( index ){\r
260                         if( index < 0 ) return null;\r
261                         var nodes = X.Class._getPrivate( this ).nodes;\r
262                         return nodes && nodes[ index ].User || null;\r
263                 },\r
264                 numNodes : function(){\r
265                         var nodes = X.Class._getPrivate( this ).nodes;\r
266                         return nodes && nodes.length || 0;\r
267                 }\r
268         }\r
269 );\r
270 \r
271 \r