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 272 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
283 * @param {string} className The class name to use. | 283 * @param {string} className The class name to use. |
284 * @return {Element} The created element. | 284 * @return {Element} The created element. |
285 */ | 285 */ |
286 function createElementWithClassName(type, className) { | 286 function createElementWithClassName(type, className) { |
287 var elm = document.createElement(type); | 287 var elm = document.createElement(type); |
288 elm.className = className; | 288 elm.className = className; |
289 return elm; | 289 return elm; |
290 } | 290 } |
291 | 291 |
292 /** | 292 /** |
293 * webkitTransitionEnd does not always fire (e.g. when animation is aborted | 293 * transitionend does not always fire (e.g. when animation is aborted |
294 * or when no paint happens during the animation). This function sets up | 294 * or when no paint happens during the animation). This function sets up |
295 * a timer and emulate the event if it is not fired when the timer expires. | 295 * a timer and emulate the event if it is not fired when the timer expires. |
296 * @param {!HTMLElement} el The element to watch for webkitTransitionEnd. | 296 * @param {!HTMLElement} el The element to watch for transitionend. |
297 * @param {number=} opt_timeOut The maximum wait time in milliseconds for the | 297 * @param {number=} opt_timeOut The maximum wait time in milliseconds for the |
298 * webkitTransitionEnd to happen. If not specified, it is fetched from |el| | 298 * transitionend to happen. If not specified, it is fetched from |el| |
299 * using the transitionDuration style value. | 299 * using the transitionDuration style value. |
300 */ | 300 */ |
301 function ensureTransitionEndEvent(el, opt_timeOut) { | 301 function ensureTransitionEndEvent(el, opt_timeOut) { |
302 if (opt_timeOut === undefined) { | 302 if (opt_timeOut === undefined) { |
303 var style = getComputedStyle(el); | 303 var style = getComputedStyle(el); |
304 opt_timeOut = parseFloat(style.transitionDuration) * 1000; | 304 opt_timeOut = parseFloat(style.transitionDuration) * 1000; |
305 | 305 |
306 // Give an additional 50ms buffer for the animation to complete. | 306 // Give an additional 50ms buffer for the animation to complete. |
307 opt_timeOut += 50; | 307 opt_timeOut += 50; |
308 } | 308 } |
309 | 309 |
310 var fired = false; | 310 var fired = false; |
311 el.addEventListener('webkitTransitionEnd', function f(e) { | 311 el.addEventListener('transitionend', function f(e) { |
312 el.removeEventListener('webkitTransitionEnd', f); | 312 el.removeEventListener('transitionend', f); |
313 fired = true; | 313 fired = true; |
314 }); | 314 }); |
315 window.setTimeout(function() { | 315 window.setTimeout(function() { |
316 if (!fired) | 316 if (!fired) |
317 cr.dispatchSimpleEvent(el, 'webkitTransitionEnd', true); | 317 cr.dispatchSimpleEvent(el, 'transitionend', true); |
318 }, opt_timeOut); | 318 }, opt_timeOut); |
319 } | 319 } |
320 | 320 |
321 /** | 321 /** |
322 * Alias for document.scrollTop getter. | 322 * Alias for document.scrollTop getter. |
323 * @param {!HTMLDocument} doc The document node where information will be | 323 * @param {!HTMLDocument} doc The document node where information will be |
324 * queried from. | 324 * queried from. |
325 * @return {number} The Y document scroll offset. | 325 * @return {number} The Y document scroll offset. |
326 */ | 326 */ |
327 function scrollTopForDocument(doc) { | 327 function scrollTopForDocument(doc) { |
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
493 * @param {!Array<string>} moduleNames | 493 * @param {!Array<string>} moduleNames |
494 * @return {!Promise} | 494 * @return {!Promise} |
495 */ | 495 */ |
496 function importModules(moduleNames) { | 496 function importModules(moduleNames) { |
497 return new Promise(function(resolve) { | 497 return new Promise(function(resolve) { |
498 define(moduleNames, function() { | 498 define(moduleNames, function() { |
499 resolve(Array.from(arguments)); | 499 resolve(Array.from(arguments)); |
500 }); | 500 }); |
501 }); | 501 }); |
502 } | 502 } |
OLD | NEW |