From 2cbb7190e5e9a1a6dca31b0ec50538efe6938f3e Mon Sep 17 00:00:00 2001 From: Scott Miles Date: Fri, 12 Oct 2012 13:43:35 -0700 Subject: [PATCH] define a utility object to store helper APIs, add 'job' API to utilities --- src/g-component.html | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/src/g-component.html b/src/g-component.html index 0278f36e..d7001022 100644 --- a/src/g-component.html +++ b/src/g-component.html @@ -92,6 +92,26 @@ license that can be found in the LICENSE file. var $ = document.querySelector.bind(document); + // utility methods + + var job = function(inJobName, inJob, inWait) { + job.stop(inJobName); + job._jobs[inJobName] = setTimeout(function() { + job.stop(inJobName); + inJob(); + }, inWait); + }; + job.stop = function(inJobName) { + if (job._jobs[inJobName]) { + clearTimeout(job._jobs[inJobName]); + delete job._jobs[inJobName]; + } + }; + job._jobs = {}; + + var utils = { + job: job + }; var nodeIterator = function(inNodes, inFn) { if (inNodes) { for (var i=0, n; (n=inNodes[i]); i++) {