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

Commit 6f6103d

Browse files
committed
Merge pull request #4695 from adobe/pflynn/link-click-safety
Fix bug #4613 - Globally preventDefault() on *all* link clicks
2 parents 1fb9041 + 1cd7afd commit 6f6103d

File tree

4 files changed

+16
-7
lines changed

4 files changed

+16
-7
lines changed

src/brackets.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -339,6 +339,22 @@ define(function (require, exports, module) {
339339
e.preventDefault();
340340
}
341341
});
342+
343+
// Prevent clicks on any link from navigating to a different page (which could lose unsaved
344+
// changes). We can't use a simple .on("click", "a") because of http://bugs.jquery.com/ticket/3861:
345+
// jQuery hides non-left clicks from such event handlers, yet middle-clicks still cause CEF to
346+
// navigate. Also, a capture handler is more reliable than bubble.
347+
window.document.body.addEventListener("click", function (e) {
348+
// Check parents too, in case link has inline formatting tags
349+
var node = e.target;
350+
while (node) {
351+
if (node.tagName === "A") {
352+
e.preventDefault();
353+
break;
354+
}
355+
node = node.parentElement;
356+
}
357+
}, true);
342358
}
343359

344360
// Dispatch htmlReady event

src/extensibility/ExtensionManagerDialog.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,6 @@ define(function (require, exports, module) {
185185
// Dialog tabs
186186
$dlg.find(".nav-tabs a")
187187
.on("click", function (event) {
188-
event.preventDefault();
189188
$(this).tab("show");
190189
});
191190

src/extensibility/ExtensionManagerView.js

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -148,11 +148,6 @@ define(function (require, exports, module) {
148148
// UI event handlers
149149
this.$el
150150
.on("click", "a", function (e) {
151-
// Never allow the default behavior for links--we don't want
152-
// them to navigate out of Brackets!
153-
e.stopImmediatePropagation();
154-
e.preventDefault();
155-
156151
var $target = $(e.target);
157152
if ($target.hasClass("undo-remove")) {
158153
ExtensionManager.markForRemoval($target.attr("data-extension-id"), false);

src/extensions/default/WebPlatformDocs/InlineDocsViewer.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,6 @@ define(function (require, exports, module) {
9797

9898
/** Clicking any link should open it in browser, not in Brackets shell */
9999
InlineDocsViewer.prototype._handleLinkClick = function (event) {
100-
event.preventDefault();
101100
var url = $(event.currentTarget).attr("href");
102101
if (url) {
103102
NativeApp.openURLInDefaultBrowser(url);

0 commit comments

Comments
 (0)