/1.4/api/source/queue.html
HTML | 108 lines | 94 code | 14 blank | 0 comment | 0 complexity | 0c95cc233b3b58887ffa2a171ba029e4 MD5 | raw file
- <!DOCTYPE html>
- <html>
- <head>
- <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
- <title>The source code</title>
- <link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />
- <script type="text/javascript" src="../resources/prettify/prettify.js"></script>
- <style type="text/css">
- .highlight { display: block; background-color: #ddd; }
- </style>
- <script type="text/javascript">
- function highlight() {
- document.getElementById(location.hash.replace(/#/, "")).className = "highlight";
- }
- </script>
- </head>
- <body onload="prettyPrint(); highlight();">
- <pre class="prettyprint lang-js"><span id='global-property-'>/**
- </span> * @ignore queue data structure
- * @author yiminghe@gmail.com
- */
- KISSY.add('anim/base/queue', function (S, Dom) {
- var // 队列集合容器
- queueCollectionKey = S.guid('ks-queue-' + S.now() + '-'),
- // 默认队列
- queueKey = S.guid('ks-queue-' + S.now() + '-'),
- Q;
- function getQueue(node, name, readOnly) {
- name = name || queueKey;
- var qu,
- quCollection = Dom.data(node, queueCollectionKey);
- if (!quCollection && !readOnly) {
- Dom.data(node, queueCollectionKey, quCollection = {});
- }
- if (quCollection) {
- qu = quCollection[name];
- if (!qu && !readOnly) {
- qu = quCollection[name] = [];
- }
- }
- return qu;
- }
- return Q = {
- queueCollectionKey: queueCollectionKey,
- queue: function (node, queue, item) {
- var qu = getQueue(node, queue);
- qu.push(item);
- return qu;
- },
- remove: function (node, queue, item) {
- var qu = getQueue(node, queue, 1),
- index;
- if (qu) {
- index = S.indexOf(item, qu);
- if (index > -1) {
- qu.splice(index, 1);
- }
- }
- if (qu && !qu.length) {
- // remove queue data
- Q.clearQueue(node, queue);
- }
- return qu;
- },
- 'clearQueues': function (node) {
- Dom.removeData(node, queueCollectionKey);
- },
- clearQueue: function clearQueue(node, queue) {
- queue = queue || queueKey;
- var quCollection = Dom.data(node, queueCollectionKey);
- if (quCollection) {
- delete quCollection[queue];
- }
- if (S.isEmptyObject(quCollection)) {
- Dom.removeData(node, queueCollectionKey);
- }
- },
- dequeue: function (node, queue) {
- var qu = getQueue(node, queue, 1);
- if (qu) {
- qu.shift();
- if (!qu.length) {
- // remove queue data
- Q.clearQueue(node, queue);
- }
- }
- return qu;
- }
- };
- }, {
- requires: ['dom']
- });</pre>
- </body>
- </html>