| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 cr.define('options', function() { | 5 cr.define('options', function() { |
| 6 const List = cr.ui.List; | 6 const List = cr.ui.List; |
| 7 const ListItem = cr.ui.ListItem; | 7 const ListItem = cr.ui.ListItem; |
| 8 | 8 |
| 9 /** | 9 /** |
| 10 * Wraps a list item to make it deletable, adding a button that will trigger a | 10 * Wraps a list item to make it deletable, adding a button that will trigger a |
| (...skipping 13 matching lines...) Expand all Loading... |
| 24 */ | 24 */ |
| 25 DeletableListItem.decorate = function(el) { | 25 DeletableListItem.decorate = function(el) { |
| 26 el.__proto__ = DeletableListItem.prototype; | 26 el.__proto__ = DeletableListItem.prototype; |
| 27 el.decorate(); | 27 el.decorate(); |
| 28 }; | 28 }; |
| 29 | 29 |
| 30 DeletableListItem.prototype = { | 30 DeletableListItem.prototype = { |
| 31 __proto__: ListItem.prototype, | 31 __proto__: ListItem.prototype, |
| 32 | 32 |
| 33 /** | 33 /** |
| 34 * The list item being wrapped to make in deletable. | 34 * The list item being wrapped to make it deletable. |
| 35 * @type {!ListItem} | 35 * @type {!ListItem} |
| 36 * @private | 36 * @private |
| 37 */ | 37 */ |
| 38 baseItem_: null, | 38 baseItem_: null, |
| 39 | 39 |
| 40 /** @inheritDoc */ | 40 /** @inheritDoc */ |
| 41 decorate: function() { | 41 decorate: function() { |
| 42 ListItem.prototype.decorate.call(this); | 42 ListItem.prototype.decorate.call(this); |
| 43 | 43 |
| 44 this.className = 'deletable-item'; | 44 this.baseItem_.classList.add('deletable-item'); |
| 45 var contentEl = this.ownerDocument.createElement('div'); | 45 this.appendChild(this.baseItem_); |
| 46 contentEl.appendChild(this.baseItem_); | 46 |
| 47 var closeButtonEl = this.ownerDocument.createElement('button'); | 47 var closeButtonEl = this.ownerDocument.createElement('button'); |
| 48 closeButtonEl.className = 'close-button'; | 48 closeButtonEl.className = 'close-button'; |
| 49 | |
| 50 this.appendChild(contentEl); | |
| 51 this.appendChild(closeButtonEl); | 49 this.appendChild(closeButtonEl); |
| 52 }, | 50 }, |
| 53 | 51 |
| 52 /** @inheritDoc */ |
| 53 selectionChanged: function() { |
| 54 // Forward the selection state to the |baseItem_|. |
| 55 // TODO(jhawkins): This is terrible. |
| 56 this.baseItem_.selected = this.selected; |
| 57 this.baseItem_.selectionChanged(); |
| 58 }, |
| 59 |
| 54 /** | 60 /** |
| 55 * Returns the list item being wrapped to make in deletable. | 61 * Returns the list item being wrapped to make it deletable. |
| 56 * @return {!ListItem} The list item being wrapped | 62 * @return {!ListItem} The list item being wrapped |
| 57 */ | 63 */ |
| 58 get contentItem() { | 64 get contentItem() { |
| 59 return this.baseItem_; | 65 return this.baseItem_; |
| 60 } | 66 }, |
| 61 }; | 67 }; |
| 62 | 68 |
| 63 var DeletableItemList = cr.ui.define('list'); | 69 var DeletableItemList = cr.ui.define('list'); |
| 64 | 70 |
| 65 DeletableItemList.prototype = { | 71 DeletableItemList.prototype = { |
| 66 __proto__: List.prototype, | 72 __proto__: List.prototype, |
| 67 | 73 |
| 68 /** @inheritDoc */ | 74 /** @inheritDoc */ |
| 69 decorate: function() { | 75 decorate: function() { |
| 70 List.prototype.decorate.call(this); | 76 List.prototype.decorate.call(this); |
| (...skipping 29 matching lines...) Expand all Loading... |
| 100 if (target.className == 'close-button') { | 106 if (target.className == 'close-button') { |
| 101 var listItem = this.getListItemAncestor(target); | 107 var listItem = this.getListItemAncestor(target); |
| 102 if (listItem) | 108 if (listItem) |
| 103 this.deleteItemAtIndex(this.getIndexOfListItem(listItem)); | 109 this.deleteItemAtIndex(this.getIndexOfListItem(listItem)); |
| 104 } | 110 } |
| 105 }, | 111 }, |
| 106 | 112 |
| 107 /** | 113 /** |
| 108 * Called when an item should be deleted; subclasses are responsible for | 114 * Called when an item should be deleted; subclasses are responsible for |
| 109 * implementing. | 115 * implementing. |
| 110 * @param {number} index The indexd of the item that is being deleted. | 116 * @param {number} index The index of the item that is being deleted. |
| 111 */ | 117 */ |
| 112 deleteItemAtIndex: function(index) { | 118 deleteItemAtIndex: function(index) { |
| 113 }, | 119 }, |
| 114 }; | 120 }; |
| 115 | 121 |
| 116 return { | 122 return { |
| 117 DeletableItemList: DeletableItemList | 123 DeletableItemList: DeletableItemList |
| 118 }; | 124 }; |
| 119 }); | 125 }); |
| OLD | NEW |