Commit daf9ba75 authored by dbeam@chromium.org's avatar dbeam@chromium.org

[extensions] Don't let clicks on <a href="#"> links escape un-prevented.

Also adds the utility to stop clicks on any page to util.js and makes the NTP a
user of this function.

BUG=136338
TEST=Inspect a background view, options, or reload an extension while scrolled
without being forced to the top of the page.

Review URL: https://chromiumcodereview.appspot.com/10832196

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@151127 0039d316-1c4b-4281-b951-d872f2087c98
parent fde874c7
...@@ -18,6 +18,7 @@ ...@@ -18,6 +18,7 @@
<script src="chrome://resources/js/util.js"></script> <script src="chrome://resources/js/util.js"></script>
<script src="chrome://resources/js/cr/ui.js"></script> <script src="chrome://resources/js/cr/ui.js"></script>
<script src="chrome://resources/js/cr/ui/alert_overlay.js"></script> <script src="chrome://resources/js/cr/ui/alert_overlay.js"></script>
<script src="chrome://resources/js/cr/ui/drag_wrapper.js"></script>
<script src="chrome://resources/js/cr/ui/focus_manager.js"></script> <script src="chrome://resources/js/cr/ui/focus_manager.js"></script>
<script src="chrome://resources/js/cr/ui/overlay.js"></script> <script src="chrome://resources/js/cr/ui/overlay.js"></script>
......
...@@ -2,7 +2,6 @@ ...@@ -2,7 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
<include src="../shared/js/cr/ui/drag_wrapper.js"></include>
<include src="../uber/uber_utils.js"></include> <include src="../uber/uber_utils.js"></include>
<include src="extension_commands_overlay.js"></include> <include src="extension_commands_overlay.js"></include>
<include src="extension_focus_manager.js"></include> <include src="extension_focus_manager.js"></include>
...@@ -116,6 +115,8 @@ cr.define('extensions', function() { ...@@ -116,6 +115,8 @@ cr.define('extensions', function() {
cr.ui.overlay.setupOverlay($('dropTargetOverlay')); cr.ui.overlay.setupOverlay($('dropTargetOverlay'));
extensions.ExtensionFocusManager.getInstance().initialize(); extensions.ExtensionFocusManager.getInstance().initialize();
preventDefaultOnPoundLinkClicks(); // From shared/js/util.js.
}, },
/** /**
...@@ -151,7 +152,6 @@ cr.define('extensions', function() { ...@@ -151,7 +152,6 @@ cr.define('extensions', function() {
ExtensionSettings.showOverlay($('extensionCommandsOverlay')); ExtensionSettings.showOverlay($('extensionCommandsOverlay'));
chrome.send('coreOptionsUserMetricsAction', chrome.send('coreOptionsUserMetricsAction',
['Options_ExtensionCommands']); ['Options_ExtensionCommands']);
e.preventDefault();
}, },
/** /**
......
...@@ -212,6 +212,8 @@ cr.define('ntp', function() { ...@@ -212,6 +212,8 @@ cr.define('ntp', function() {
cr.dispatchSimpleEvent(document, 'ntpLoaded', true, true); cr.dispatchSimpleEvent(document, 'ntpLoaded', true, true);
document.documentElement.classList.remove('starting-up'); document.documentElement.classList.remove('starting-up');
}); });
preventDefaultOnPoundLinkClicks(); // From shared/js/util.js.
} }
/** /**
......
...@@ -128,6 +128,17 @@ function disableTextSelectAndDrag(opt_allowSelectStart, opt_allowDragStart) { ...@@ -128,6 +128,17 @@ function disableTextSelectAndDrag(opt_allowSelectStart, opt_allowDragStart) {
}; };
} }
/**
* Call this to stop clicks on <a href="#"> links from scrolling to the top of
* the page (and possibly showing a # in the link).
*/
function preventDefaultOnPoundLinkClicks() {
document.addEventListener('click', function(e) {
if (e.target.nodeName == 'A' && e.target.getAttribute('href') == '#')
e.preventDefault();
});
}
/** /**
* Check the directionality of the page. * Check the directionality of the page.
* @return {boolean} True if Chrome is running an RTL UI. * @return {boolean} True if Chrome is running an RTL UI.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment