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.

queue-promote.js 1.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  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('queue-promote', function(Y) {
  9. /**
  10. * Adds methods promote, remove, and indexOf to Queue instances.
  11. *
  12. * @module queue-promote
  13. * @for Queue
  14. */
  15. Y.mix(Y.Queue.prototype, {
  16. /**
  17. * Returns the current index in the queue of the specified item
  18. *
  19. * @method indexOf
  20. * @param needle {MIXED} the item to search for
  21. * @return {Number} the index of the item or -1 if not found
  22. */
  23. indexOf : function (callback) {
  24. return Y.Array.indexOf(this._q, callback);
  25. },
  26. /**
  27. * Moves the referenced item to the head of the queue
  28. *
  29. * @method promote
  30. * @param item {MIXED} an item in the queue
  31. */
  32. promote : function (callback) {
  33. var index = this.indexOf(callback);
  34. if (index > -1) {
  35. this._q.unshift(this._q.splice(index,1)[0]);
  36. }
  37. },
  38. /**
  39. * Removes the referenced item from the queue
  40. *
  41. * @method remove
  42. * @param item {MIXED} an item in the queue
  43. */
  44. remove : function (callback) {
  45. var index = this.indexOf(callback);
  46. if (index > -1) {
  47. this._q.splice(index,1);
  48. }
  49. }
  50. });
  51. }, '3.4.0' ,{requires:['yui-base']});