1 // Copyright (c) 2010 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 }, 40 41 /** 42 * Called when the selection state of this element changes. 43 */ 44 selectionChanged: function() { 45 }, 46 }; 47 48 /** 49 * Whether the item is selected. Setting this does not update the underlying 50 * selection model. This is only used for display purpose. 51 * @type {boolean} 52 */ 53 cr.defineProperty(ListItem, 'selected', cr.PropertyKind.BOOL_ATTR, 54 function() { 55 this.selectionChanged(); 56 }); 57 58 /** 59 * Whether the item is the lead in a selection. Setting this does not update 60 * the underlying selection model. This is only used for display purpose. 61 * @type {boolean} 62 */ 63 cr.defineProperty(ListItem, 'lead', cr.PropertyKind.BOOL_ATTR); 64 65 /** 66 * This item's index in the containing list. 67 * @type {number} 68 */ 69 cr.defineProperty(ListItem, 'listIndex'); 70 71 return { 72 ListItem: ListItem 73 }; 74 }); 75