Skip to content
This repository was archived by the owner on Sep 6, 2021. It is now read-only.

Commit 1b957c4

Browse files
committed
Move the triggerHandler call into _renderList instead of calling it directly in refresh().
1 parent ba8bd1b commit 1b957c4

2 files changed

Lines changed: 34 additions & 26 deletions

File tree

src/search/FileFilters.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -407,10 +407,10 @@ define(function (require, exports, module) {
407407
/**
408408
* Set up mouse click event listeners for 'Delete' and 'Edit' buttons
409409
* when the dropdown is open. Also set check mark on the active filter.
410-
* @param {!Event>} event openDropdown event triggered when the dropdown is open
410+
* @param {!Event>} event listRendered event triggered when the dropdown is open
411411
* @param {!jQueryObject} $dropdown the jQuery DOM node of the dropdown list
412412
*/
413-
function _handleOpenDropdown(event, $dropdown) {
413+
function _handleListRendered(event, $dropdown) {
414414
var activeFilterIndex = PreferencesManager.getViewState("activeFileFilter"),
415415
checkedItemIndex = (activeFilterIndex > -1) ? (activeFilterIndex + FIRST_FILTER_INDEX) : -1;
416416
_picker.setChecked(checkedItemIndex, true);
@@ -461,7 +461,7 @@ define(function (require, exports, module) {
461461
_picker.$button.addClass("file-filter-picker no-focus");
462462

463463
// Set up mouse click event listeners for 'Delete' and 'Edit' buttons
464-
$(_picker).on("openDropdown", _handleOpenDropdown);
464+
$(_picker).on("listRendered", _handleListRendered);
465465

466466
$(_picker).on("select", function (event, item, itemIndex) {
467467
if (itemIndex === 0) {
@@ -474,7 +474,6 @@ define(function (require, exports, module) {
474474
editFilter({ name: "", patterns: [] }, -1);
475475
} else if (itemIndex === 1) {
476476
// Uncheck the prior active filter in the dropdown list.
477-
var checkedItemIndex = getActiveFilter() + FIRST_FILTER_INDEX;
478477
_picker.setChecked(itemIndex, false);
479478

480479
// Clear the active filter

src/widgets/DropdownButton.js

Lines changed: 31 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -119,8 +119,16 @@ define(function (require, exports, module) {
119119
return _.escape(String(item));
120120
};
121121

122-
/** Converts the list of item objects into HTML list items in format required by DropdownEventHandler */
123-
DropdownButton.prototype._renderList = function () {
122+
/**
123+
* Converts the list of item objects into HTML list items in format required by DropdownEventHandler
124+
* @param {!jQueryObject} parent The dropdown element
125+
* @return {!jQueryObject} The dropdown element with the rendered list items appended.
126+
*/
127+
DropdownButton.prototype._renderList = function (parent) {
128+
if (!parent) {
129+
return null;
130+
}
131+
124132
var html = "";
125133
this.items.forEach(function (item, i) {
126134
if (item === "---") {
@@ -131,7 +139,14 @@ define(function (require, exports, module) {
131139
html += "</a></li>";
132140
}
133141
}.bind(this));
134-
return html;
142+
143+
parent.append(html);
144+
145+
// Also trigger listRendered handler so that custom event handlers can be
146+
// set up for any custom UI in the list.
147+
$(this).triggerHandler("listRendered", [parent]);
148+
149+
return parent;
135150
};
136151

137152
/**
@@ -145,11 +160,7 @@ define(function (require, exports, module) {
145160

146161
// Remove all list items and then re-create them from this.items.
147162
$("li", this.$dropdown).remove();
148-
this.$dropdown.append(this._renderList());
149-
150-
// Also trigger openDropdown handler so that custom event handlers can be
151-
// set up for any custom UI in the list.
152-
$(this).triggerHandler("openDropdown", [this.$dropdown]);
163+
this._renderList(this.$dropdown);
153164
};
154165

155166
/**
@@ -185,20 +196,22 @@ define(function (require, exports, module) {
185196
Menus.closeAll();
186197

187198
var $dropdown = $("<ul class='dropdown-menu dropdownbutton-popup' tabindex='-1'>")
188-
.addClass(this.dropdownExtraClasses) // (no-op if unspecified)
189-
.append(this._renderList())
199+
.addClass(this.dropdownExtraClasses); // (no-op if unspecified)
200+
201+
this.$dropdown = $dropdown;
202+
this._renderList(this.$dropdown)
190203
.appendTo($("body"))
191204
.data("attached-to", this.$button[0]); // keep ModalBar open while dropdown focused
192205

193206
// Calculate position of dropdown
194-
var toggleOffset = this.$button.offset(),
195-
posLeft = toggleOffset.left,
196-
posTop = toggleOffset.top + this.$button.outerHeight(),
197-
elementRect = {
198-
top: posTop,
199-
left: posLeft,
200-
height: $dropdown.height(),
201-
width: $dropdown.width()
207+
var toggleOffset = this.$button.offset(),
208+
posLeft = toggleOffset.left,
209+
posTop = toggleOffset.top + this.$button.outerHeight(),
210+
elementRect = {
211+
top: posTop,
212+
left: posLeft,
213+
height: $dropdown.height(),
214+
width: $dropdown.width()
202215
},
203216
clip = ViewUtils.getElementClipSize($(window), elementRect);
204217

@@ -228,10 +241,6 @@ define(function (require, exports, module) {
228241
// Manage focus
229242
this._lastFocus = window.document.activeElement;
230243
$dropdown.focus();
231-
232-
this.$dropdown = $dropdown;
233-
234-
$(this).triggerHandler("openDropdown", [$dropdown]);
235244
};
236245

237246
/**

0 commit comments

Comments
 (0)