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

Commit 5ccd51f

Browse files
committed
Fixes after first review
1 parent c4329f9 commit 5ccd51f

1 file changed

Lines changed: 27 additions & 28 deletions

File tree

src/widgets/Dialogs.js

Lines changed: 27 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -64,37 +64,37 @@ define(function (require, exports, module) {
6464
/**
6565
* @private
6666
* Dismises a modal dialog
67-
* @param {$.Element} dlg
67+
* @param {$.Element} $dlg
6868
* @param {string} buttonId
6969
*/
70-
function _dismissDialog(dlg, buttonId) {
71-
dlg.data("buttonId", buttonId);
72-
$(".clickable-link", dlg).off("click");
73-
dlg.modal("hide");
70+
function _dismissDialog($dlg, buttonId) {
71+
$dlg.data("buttonId", buttonId);
72+
$(".clickable-link", $dlg).off("click");
73+
$dlg.modal("hide");
7474
}
7575

7676
/**
7777
* @private
7878
* Returns true if the modal dialog has a button with the given ID
79-
* @param {$.Element} dlg
79+
* @param {$.Element} $dlg
8080
* @param {string} buttonId
8181
* @return {boolean}
8282
*/
83-
function _hasButton(dlg, buttonId) {
84-
return (dlg.find("[data-button-id='" + buttonId + "']").length > 0);
83+
function _hasButton($dlg, buttonId) {
84+
return ($dlg.find("[data-button-id='" + buttonId + "']").length > 0);
8585
}
8686

8787

8888
/**
8989
* @private
9090
* Handles the use of Tab so that it stays inside the Dialog
9191
* @param {$.Event} event
92-
* @param {$.Element} $element
92+
* @param {$.Element} $dlg
9393
*/
94-
function _watchTab(event, $element) {
95-
var $inputs = $(":input:enabled, :checkbox, :radio, a", $element).filter(":visible");
94+
function _handleTab(event, $dlg) {
95+
var $inputs = $(":input:enabled, a", $dlg).filter(":visible");
9696

97-
if ($(event.target).closest($element).length) {
97+
if ($(event.target).closest($dlg).length) {
9898
// If it's the first or last tabbable element, focus the last/first element
9999
if ((!event.shiftKey && event.target === $inputs[$inputs.length - 1]) ||
100100
(event.shiftKey && event.target === $inputs[0])) {
@@ -121,23 +121,23 @@ define(function (require, exports, module) {
121121
* @return {boolean}
122122
*/
123123
var _keydownHook = function (e, autoDismiss) {
124-
var primaryBtn = this.find(".primary"),
125-
buttonId = null,
126-
which = String.fromCharCode(e.which);
124+
var $primaryBtn = this.find(".primary"),
125+
buttonId = null,
126+
which = String.fromCharCode(e.which);
127127

128128
// There might be a textfield in the dialog's UI; don't want to mistake normal typing for dialog dismissal
129129
var inTextArea = (e.target.tagName === "TEXTAREA"),
130130
inTypingField = inTextArea || ($(e.target).filter(":text, :password").length > 0);
131131

132132
if (e.which === KeyEvent.DOM_VK_TAB) {
133-
_watchTab(e, this);
133+
_handleTab(e, this);
134134
} else if (e.which === KeyEvent.DOM_VK_ESCAPE) {
135135
buttonId = DIALOG_BTN_CANCEL;
136136
} else if (e.which === KeyEvent.DOM_VK_RETURN && !inTextArea) { // enter key in single-line text input still dismisses
137137
// Click primary button
138-
primaryBtn.click();
138+
$primaryBtn.click();
139139
} else if (e.which === KeyEvent.DOM_VK_SPACE) {
140-
// Space bar on focused button
140+
// Space bar on focused button or link
141141
this.find(".dialog-button:focus, a:focus").click();
142142
} else if (brackets.platform === "mac") {
143143
// CMD+D Don't Save
@@ -225,12 +225,11 @@ define(function (require, exports, module) {
225225
autoDismiss = true;
226226
}
227227

228-
var result = $.Deferred(),
229-
promise = result.promise();
230-
231-
var $dlg = $(template)
232-
.addClass("instance")
233-
.appendTo(window.document.body);
228+
var result = $.Deferred(),
229+
promise = result.promise(),
230+
$dlg = $(template)
231+
.addClass("instance")
232+
.appendTo(window.document.body);
234233

235234
// Save the dialog promise for unit tests
236235
$dlg.data("promise", promise);
@@ -291,7 +290,7 @@ define(function (require, exports, module) {
291290
show: true,
292291
keyboard: false // handle the ESC key ourselves so we can deal with nested dialogs
293292
})
294-
// Updates the z-index of the modal dialog and the blackdrop
293+
// Updates the z-index of the modal dialog and the backdrop
295294
.css("z-index", zIndex + 1)
296295
.next().css("z-index", zIndex);
297296

@@ -331,9 +330,9 @@ define(function (require, exports, module) {
331330
* @param {string} dlgClass The class name identifier for the dialog.
332331
*/
333332
function cancelModalDialogIfOpen(dlgClass) {
334-
$("." + dlgClass + ".instance").each(function (index, dlg) {
335-
if ($(dlg).is(":visible")) { // Bootstrap breaks if try to hide dialog that's already hidden
336-
_dismissDialog($(dlg), DIALOG_CANCELED);
333+
$("." + dlgClass + ".instance").each(function () {
334+
if ($(this).is(":visible")) { // Bootstrap breaks if try to hide dialog that's already hidden
335+
_dismissDialog($(this), DIALOG_CANCELED);
337336
}
338337
});
339338
}

0 commit comments

Comments
 (0)