PageRenderTime 44ms CodeModel.GetById 21ms RepoModel.GetById 1ms app.codeStats 0ms

/1.4/api/source/queue.html

https://github.com/yiminghe/kissyteam.github.com
HTML | 108 lines | 94 code | 14 blank | 0 comment | 0 complexity | 0c95cc233b3b58887ffa2a171ba029e4 MD5 | raw file
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  5. <title>The source code</title>
  6. <link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />
  7. <script type="text/javascript" src="../resources/prettify/prettify.js"></script>
  8. <style type="text/css">
  9. .highlight { display: block; background-color: #ddd; }
  10. </style>
  11. <script type="text/javascript">
  12. function highlight() {
  13. document.getElementById(location.hash.replace(/#/, "")).className = "highlight";
  14. }
  15. </script>
  16. </head>
  17. <body onload="prettyPrint(); highlight();">
  18. <pre class="prettyprint lang-js"><span id='global-property-'>/**
  19. </span> * @ignore queue data structure
  20. * @author yiminghe@gmail.com
  21. */
  22. KISSY.add('anim/base/queue', function (S, Dom) {
  23. var // 队列集合容器
  24. queueCollectionKey = S.guid('ks-queue-' + S.now() + '-'),
  25. // 默认队列
  26. queueKey = S.guid('ks-queue-' + S.now() + '-'),
  27. Q;
  28. function getQueue(node, name, readOnly) {
  29. name = name || queueKey;
  30. var qu,
  31. quCollection = Dom.data(node, queueCollectionKey);
  32. if (!quCollection &amp;&amp; !readOnly) {
  33. Dom.data(node, queueCollectionKey, quCollection = {});
  34. }
  35. if (quCollection) {
  36. qu = quCollection[name];
  37. if (!qu &amp;&amp; !readOnly) {
  38. qu = quCollection[name] = [];
  39. }
  40. }
  41. return qu;
  42. }
  43. return Q = {
  44. queueCollectionKey: queueCollectionKey,
  45. queue: function (node, queue, item) {
  46. var qu = getQueue(node, queue);
  47. qu.push(item);
  48. return qu;
  49. },
  50. remove: function (node, queue, item) {
  51. var qu = getQueue(node, queue, 1),
  52. index;
  53. if (qu) {
  54. index = S.indexOf(item, qu);
  55. if (index &gt; -1) {
  56. qu.splice(index, 1);
  57. }
  58. }
  59. if (qu &amp;&amp; !qu.length) {
  60. // remove queue data
  61. Q.clearQueue(node, queue);
  62. }
  63. return qu;
  64. },
  65. 'clearQueues': function (node) {
  66. Dom.removeData(node, queueCollectionKey);
  67. },
  68. clearQueue: function clearQueue(node, queue) {
  69. queue = queue || queueKey;
  70. var quCollection = Dom.data(node, queueCollectionKey);
  71. if (quCollection) {
  72. delete quCollection[queue];
  73. }
  74. if (S.isEmptyObject(quCollection)) {
  75. Dom.removeData(node, queueCollectionKey);
  76. }
  77. },
  78. dequeue: function (node, queue) {
  79. var qu = getQueue(node, queue, 1);
  80. if (qu) {
  81. qu.shift();
  82. if (!qu.length) {
  83. // remove queue data
  84. Q.clearQueue(node, queue);
  85. }
  86. }
  87. return qu;
  88. }
  89. };
  90. }, {
  91. requires: ['dom']
  92. });</pre>
  93. </body>
  94. </html>