| OLD | NEW |
| 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 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 77 this.emptyMessage_.classList.add('empty-message'); | 77 this.emptyMessage_.classList.add('empty-message'); |
| 78 this.emptyMessage_.hidden = true; | 78 this.emptyMessage_.hidden = true; |
| 79 this.insertBefore(this.emptyMessage_, this.firstChild); | 79 this.insertBefore(this.emptyMessage_, this.firstChild); |
| 80 | 80 |
| 81 this.spinner_ = document.createElement('div'); | 81 this.spinner_ = document.createElement('div'); |
| 82 this.spinner_.classList.add('spinner'); | 82 this.spinner_.classList.add('spinner'); |
| 83 this.insertBefore(this.spinner_, this.firstChild); | 83 this.insertBefore(this.spinner_, this.firstChild); |
| 84 | 84 |
| 85 this.autoExpands = true; | 85 this.autoExpands = true; |
| 86 this.boundUpdateMessage_ = this.updateMessageDisplay_.bind(this); | 86 this.boundUpdateMessage_ = this.updateMessageDisplay_.bind(this); |
| 87 this.setLoading(true); | 87 this.setSpinnerShowing(true); |
| 88 }, | 88 }, |
| 89 | 89 |
| 90 /** | 90 /** |
| 91 * Sets the data model of the list. | 91 * Sets the data model of the list. |
| 92 * @param {cr.ui.ArrayDataModel} data | 92 * @param {cr.ui.ArrayDataModel} data |
| 93 */ | 93 */ |
| 94 setData: function(data) { | 94 setData: function(data) { |
| 95 if (this.dataModel) | 95 if (this.dataModel) |
| 96 this.dataModel.removeEventListener('splice', this.boundUpdateMessage_); | 96 this.dataModel.removeEventListener('splice', this.boundUpdateMessage_); |
| 97 | 97 |
| 98 this.dataModel = data; | 98 this.dataModel = data; |
| 99 this.dataModel.addEventListener('splice', this.boundUpdateMessage_); | 99 this.dataModel.addEventListener('splice', this.boundUpdateMessage_); |
| 100 this.updateMessageDisplay_(); | 100 this.updateMessageDisplay_(); |
| 101 }, | 101 }, |
| 102 | 102 |
| 103 /** | 103 /** |
| 104 * Sets the empty message text. | 104 * Sets the empty message text. |
| 105 * @param {string} message | 105 * @param {string} message |
| 106 */ | 106 */ |
| 107 setEmptyMessage: function(message) { | 107 setEmptyMessage: function(message) { |
| 108 this.emptyMessage_.textContent = message; | 108 this.emptyMessage_.textContent = message; |
| 109 }, | 109 }, |
| 110 | 110 |
| 111 /** | 111 /** |
| 112 * Sets the loading state of the list. If |loading| is true, the loading | 112 * Sets the spinner display state. If |showing| is true, the loading |
| 113 * spinner is dispayed. | 113 * spinner is dispayed. |
| 114 * @param {boolean} loading | 114 * @param {boolean} showing |
| 115 */ | 115 */ |
| 116 setLoading: function(loading) { | 116 setSpinnerShowing: function(showing) { |
| 117 this.spinner_.hidden = !loading; | 117 this.spinner_.hidden = !showing; |
| 118 }, | 118 }, |
| 119 | 119 |
| 120 /** | 120 /** |
| 121 * Gets the loading state of the list. Returns true if the list is loading. | 121 * Gets the spinner display state. Returns true if the spinner is showing. |
| 122 * @return {boolean} | 122 * @return {boolean} |
| 123 */ | 123 */ |
| 124 isLoading: function() { | 124 isSpinnerShowing: function() { |
| 125 return !this.spinner_.hidden; | 125 return !this.spinner_.hidden; |
| 126 }, | 126 }, |
| 127 | 127 |
| 128 /** | 128 /** |
| 129 * 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 |
| 130 * the data model, the empty message is displayed. | 130 * the data model, the empty message is displayed. |
| 131 */ | 131 */ |
| 132 updateMessageDisplay_: function() { | 132 updateMessageDisplay_: function() { |
| 133 this.emptyMessage_.hidden = this.dataModel.length > 0; | 133 this.emptyMessage_.hidden = this.dataModel.length > 0; |
| 134 }, | 134 }, |
| 135 }; | 135 }; |
| 136 | 136 |
| 137 return { | 137 return { |
| 138 ExpandableListItem: ExpandableListItem, | 138 ExpandableListItem: ExpandableListItem, |
| 139 ExpandableList: ExpandableList, | 139 ExpandableList: ExpandableList, |
| 140 } | 140 } |
| 141 }); | 141 }); |
| OLD | NEW |