| 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 356 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 367 var elm = document.createElement(type); | 367 var elm = document.createElement(type); |
| 368 elm.className = className; | 368 elm.className = className; |
| 369 return elm; | 369 return elm; |
| 370 } | 370 } |
| 371 | 371 |
| 372 /** | 372 /** |
| 373 * webkitTransitionEnd does not always fire (e.g. when animation is aborted | 373 * webkitTransitionEnd does not always fire (e.g. when animation is aborted |
| 374 * or when no paint happens during the animation). This function sets up | 374 * or when no paint happens during the animation). This function sets up |
| 375 * a timer and emulate the event if it is not fired when the timer expires. | 375 * a timer and emulate the event if it is not fired when the timer expires. |
| 376 * @param {!HTMLElement} el The element to watch for webkitTransitionEnd. | 376 * @param {!HTMLElement} el The element to watch for webkitTransitionEnd. |
| 377 * @param {number} timeOut The maximum wait time in milliseconds for the | 377 * @param {number=} opt_timeOut The maximum wait time in milliseconds for the |
| 378 * webkitTransitionEnd to happen. | 378 * webkitTransitionEnd to happen. If not specified, it is fetched from |el| |
| 379 * using the transitionDuration style value. |
| 379 */ | 380 */ |
| 380 function ensureTransitionEndEvent(el, timeOut) { | 381 function ensureTransitionEndEvent(el, opt_timeOut) { |
| 382 if (opt_timeOut === undefined) { |
| 383 var style = getComputedStyle(el); |
| 384 opt_timeOut = parseFloat(style.transitionDuration) * 1000; |
| 385 |
| 386 // Give an additional 50ms buffer for the animation to complete. |
| 387 opt_timeOut += 50; |
| 388 } |
| 389 |
| 381 var fired = false; | 390 var fired = false; |
| 382 el.addEventListener('webkitTransitionEnd', function f(e) { | 391 el.addEventListener('webkitTransitionEnd', function f(e) { |
| 383 el.removeEventListener('webkitTransitionEnd', f); | 392 el.removeEventListener('webkitTransitionEnd', f); |
| 384 fired = true; | 393 fired = true; |
| 385 }); | 394 }); |
| 386 window.setTimeout(function() { | 395 window.setTimeout(function() { |
| 387 if (!fired) | 396 if (!fired) |
| 388 cr.dispatchSimpleEvent(el, 'webkitTransitionEnd', true); | 397 cr.dispatchSimpleEvent(el, 'webkitTransitionEnd', true); |
| 389 }, timeOut); | 398 }, opt_timeOut); |
| 390 } | 399 } |
| 391 | 400 |
| 392 /** | 401 /** |
| 393 * Alias for document.scrollTop getter. | 402 * Alias for document.scrollTop getter. |
| 394 * @param {!HTMLDocument} doc The document node where information will be | 403 * @param {!HTMLDocument} doc The document node where information will be |
| 395 * queried from. | 404 * queried from. |
| 396 * @return {number} The Y document scroll offset. | 405 * @return {number} The Y document scroll offset. |
| 397 */ | 406 */ |
| 398 function scrollTopForDocument(doc) { | 407 function scrollTopForDocument(doc) { |
| 399 return doc.documentElement.scrollTop || doc.body.scrollTop; | 408 return doc.documentElement.scrollTop || doc.body.scrollTop; |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 458 } | 467 } |
| 459 | 468 |
| 460 /** | 469 /** |
| 461 * Quote a string so it can be used in a regular expression. | 470 * Quote a string so it can be used in a regular expression. |
| 462 * @param {string} str The source string. | 471 * @param {string} str The source string. |
| 463 * @return {string} The escaped string. | 472 * @return {string} The escaped string. |
| 464 */ | 473 */ |
| 465 function quoteString(str) { | 474 function quoteString(str) { |
| 466 return str.replace(/([\\\.\+\*\?\[\^\]\$\(\)\{\}\=\!\<\>\|\:])/g, '\\$1'); | 475 return str.replace(/([\\\.\+\*\?\[\^\]\$\(\)\{\}\=\!\<\>\|\:])/g, '\\$1'); |
| 467 } | 476 } |
| OLD | NEW |