| 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 267 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 278 * @param {string} className The class name to use. | 278 * @param {string} className The class name to use. |
| 279 * @return {Element} The created element. | 279 * @return {Element} The created element. |
| 280 */ | 280 */ |
| 281 function createElementWithClassName(type, className) { | 281 function createElementWithClassName(type, className) { |
| 282 var elm = document.createElement(type); | 282 var elm = document.createElement(type); |
| 283 elm.className = className; | 283 elm.className = className; |
| 284 return elm; | 284 return elm; |
| 285 } | 285 } |
| 286 | 286 |
| 287 /** | 287 /** |
| 288 * webkitTransitionEnd does not always fire (e.g. when animation is aborted | 288 * transitionend does not always fire (e.g. when animation is aborted |
| 289 * or when no paint happens during the animation). This function sets up | 289 * or when no paint happens during the animation). This function sets up |
| 290 * a timer and emulate the event if it is not fired when the timer expires. | 290 * a timer and emulate the event if it is not fired when the timer expires. |
| 291 * @param {!HTMLElement} el The element to watch for webkitTransitionEnd. | 291 * @param {!HTMLElement} el The element to watch for transitionend. |
| 292 * @param {number=} opt_timeOut The maximum wait time in milliseconds for the | 292 * @param {number=} opt_timeOut The maximum wait time in milliseconds for the |
| 293 * webkitTransitionEnd to happen. If not specified, it is fetched from |el| | 293 * transitionend to happen. If not specified, it is fetched from |el| |
| 294 * using the transitionDuration style value. | 294 * using the transitionDuration style value. |
| 295 */ | 295 */ |
| 296 function ensureTransitionEndEvent(el, opt_timeOut) { | 296 function ensureTransitionEndEvent(el, opt_timeOut) { |
| 297 if (opt_timeOut === undefined) { | 297 if (opt_timeOut === undefined) { |
| 298 var style = getComputedStyle(el); | 298 var style = getComputedStyle(el); |
| 299 opt_timeOut = parseFloat(style.transitionDuration) * 1000; | 299 opt_timeOut = parseFloat(style.transitionDuration) * 1000; |
| 300 | 300 |
| 301 // Give an additional 50ms buffer for the animation to complete. | 301 // Give an additional 50ms buffer for the animation to complete. |
| 302 opt_timeOut += 50; | 302 opt_timeOut += 50; |
| 303 } | 303 } |
| 304 | 304 |
| 305 var fired = false; | 305 var fired = false; |
| 306 el.addEventListener('webkitTransitionEnd', function f(e) { | 306 el.addEventListener('transitionend', function f(e) { |
| 307 el.removeEventListener('webkitTransitionEnd', f); | 307 el.removeEventListener('transitionend', f); |
| 308 fired = true; | 308 fired = true; |
| 309 }); | 309 }); |
| 310 window.setTimeout(function() { | 310 window.setTimeout(function() { |
| 311 if (!fired) | 311 if (!fired) |
| 312 cr.dispatchSimpleEvent(el, 'webkitTransitionEnd', true); | 312 cr.dispatchSimpleEvent(el, 'transitionend', true); |
| 313 }, opt_timeOut); | 313 }, opt_timeOut); |
| 314 } | 314 } |
| 315 | 315 |
| 316 /** | 316 /** |
| 317 * Alias for document.scrollTop getter. | 317 * Alias for document.scrollTop getter. |
| 318 * @param {!HTMLDocument} doc The document node where information will be | 318 * @param {!HTMLDocument} doc The document node where information will be |
| 319 * queried from. | 319 * queried from. |
| 320 * @return {number} The Y document scroll offset. | 320 * @return {number} The Y document scroll offset. |
| 321 */ | 321 */ |
| 322 function scrollTopForDocument(doc) { | 322 function scrollTopForDocument(doc) { |
| (...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 531 }); | 531 }); |
| 532 } | 532 } |
| 533 | 533 |
| 534 /** | 534 /** |
| 535 * @param {!Event} e | 535 * @param {!Event} e |
| 536 * @return {boolean} Whether a modifier key was down when processing |e|. | 536 * @return {boolean} Whether a modifier key was down when processing |e|. |
| 537 */ | 537 */ |
| 538 function hasKeyModifiers(e) { | 538 function hasKeyModifiers(e) { |
| 539 return !!(e.altKey || e.ctrlKey || e.metaKey || e.shiftKey); | 539 return !!(e.altKey || e.ctrlKey || e.metaKey || e.shiftKey); |
| 540 } | 540 } |
| OLD | NEW |