API Docs for: 3.13.0
Show:

File: queue-promote/js/queue-promote.js

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