| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 | |
| 5 /** | 4 /** |
| 6 * @constructor | 5 * @unrestricted |
| 7 * @extends {WebInspector.Object} | |
| 8 * @param {!Element} element | |
| 9 */ | 6 */ |
| 10 WebInspector.DropDownMenu = function(element) | 7 WebInspector.DropDownMenu = class extends WebInspector.Object { |
| 11 { | 8 /** |
| 9 * @param {!Element} element |
| 10 */ |
| 11 constructor(element) { |
| 12 super(); |
| 12 /** @type {!Array.<!WebInspector.DropDownMenu.Item>} */ | 13 /** @type {!Array.<!WebInspector.DropDownMenu.Item>} */ |
| 13 this._items = []; | 14 this._items = []; |
| 14 | 15 |
| 15 element.addEventListener("mousedown", this._onMouseDown.bind(this)); | 16 element.addEventListener('mousedown', this._onMouseDown.bind(this)); |
| 17 } |
| 18 |
| 19 /** |
| 20 * @param {!Event} event |
| 21 */ |
| 22 _onMouseDown(event) { |
| 23 if (event.which !== 1) |
| 24 return; |
| 25 var menu = new WebInspector.ContextMenu(event); |
| 26 for (var item of this._items) |
| 27 menu.appendCheckboxItem(item.title, this._itemHandler.bind(this, item.id),
item.id === this._selectedItemId); |
| 28 menu.show(); |
| 29 } |
| 30 |
| 31 /** |
| 32 * @param {string} id |
| 33 */ |
| 34 _itemHandler(id) { |
| 35 this.dispatchEventToListeners(WebInspector.DropDownMenu.Events.ItemSelected,
id); |
| 36 } |
| 37 |
| 38 /** |
| 39 * @param {string} id |
| 40 * @param {string} title |
| 41 */ |
| 42 addItem(id, title) { |
| 43 this._items.push({id: id, title: title}); |
| 44 } |
| 45 |
| 46 /** |
| 47 * @param {string} id |
| 48 */ |
| 49 selectItem(id) { |
| 50 this._selectedItemId = id; |
| 51 } |
| 52 |
| 53 clear() { |
| 54 this._items = []; |
| 55 delete this._selectedItemId; |
| 56 } |
| 16 }; | 57 }; |
| 17 | 58 |
| 18 /** @typedef {{id: string, title: string}} */ | 59 /** @typedef {{id: string, title: string}} */ |
| 19 WebInspector.DropDownMenu.Item; | 60 WebInspector.DropDownMenu.Item; |
| 20 | 61 |
| 21 /** @enum {symbol} */ | 62 /** @enum {symbol} */ |
| 22 WebInspector.DropDownMenu.Events = { | 63 WebInspector.DropDownMenu.Events = { |
| 23 ItemSelected: Symbol("ItemSelected") | 64 ItemSelected: Symbol('ItemSelected') |
| 24 }; | 65 }; |
| 25 | |
| 26 WebInspector.DropDownMenu.prototype = { | |
| 27 /** | |
| 28 * @param {!Event} event | |
| 29 */ | |
| 30 _onMouseDown: function(event) | |
| 31 { | |
| 32 if (event.which !== 1) | |
| 33 return; | |
| 34 var menu = new WebInspector.ContextMenu(event); | |
| 35 for (var item of this._items) | |
| 36 menu.appendCheckboxItem(item.title, this._itemHandler.bind(this, ite
m.id), item.id === this._selectedItemId); | |
| 37 menu.show(); | |
| 38 }, | |
| 39 | |
| 40 /** | |
| 41 * @param {string} id | |
| 42 */ | |
| 43 _itemHandler: function(id) | |
| 44 { | |
| 45 this.dispatchEventToListeners(WebInspector.DropDownMenu.Events.ItemSelec
ted, id); | |
| 46 }, | |
| 47 | |
| 48 /** | |
| 49 * @param {string} id | |
| 50 * @param {string} title | |
| 51 */ | |
| 52 addItem: function(id, title) | |
| 53 { | |
| 54 this._items.push({id: id, title: title}); | |
| 55 }, | |
| 56 | |
| 57 /** | |
| 58 * @param {string} id | |
| 59 */ | |
| 60 selectItem: function(id) | |
| 61 { | |
| 62 this._selectedItemId = id; | |
| 63 }, | |
| 64 | |
| 65 clear: function() | |
| 66 { | |
| 67 this._items = []; | |
| 68 delete this._selectedItemId; | |
| 69 }, | |
| 70 | |
| 71 __proto__: WebInspector.Object.prototype | |
| 72 }; | |
| OLD | NEW |