Created
September 12, 2013 22:38
-
-
Save diestrin/6544755 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
waitFor: function (config) { | |
// Optional | |
var context = config.context || window, | |
interval = config.interval || 50, | |
timeOut = config.timeOut || 2000, | |
expire = config.expire || function(){}; | |
// Required | |
var varName = config.varName, | |
callback = config.callback; | |
// Local | |
var timeOutId, | |
expireId; | |
if (varName in context && !$.isEmptyObject(context[varName])) { | |
callback(context[varName]); | |
} else { | |
!function lookUp () { | |
timeOutId = setTimeout(function () { | |
if (varName in context && !$.isEmptyObject(context[varName])){ | |
callback(context[varName]); | |
clearTimeout(expireId); | |
} else { | |
lookUp(); | |
} | |
}, interval); | |
}(); | |
if (config.timeOut !== 0) | |
expireId = setTimeout(function () { | |
clearTimeout(timeOutId); | |
expire(); | |
}, timeOut); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment