Dashboard sipadu mbip
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

yui-later-debug.js 2.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. /*
  2. Copyright (c) 2010, Yahoo! Inc. All rights reserved.
  3. Code licensed under the BSD License:
  4. http://developer.yahoo.com/yui/license.html
  5. version: 3.4.0
  6. build: nightly
  7. */
  8. YUI.add('yui-later', function(Y) {
  9. /**
  10. * Provides a setTimeout/setInterval wrapper. This module is a `core` YUI module, <a href="../classes/YUI.html#method_later">it's documentation is located under the YUI class</a>.
  11. *
  12. * @module yui
  13. * @submodule yui-later
  14. */
  15. var NO_ARGS = [];
  16. /**
  17. * Executes the supplied function in the context of the supplied
  18. * object 'when' milliseconds later. Executes the function a
  19. * single time unless periodic is set to true.
  20. * @for YUI
  21. * @method later
  22. * @param when {int} the number of milliseconds to wait until the fn
  23. * is executed.
  24. * @param o the context object.
  25. * @param fn {Function|String} the function to execute or the name of
  26. * the method in the 'o' object to execute.
  27. * @param data [Array] data that is provided to the function. This
  28. * accepts either a single item or an array. If an array is provided,
  29. * the function is executed with one parameter for each array item.
  30. * If you need to pass a single array parameter, it needs to be wrapped
  31. * in an array [myarray].
  32. *
  33. * Note: native methods in IE may not have the call and apply methods.
  34. * In this case, it will work, but you are limited to four arguments.
  35. *
  36. * @param periodic {boolean} if true, executes continuously at supplied
  37. * interval until canceled.
  38. * @return {object} a timer object. Call the cancel() method on this
  39. * object to stop the timer.
  40. */
  41. Y.later = function(when, o, fn, data, periodic) {
  42. when = when || 0;
  43. data = (!Y.Lang.isUndefined(data)) ? Y.Array(data) : NO_ARGS;
  44. o = o || Y.config.win || Y;
  45. var cancelled = false,
  46. method = (o && Y.Lang.isString(fn)) ? o[fn] : fn,
  47. wrapper = function() {
  48. // IE 8- may execute a setInterval callback one last time
  49. // after clearInterval was called, so in order to preserve
  50. // the cancel() === no more runny-run, we have to jump through
  51. // an extra hoop.
  52. if (!cancelled) {
  53. if (!method.apply) {
  54. method(data[0], data[1], data[2], data[3]);
  55. } else {
  56. method.apply(o, data || NO_ARGS);
  57. }
  58. }
  59. },
  60. id = (periodic) ? setInterval(wrapper, when) : setTimeout(wrapper, when);
  61. return {
  62. id: id,
  63. interval: periodic,
  64. cancel: function() {
  65. cancelled = true;
  66. if (this.interval) {
  67. clearInterval(id);
  68. } else {
  69. clearTimeout(id);
  70. }
  71. }
  72. };
  73. };
  74. Y.Lang.later = Y.later;
  75. }, '3.4.0' ,{requires:['yui-base']});