| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 | 4 |
| 5 // <include src="assert.js"> | 5 // <include src="assert.js"> |
| 6 | 6 |
| 7 /** | 7 /** |
| 8 * Alias for document.getElementById. Found elements must be HTMLElements. | 8 * Alias for document.getElementById. Found elements must be HTMLElements. |
| 9 * @param {string} id The ID of the element to find. | 9 * @param {string} id The ID of the element to find. |
| 10 * @return {HTMLElement} The found element or null if not found. | 10 * @return {HTMLElement} The found element or null if not found. |
| (...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 205 * @return {!HTMLElement} the Element. | 205 * @return {!HTMLElement} the Element. |
| 206 */ | 206 */ |
| 207 function queryRequiredElement(selectors, opt_context) { | 207 function queryRequiredElement(selectors, opt_context) { |
| 208 var element = (opt_context || document).querySelector(selectors); | 208 var element = (opt_context || document).querySelector(selectors); |
| 209 return assertInstanceof(element, HTMLElement, | 209 return assertInstanceof(element, HTMLElement, |
| 210 'Missing required element: ' + selectors); | 210 'Missing required element: ' + selectors); |
| 211 } | 211 } |
| 212 | 212 |
| 213 // Handle click on a link. If the link points to a chrome: or file: url, then | 213 // Handle click on a link. If the link points to a chrome: or file: url, then |
| 214 // call into the browser to do the navigation. | 214 // call into the browser to do the navigation. |
| 215 document.addEventListener('click', function(e) { | 215 ['click', 'auxclick'].forEach(function(eventName) { |
| 216 if (e.defaultPrevented) | 216 document.addEventListener(eventName, function(e) { |
| 217 return; | 217 if (e.defaultPrevented) |
| 218 return; |
| 218 | 219 |
| 219 var eventPath = e.path; | 220 var eventPath = e.path; |
| 220 var anchor = null; | 221 var anchor = null; |
| 221 if (eventPath) { | 222 if (eventPath) { |
| 222 for (var i = 0; i < eventPath.length; i++) { | 223 for (var i = 0; i < eventPath.length; i++) { |
| 223 var element = eventPath[i]; | 224 var element = eventPath[i]; |
| 224 if (element.tagName === 'A' && element.href) { | 225 if (element.tagName === 'A' && element.href) { |
| 225 anchor = element; | 226 anchor = element; |
| 226 break; | 227 break; |
| 228 } |
| 227 } | 229 } |
| 228 } | 230 } |
| 229 } | |
| 230 | 231 |
| 231 // Fallback if Event.path is not available. | 232 // Fallback if Event.path is not available. |
| 232 var el = e.target; | 233 var el = e.target; |
| 233 if (!anchor && el.nodeType == Node.ELEMENT_NODE && | 234 if (!anchor && el.nodeType == Node.ELEMENT_NODE && |
| 234 el.webkitMatchesSelector('A, A *')) { | 235 el.webkitMatchesSelector('A, A *')) { |
| 235 while (el.tagName != 'A') { | 236 while (el.tagName != 'A') { |
| 236 el = el.parentElement; | 237 el = el.parentElement; |
| 238 } |
| 239 anchor = el; |
| 237 } | 240 } |
| 238 anchor = el; | |
| 239 } | |
| 240 | 241 |
| 241 if (!anchor) | 242 if (!anchor) |
| 242 return; | 243 return; |
| 243 | 244 |
| 244 anchor = /** @type {!HTMLAnchorElement} */(anchor); | 245 anchor = /** @type {!HTMLAnchorElement} */(anchor); |
| 245 if ((anchor.protocol == 'file:' || anchor.protocol == 'about:') && | 246 if ((anchor.protocol == 'file:' || anchor.protocol == 'about:') && |
| 246 (e.button == 0 || e.button == 1)) { | 247 (e.button == 0 || e.button == 1)) { |
| 247 chrome.send('navigateToUrl', [ | 248 chrome.send('navigateToUrl', [ |
| 248 anchor.href, | 249 anchor.href, |
| 249 anchor.target, | 250 anchor.target, |
| 250 e.button, | 251 e.button, |
| 251 e.altKey, | 252 e.altKey, |
| 252 e.ctrlKey, | 253 e.ctrlKey, |
| 253 e.metaKey, | 254 e.metaKey, |
| 254 e.shiftKey | 255 e.shiftKey |
| 255 ]); | 256 ]); |
| 256 e.preventDefault(); | 257 e.preventDefault(); |
| 257 } | 258 } |
| 259 }); |
| 258 }); | 260 }); |
| 259 | 261 |
| 260 /** | 262 /** |
| 261 * Creates a new URL which is the old URL with a GET param of key=value. | 263 * Creates a new URL which is the old URL with a GET param of key=value. |
| 262 * @param {string} url The base URL. There is not sanity checking on the URL so | 264 * @param {string} url The base URL. There is not sanity checking on the URL so |
| 263 * it must be passed in a proper format. | 265 * it must be passed in a proper format. |
| 264 * @param {string} key The key of the param. | 266 * @param {string} key The key of the param. |
| 265 * @param {string} value The value of the param. | 267 * @param {string} value The value of the param. |
| 266 * @return {string} The new URL. | 268 * @return {string} The new URL. |
| 267 */ | 269 */ |
| (...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 450 case 0xdb: return '['; | 452 case 0xdb: return '['; |
| 451 case 0xdd: return ']'; | 453 case 0xdd: return ']'; |
| 452 } | 454 } |
| 453 return 'Unidentified'; | 455 return 'Unidentified'; |
| 454 } | 456 } |
| 455 }); | 457 }); |
| 456 } else { | 458 } else { |
| 457 window.console.log("KeyboardEvent.Key polyfill not required"); | 459 window.console.log("KeyboardEvent.Key polyfill not required"); |
| 458 } | 460 } |
| 459 // </if> /* is_ios */ | 461 // </if> /* is_ios */ |
| OLD | NEW |