jquery Source (3653, 3797) queue (): Queue method: Execution Order Management

Source: Internet
Author: User

//external Interfacejquery.extend ({queue:function(Elem, type, data) {//queue up. element, queue name, stored in function    //Jquery.queue (this, type, function (next, hooks) {})        varqueue; if(elem) {type= (Type | | "FX") + "queue";//do not write queue name is FX            //$.queue (document, ' Q1 ', aaa| | [AAA,BBB]); Queue = Data_priv.get (Elem, type);//Get method var cache = this.cache[This.key (elem)];return type = = = undefined? cache:cache[type];key method return unlock = elem[This.expando]; expando gets the 1,2,3,4 number in the cache in the Data_priv object based on the unique identity of the element, obtains the JSON in the cache according to the unlock number, Gets the value from the JSON according to the type            /*Data_priv = {1 (document.203089541586732714850=1): {name (type): ' Haha ' (queu e), Q1queue (type): ... (Queue array),}}*/            //dequeue by getting out quickly if the is just a lookup            if(data) {//Name of function                if(!queue | | jquery.isarray (DATA)) {//The queue has no (the function is not an array) or the queue has but the function is an array, note that the array will overwrite all previous.                     /*$.queue (document, ' Q1 ', AAA);                    $.queue (document, ' Q1 ', BBB);                    $.queue (document, ' Q1 ', [CCC]); */Queue=data_priv.access (Elem, type, Jquery.makearray (data)); } Else{//The queue has (stating that the Q1 queue was added before) and the function is not an array direct push, noting that the queue always has an array when the queue does not existQueue.push (data); }            }            returnQueue | | []; }}, Dequeue:function(Elem, type) {type= Type | | "FX";//can only write Jquery.queue (), cannot write queue (), queue () is a static method of the jquery class, can only be called by static means. /*Jquery.extend ({a:function () {alert (1)},b:function () {jquery.a ();}} ) $.b ();*/        varQueue = Jquery.queue (Elem, type),//get the value of type, is an array,Startlength =queue.length, FN= Queue.shift (),//removes the first array of arraysHooks =jquery._queuehooks (Elem, type), Next=function() {Jquery.dequeue (elem, type);//Next, can not directly write dequeue, this line of statement is not finished when dequeue does not exist            }; //If the FX queue is dequeued, always remove the Progress Sentinel        if(fn = = = "InProgress")) {fn=Queue.shift (); Startlength--; }        if(FN) {//Add A Progress Sentinel to prevent the FX queue from being            //automatically dequeued            if(Type = = = "FX") {Queue.unshift ("InProgress");//inprogress Add in            }            //Clear up the last queue stop function            DeleteHooks.stop; Fn.call (Elem, Next, hooks);//out of the team function execution,        }        if(!startlength &&hooks)        {Hooks.empty.fire (); }    },    /*Data_priv = {1 (elem:document.203089541586732714850=1): {name (type): ' Haha ' (queue), q1q Ueue (type): ... (Queue array),}}*/_queuehooks:function(Elem, type) {varKey = Type + "Queuehooks"; //If there is, there is no key,value. Value is a JSON append        returnData_priv.get (Elem, key) | |data_priv.access (Elem, Key, {empty:jQuery.Callbacks ("Once Memory"). Add (function() {data_priv.remove (Elem, [Type+ "Queue", key]);    })        }); }}); JQuery.fn.extend ({//this.queue (Type, function (next, hooks) {    //$ (' #div '). Queue (' Q1 ', BBB);Queuefunction(type, data) {varSetter = 2; //$ (' #div '). Queue (BBB);        if(typeofType!== "string") {//only one function was passed, no typedata =type; Type= "FX"; Setter--; }///console.log ($ (' #div '). Queue (' Q1 ')); View        if(Arguments.length <setter) {            returnJquery.queue ( This[0], type);//static method Invocation        }        returndata = = = undefined? This :             This. each (function() {//$ (' #div ') is an array, for each setting                varQueue = Jquery.queue ( This, type, data);//every one of them.                //ensure a hooks for the This queueJquery._queuehooks ( This, type); if(Type = = = "FX" && Queue[0]!== "InProgress") {Jquery.dequeue ( This, type);//the first team is then immediately out of the queue, calling                }            }); }, Dequeue:function(type) {return  This. each (function() {Jquery.dequeue ( This, type);//each of the team        }); },        //. Delay (in)    /*jQuery.fx.speeds = {slow:600, fast:200,//Default speed _default:400}; */    //jquery.fx = Tween.prototype.init;Delayfunction(time, type) { time= jquery.fx? jquery.fx.speeds[Time] | |Time:time; Type= Type | | "FX";//Queue The second parameter is an anonymous function, which is also added in        return  This. Queue (Type,function(Next, hooks) {varTimeout =SetTimeout (Next, time); Hooks.stop=function() {cleartimeout (timeout);        };    }); }, Clearqueue:function(type) {return  This. Queue (Type | | "FX", []);//an empty array is true    },    //after all the queues have been executed, callPromisefunction(type, obj) {vartmp, Count= 1, defer=jquery.deferred (), Elements= This, I= This. Length, Resolve=function() {                if( ! ( --count))                {Defer.resolvewith (elements, [elements]);        }            }; if(typeofType!== "string") {obj=type; Type=undefined; } type= Type | | "FX";  while(i--) {tmp= Data_priv.get (elements[i], type + "Queuehooks" ); if(TMP &&tmp.empty) {count++;            Tmp.empty.add (resolve);        }} resolve (); returndefer.promise (obj); }});

jquery Source (3653, 3797) queue (): Queue method: Execution Order Management

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.