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

Side by Side Diff: chrome/browser/resources/bluetooth_internals/expandable_list.js

Issue 2622393002: bluetooth: Add characteristic list to DeviceDetailsPage in internals page. (Closed)
Patch Set: Simplifications Created 3 years, 11 months 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
OLDNEW
1 // Copyright 2017 The Chromium Authors. All rights reserved. 1 // Copyright 2017 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 /** 5 /**
6 * Javascript for ExpandableList and ExpandableListItem, served from 6 * Javascript for ExpandableList and ExpandableListItem, served from
7 * chrome://bluetooth-internals/. 7 * chrome://bluetooth-internals/.
8 */ 8 */
9 9
10 cr.define('expandable_list', function() { 10 cr.define('expandable_list', function() {
(...skipping 13 matching lines...) Expand all
24 /** 24 /**
25 * Decorates the element as an expandable list item and caches the created 25 * Decorates the element as an expandable list item and caches the created
26 * content holders for implementations. 26 * content holders for implementations.
27 * @override 27 * @override
28 */ 28 */
29 decorate: function() { 29 decorate: function() {
30 this.classList.add('expandable-list-item'); 30 this.classList.add('expandable-list-item');
31 this.briefContent_ = document.createElement('div'); 31 this.briefContent_ = document.createElement('div');
32 this.briefContent_.classList.add('brief-content'); 32 this.briefContent_.classList.add('brief-content');
33 this.briefContent_.addEventListener( 33 this.briefContent_.addEventListener(
34 'click', this.toggleExpand_.bind(this)); 34 'click', this.onExpand_.bind(this));
35 this.appendChild(this.briefContent_); 35 this.appendChild(this.briefContent_);
36 36
37 this.expandedContent_ = document.createElement('div'); 37 this.expandedContent_ = document.createElement('div');
38 this.expandedContent_.classList.add('expanded-content'); 38 this.expandedContent_.classList.add('expanded-content');
39 this.appendChild(this.expandedContent_); 39 this.appendChild(this.expandedContent_);
40 }, 40 },
41 41
42 /** 42 /**
43 * Called when the list item is expanded or collapsed.
44 * @param {boolean} expanded
45 */
46 onExpandInternal: function(expanded) {},
47
48 /**
43 * Toggles the expanded class on the item. 49 * Toggles the expanded class on the item.
44 * @private 50 * @private
45 */ 51 */
46 toggleExpand_: function() { 52 onExpand_: function() {
47 this.classList.toggle('expanded'); 53 this.onExpandInternal(this.classList.toggle('expanded'));
48 }, 54 },
49 }; 55 };
50 56
51 /** 57 /**
52 * A list that contains expandable list items. 58 * A list that contains expandable list items.
53 * @abstract 59 * @abstract
54 * @constructor 60 * @constructor
55 */ 61 */
56 var ExpandableList = cr.ui.define('list'); 62 var ExpandableList = cr.ui.define('list');
57 63
(...skipping 13 matching lines...) Expand all
71 this.emptyMessage_.classList.add('empty-message'); 77 this.emptyMessage_.classList.add('empty-message');
72 this.emptyMessage_.hidden = true; 78 this.emptyMessage_.hidden = true;
73 this.insertBefore(this.emptyMessage_, this.firstChild); 79 this.insertBefore(this.emptyMessage_, this.firstChild);
74 80
75 this.spinner_ = document.createElement('div'); 81 this.spinner_ = document.createElement('div');
76 this.spinner_.classList.add('spinner'); 82 this.spinner_.classList.add('spinner');
77 this.insertBefore(this.spinner_, this.firstChild); 83 this.insertBefore(this.spinner_, this.firstChild);
78 84
79 this.autoExpands = true; 85 this.autoExpands = true;
80 this.boundUpdateMessage_ = this.updateMessageDisplay_.bind(this); 86 this.boundUpdateMessage_ = this.updateMessageDisplay_.bind(this);
87 this.setLoading(true);
81 }, 88 },
82 89
83 /** 90 /**
84 * Sets the data model of the list. 91 * Sets the data model of the list.
85 * @param {cr.ui.ArrayDataModel} data 92 * @param {cr.ui.ArrayDataModel} data
86 */ 93 */
87 setData: function(data) { 94 setData: function(data) {
88 if (this.dataModel) 95 if (this.dataModel)
89 this.dataModel.removeEventListener('splice', this.boundUpdateMessage_); 96 this.dataModel.removeEventListener('splice', this.boundUpdateMessage_);
90 97
(...skipping 13 matching lines...) Expand all
104 /** 111 /**
105 * Sets the loading state of the list. If |loading| is true, the loading 112 * Sets the loading state of the list. If |loading| is true, the loading
106 * spinner is dispayed. 113 * spinner is dispayed.
107 * @param {boolean} loading 114 * @param {boolean} loading
108 */ 115 */
109 setLoading: function(loading) { 116 setLoading: function(loading) {
110 this.spinner_.hidden = !loading; 117 this.spinner_.hidden = !loading;
111 }, 118 },
112 119
113 /** 120 /**
121 * Gets the loading state of the list. Returns true if the list is loading.
122 * @return {boolean}
123 */
124 isLoading: function() {
125 return !this.spinner_.hidden;
126 },
127
128 /**
114 * Updates the display state of the empty message. If there are no items in 129 * Updates the display state of the empty message. If there are no items in
115 * the data model, the empty message is displayed. 130 * the data model, the empty message is displayed.
116 */ 131 */
117 updateMessageDisplay_: function() { 132 updateMessageDisplay_: function() {
118 this.emptyMessage_.hidden = this.dataModel.length > 0; 133 this.emptyMessage_.hidden = this.dataModel.length > 0;
119 }, 134 },
120 }; 135 };
121 136
122 return { 137 return {
123 ExpandableListItem: ExpandableListItem, 138 ExpandableListItem: ExpandableListItem,
124 ExpandableList: ExpandableList, 139 ExpandableList: ExpandableList,
125 } 140 }
126 }); 141 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698