22
22
THE SOFTWARE.
23
23
****************************************************************************/
24
24
25
+ /**
26
+ * listView event type
27
+ * @type {Object }
28
+ */
25
29
ccs . ListViewEventType = {
26
30
listViewOnselectedItem : 0
27
31
} ;
28
32
33
+ /**
34
+ * listView gravity
35
+ * @type {Object }
36
+ */
29
37
ccs . ListViewGravity = {
30
38
left : 0 ,
31
39
right : 1 ,
@@ -35,6 +43,11 @@ ccs.ListViewGravity = {
35
43
centerVertical : 5
36
44
} ;
37
45
46
+ /**
47
+ * Base class for ccs.ListView
48
+ * @class
49
+ * @extends ccs.ScrollView
50
+ */
38
51
ccs . ListView = ccs . ScrollView . extend ( {
39
52
_model : null ,
40
53
_items : null ,
@@ -65,12 +78,15 @@ ccs.ListView = ccs.ScrollView.extend({
65
78
return false ;
66
79
} ,
67
80
81
+ /**
82
+ * Sets a item model for listview. A model will be cloned for adding default item.
83
+ * @param {ccs.Widget } model
84
+ */
68
85
setItemModel : function ( model ) {
69
86
if ( ! model ) {
70
87
return ;
71
88
}
72
89
this . _model = model ;
73
-
74
90
} ,
75
91
76
92
updateInnerContainerSize : function ( ) {
@@ -206,6 +222,9 @@ ccs.ListView = ccs.ScrollView.extend({
206
222
}
207
223
} ,
208
224
225
+ /**
226
+ * Push back a default item(create by a cloned model) into listview.
227
+ */
209
228
pushBackDefaultItem : function ( ) {
210
229
if ( ! this . _model ) {
211
230
return ;
@@ -217,6 +236,10 @@ ccs.ListView = ccs.ScrollView.extend({
217
236
this . _refreshViewDirty = true ;
218
237
} ,
219
238
239
+ /**
240
+ * Insert a default item(create by a cloned model) into listview.
241
+ * @param {Number } index
242
+ */
220
243
insertDefaultItem : function ( index ) {
221
244
if ( ! this . _model ) {
222
245
return ;
@@ -228,20 +251,33 @@ ccs.ListView = ccs.ScrollView.extend({
228
251
this . _refreshViewDirty = true ;
229
252
} ,
230
253
254
+ /**
255
+ * Push back custom item into listview.
256
+ * @param {ccs.Widget } item
257
+ */
231
258
pushBackCustomItem : function ( item ) {
232
259
this . _items . push ( item ) ;
233
260
this . remedyLayoutParameter ( item ) ;
234
261
this . addChild ( item ) ;
235
262
this . _refreshViewDirty = true ;
236
263
} ,
237
264
265
+ /**
266
+ * Push back custom item into listview.
267
+ * @param {ccs.Widget } item
268
+ * @param {Number } index
269
+ */
238
270
insertCustomItem : function ( item , index ) {
239
271
cc . ArrayAppendObjectToIndex ( this . _items , item , index ) ;
240
272
this . remedyLayoutParameter ( item ) ;
241
273
this . addChild ( item ) ;
242
274
this . _refreshViewDirty = true ;
243
275
} ,
244
276
277
+ /**
278
+ * Removes a item whose index is same as the parameter.
279
+ * @param {Number } index
280
+ */
245
281
removeItem : function ( index ) {
246
282
var item = this . getItem ( index ) ;
247
283
if ( ! item ) {
@@ -252,25 +288,46 @@ ccs.ListView = ccs.ScrollView.extend({
252
288
this . _refreshViewDirty = true ;
253
289
} ,
254
290
291
+ /**
292
+ * Removes the last item of listview.
293
+ */
255
294
removeLastItem : function ( ) {
256
295
this . removeItem ( this . _items . length - 1 ) ;
257
296
} ,
258
297
298
+ /**
299
+ * Returns a item whose index is same as the parameter.
300
+ * @param {Number } index
301
+ * @returns {cc.Widget }
302
+ */
259
303
getItem : function ( index ) {
260
304
if ( index < 0 || index >= this . _items . length ) {
261
305
return null ;
262
306
}
263
307
return this . _items [ index ] ;
264
308
} ,
265
309
310
+ /**
311
+ * Returns the item container.
312
+ * @returns {Array }
313
+ */
266
314
getItems : function ( ) {
267
315
return this . _items ;
268
316
} ,
269
317
318
+ /**
319
+ * Returns the index of item.
320
+ * @param {ccs.Widget } item
321
+ * @returns {Number }
322
+ */
270
323
getIndex : function ( item ) {
271
324
return cc . ArrayGetIndexOfObject ( this . _items , item ) ;
272
325
} ,
273
326
327
+ /**
328
+ * Changes the gravity of listview.
329
+ * @param {ccs.ListViewGravity } gravity
330
+ */
274
331
setGravity : function ( gravity ) {
275
332
if ( this . _gravity == gravity ) {
276
333
return ;
@@ -279,6 +336,10 @@ ccs.ListView = ccs.ScrollView.extend({
279
336
this . _refreshViewDirty = true ;
280
337
} ,
281
338
339
+ /**
340
+ * Changes the margin between each item.
341
+ * @param {Number } margin
342
+ */
282
343
setItemsMargin : function ( margin ) {
283
344
if ( this . _itemsMargin == margin ) {
284
345
return ;
@@ -287,6 +348,10 @@ ccs.ListView = ccs.ScrollView.extend({
287
348
this . _refreshViewDirty = true ;
288
349
} ,
289
350
351
+ /**
352
+ * Changes scroll direction of scrollview.
353
+ * @param {ccs.ScrollViewDir } dir
354
+ */
290
355
setDirection : function ( dir ) {
291
356
switch ( dir ) {
292
357
case ccs . ScrollViewDir . vertical :
@@ -305,6 +370,11 @@ ccs.ListView = ccs.ScrollView.extend({
305
370
306
371
} ,
307
372
373
+ /**
374
+ * add event listener
375
+ * @param {Function } selector
376
+ * @param {Object } target
377
+ */
308
378
addEventListenerListView : function ( selector , target ) {
309
379
this . _listViewEventListener = target ;
310
380
this . _listViewEventSelector = selector ;
@@ -331,6 +401,10 @@ ccs.ListView = ccs.ScrollView.extend({
331
401
}
332
402
} ,
333
403
404
+ /**
405
+ * get current selected index
406
+ * @returns {number }
407
+ */
334
408
getCurSelectedIndex : function ( ) {
335
409
return this . _curSelectedIndex ;
336
410
} ,
@@ -363,8 +437,13 @@ ccs.ListView = ccs.ScrollView.extend({
363
437
ccs . ScrollView . prototype . onSizeChanged . call ( this ) ;
364
438
this . _refreshViewDirty = true ;
365
439
} ,
440
+
441
+ /**
442
+ * Returns the "class name" of widget.
443
+ * @returns {string }
444
+ */
366
445
getDescription : function ( ) {
367
- return "ListViewEx " ;
446
+ return "ListView " ;
368
447
} ,
369
448
370
449
createCloneInstance : function ( ) {
0 commit comments