Last active
April 15, 2016 00:45
-
-
Save nathanaelnsmith/1027c49637045d0a0b33fe265ac176ae to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* Author: Nathanael Smith | |
* Description: This module stores functions in a run queue until they're needed to be executed. | |
*/ | |
var ExeQue = (function(){ | |
function store (location, func) { | |
var queue = getQueue(location).concat(func); | |
if (location instanceof jQuery) { | |
location.data('ExeQue', queue); | |
} else { | |
location.ExeQue = queue; | |
} | |
return queue; | |
} | |
function execute (location) { | |
var queue = getQueue(location); | |
for(var i = 0; i < queue.length; i++) { | |
queue[i](); | |
} | |
deleteQueue(location); | |
return true; | |
} | |
function getQueue (location) { | |
return (location instanceof jQuery ? location.data('ExeQue') : location.ExeQue) || []; | |
} | |
function deleteQueue (location) { | |
if (location instanceof jQuery) { | |
$.removeData(location, 'ExeQue'); | |
} else { | |
delete location.ExeQue; | |
} | |
} | |
return { | |
store: store, | |
execute: execute | |
} | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment