- add sources.
[platform/framework/web/crosswalk.git] / src / ui / webui / resources / js / cr / ui / list_item.js
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 cr.define('cr.ui', function() {
6
7   /**
8    * Creates a new list item element.
9    * @param {string} opt_label The text label for the item.
10    * @constructor
11    * @extends {HTMLLIElement}
12    */
13   var ListItem = cr.ui.define('li');
14
15   ListItem.prototype = {
16     __proto__: HTMLLIElement.prototype,
17
18     /**
19      * Plain text label.
20      * @type {string}
21      */
22     get label() {
23       return this.textContent;
24     },
25     set label(label) {
26       this.textContent = label;
27     },
28
29     /**
30      * This item's index in the containing list.
31      * @type {number}
32      */
33     listIndex_: -1,
34
35     /**
36      * Called when an element is decorated as a list item.
37      */
38     decorate: function() {
39       this.setAttribute('role', 'listitem');
40     },
41
42     /**
43      * Called when the selection state of this element changes.
44      */
45     selectionChanged: function() {
46     },
47   };
48
49   /**
50    * Whether the item is selected. Setting this does not update the underlying
51    * selection model. This is only used for display purpose.
52    * @type {boolean}
53    */
54   cr.defineProperty(ListItem, 'selected', cr.PropertyKind.BOOL_ATTR,
55                     function() {
56                       this.selectionChanged();
57                     });
58
59   /**
60    * Whether the item is the lead in a selection. Setting this does not update
61    * the underlying selection model. This is only used for display purpose.
62    * @type {boolean}
63    */
64   cr.defineProperty(ListItem, 'lead', cr.PropertyKind.BOOL_ATTR);
65
66   /**
67    * This item's index in the containing list.
68    * @type {number}
69    */
70   cr.defineProperty(ListItem, 'listIndex');
71
72   return {
73     ListItem: ListItem
74   };
75 });