| 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 el = e.target; | 220 var el = e.target; |
| 220 if (el.nodeType == Node.ELEMENT_NODE && | 221 if (el.nodeType == Node.ELEMENT_NODE && |
| 221 el.webkitMatchesSelector('A, A *')) { | 222 el.webkitMatchesSelector('A, A *')) { |
| 222 while (el.tagName != 'A') { | 223 while (el.tagName != 'A') { |
| 223 el = el.parentElement; | 224 el = el.parentElement; |
| 225 } |
| 226 |
| 227 if ((el.protocol == 'file:' || el.protocol == 'about:') && |
| 228 (e.button == 0 || e.button == 1)) { |
| 229 chrome.send('navigateToUrl', [ |
| 230 el.href, |
| 231 el.target, |
| 232 e.button, |
| 233 e.altKey, |
| 234 e.ctrlKey, |
| 235 e.metaKey, |
| 236 e.shiftKey |
| 237 ]); |
| 238 e.preventDefault(); |
| 239 } |
| 224 } | 240 } |
| 225 | 241 }); |
| 226 if ((el.protocol == 'file:' || el.protocol == 'about:') && | |
| 227 (e.button == 0 || e.button == 1)) { | |
| 228 chrome.send('navigateToUrl', [ | |
| 229 el.href, | |
| 230 el.target, | |
| 231 e.button, | |
| 232 e.altKey, | |
| 233 e.ctrlKey, | |
| 234 e.metaKey, | |
| 235 e.shiftKey | |
| 236 ]); | |
| 237 e.preventDefault(); | |
| 238 } | |
| 239 } | |
| 240 }); | 242 }); |
| 241 | 243 |
| 242 /** | 244 /** |
| 243 * Creates a new URL which is the old URL with a GET param of key=value. | 245 * Creates a new URL which is the old URL with a GET param of key=value. |
| 244 * @param {string} url The base URL. There is not sanity checking on the URL so | 246 * @param {string} url The base URL. There is not sanity checking on the URL so |
| 245 * it must be passed in a proper format. | 247 * it must be passed in a proper format. |
| 246 * @param {string} key The key of the param. | 248 * @param {string} key The key of the param. |
| 247 * @param {string} value The value of the param. | 249 * @param {string} value The value of the param. |
| 248 * @return {string} The new URL. | 250 * @return {string} The new URL. |
| 249 */ | 251 */ |
| (...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 432 case 0xdb: return '['; | 434 case 0xdb: return '['; |
| 433 case 0xdd: return ']'; | 435 case 0xdd: return ']'; |
| 434 } | 436 } |
| 435 return 'Unidentified'; | 437 return 'Unidentified'; |
| 436 } | 438 } |
| 437 }); | 439 }); |
| 438 } else { | 440 } else { |
| 439 window.console.log("KeyboardEvent.Key polyfill not required"); | 441 window.console.log("KeyboardEvent.Key polyfill not required"); |
| 440 } | 442 } |
| 441 // </if> /* is_ios */ | 443 // </if> /* is_ios */ |
| OLD | NEW |