list_item.js revision 1320f92c476a1ad9d19dba2a48c72b75566198e9
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 5cr.define('cr.ui', function() { 6 7 /** 8 * Creates a new list item element. 9 * @constructor 10 * @extends {HTMLLIElement} 11 */ 12 var ListItem = cr.ui.define('li'); 13 14 ListItem.prototype = { 15 __proto__: HTMLLIElement.prototype, 16 17 /** 18 * Plain text label. 19 * @type {string} 20 */ 21 get label() { 22 return this.textContent; 23 }, 24 set label(label) { 25 this.textContent = label; 26 }, 27 28 /** 29 * This item's index in the containing list. 30 * @type {number} 31 */ 32 listIndex_: -1, 33 34 /** 35 * Called when an element is decorated as a list item. 36 */ 37 decorate: function() { 38 this.setAttribute('role', 'listitem'); 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 */ 52 cr.defineProperty(ListItem, 'selected', cr.PropertyKind.BOOL_ATTR, 53 function() { 54 this.selectionChanged(); 55 }); 56 57 /** 58 * Whether the item is the lead in a selection. Setting this does not update 59 * the underlying selection model. This is only used for display purpose. 60 */ 61 cr.defineProperty(ListItem, 'lead', cr.PropertyKind.BOOL_ATTR); 62 63 /** 64 * This item's index in the containing list. 65 * type {number} 66 */ 67 cr.defineProperty(ListItem, 'listIndex'); 68 69 return { 70 ListItem: ListItem 71 }; 72}); 73