JSFiddle - React, Tailwind, and code Playground
by amindunited
JavaScript
function betshopQueue(option) {
var fn = function(){};
var qArray = [];//An array of items to be queued, or q'd if you are spelling lazily
var running = false;//Boolean to mark while the queue is being processed
var callBack = callBack;
var paused = false;
var parent = this;
var methods = {
proccessQueue: function() {
running = true;//Flag this function as running
//If there are items in the queue ... proccess them
if (qArray.length > 0) {
//Make sure that we have a function to apply, before we try to apply it
if (typeof callBack === "function") {
callBack.apply(parent, [qArray[0], taskComplete]);
}
} else {
running = false;
console.log("The queue is now empty ");
}
},
pause: function(){
console.log("you called pause");
}
}
console.log("arguments[0]", arguments[0]);
if (methods[arguments[0]]) {
console.log(methods[arguments[0]]);
} else if (typeof arguments[0] === "function") {
fn = arguments[0];
console.log('added function');
} else {
qArray.push(arguments);
//if the queue isn't currently being proccessed...start it
if (running === false) {
proccessQueue();
}
}
};
//SOF Second queue Example
var n3r = new betshopQueue( function (queueItem, taskComplete) {
//console.log("I am the passed function my parent has the item ", thing, this, qArray);
$.getJSON(
"http://picasaweb.google.com/data/feed/api/user/buckley.robin/albumid/5751950773409336513" + '' +'?alt=json&thumbsize=' + '50' ,
function(data){
$('<img></img>').attr('src', queueItem).appendTo('body');
taskComplete();//YOU MUST CALL THIS WHEN YOUR TASK IS COMPLETE
});
});
console.log("n3r",...