Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(388)

Side by Side Diff: chrome/browser/resources/options/deletable_item_list.js

Issue 5685003: DOMUI Prefs: Add a deletable item list type, and use it for startup pages. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Whitespace fix Created 10 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
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('options', function() {
6 const List = cr.ui.List;
7 const ListItem = cr.ui.ListItem;
8
9 /**
10 * Wraps a list item to make it deletable, adding a delete button that calls
11 * deleteItem(value) on delegate when it is clicked.
12 * @param {!ListItem} baseItem The list element to wrap.
13 * @param {*} delegate The delegate to call.
14 * @param {*} value The value corresponding to the list item.
15 */
16 function DeletableListItem(baseItem, delegate, value) {
17 var el = cr.doc.createElement('div');
18 el.baseItem_ = baseItem;
19 el.delegate_ = delegate;
20 el.value_ = value;
21 DeletableListItem.decorate(el);
22 return el;
23 }
24
25 /**
26 * Decorates an element as a deletable list item.
27 * @param {!HTMLElement} el The element to decorate.
28 */
29 DeletableListItem.decorate = function(el) {
30 el.__proto__ = DeletableListItem.prototype;
31 el.decorate();
32 };
33
34 DeletableListItem.prototype = {
35 __proto__: ListItem.prototype,
36
37 /**
38 * The list item being wrapped to make in deletable.
39 * @type {!ListItem}
40 * @private
41 */
42 baseItem_: null,
43
44 /**
45 * The delegate to call on item deletion.
46 * @type {*}
47 * @private
48 */
49 delegate_: null,
50
51 /**
52 * The value for the list item.
53 * @type {*}
54 * @private
55 */
56 value_: null,
57
58 /** @inheritDoc */
59 decorate: function() {
60 ListItem.prototype.decorate.call(this);
61
62 this.className = 'deletable-item';
63 var contentEl = this.ownerDocument.createElement('div');
64 contentEl.appendChild(this.baseItem_);
65 var closeEl = this.ownerDocument.createElement('div');
66 var closeButtonEl = this.ownerDocument.createElement('button');
arv (Not doing code reviews) 2010/12/13 20:18:41 I think you can get away with only closeButtonEl h
stuartmorgan 2010/12/14 00:10:58 Done.
67 closeButtonEl.className = 'close-button';
68 var self = this;
69 closeButtonEl.onclick = function(event) {
arv (Not doing code reviews) 2010/12/13 20:18:41 I think you might be better of listening to click
stuartmorgan 2010/12/14 00:10:58 Done.
70 self.delegate_.deleteItem(self.value_);
arv (Not doing code reviews) 2010/12/13 20:18:41 Another option might have been to dispatch a delet
71 };
72 closeEl.appendChild(closeButtonEl);
73
74 this.appendChild(contentEl);
75 this.appendChild(closeEl);
76 },
77
78 /**
79 * Returns the list item being wrapped to make in deletable.
80 * @return {!ListItem} The list item being wrapped
81 */
82 get contentItem() {
83 return this.baseItem_;
84 }
85 };
86
87 var DeletableItemList = cr.ui.define('list');
88
89 DeletableItemList.prototype = {
90 __proto__: List.prototype,
91
92 /** @inheritDoc */
93 createItem: function(value) {
94 var baseItem = this.createItemContents(value);
95 return new DeletableListItem(baseItem, this, value);
96 },
97
98 /**
99 * Creates a new list item to use as the main row contents for |value|.
100 * Subclasses should override this instead of createItem.
101 * @param {*} value The value to use for the item.
102 * @return {!ListItem} The newly created list item.
103 */
104 createItemContents: function(value) {
105 List.prototype.createItem.call(this, value);
106 },
107
108 /**
109 * Called when an item should be deleted; subclasses are responsible for
110 * implementing.
111 * @param {*} value The item value that is being deleted.
112 */
113 deleteItem: function(value) {
114 },
115 };
116
117 return {
118 DeletableItemList: DeletableItemList
119 };
120 });
OLDNEW
« no previous file with comments | « chrome/browser/resources/options/browser_options_startup_page_list.js ('k') | chrome/browser/resources/options/options.html » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698