I've got some code that I want to run when certain HTML elements are added to the page.
To do this, I have a "runOnRender" function:
runOnRender: function (func, args, interval) {
var that = this;
var guid = hb.getGuid().substr(0,7);
var checkFunc = function () {
if (that.$el.height() > 0 && that.$el.width() > 0) {
clearInterval(that[guid]);
that[guid] = 0;
func.call(that, args);
}
};
this[guid] = setInterval(checkFunc, interval || 200);
}
Setting the interval to 200 is about as high as I can go before there is often a noticeable lag in the event firing. The last thing I want is my users wondering why a button just got clicked or seeing a label text change, etc.
Here's the catch. It is entirely possible that this "runOnRender" will be set up.....but the User never causes the action that makes the HTML element in question hit the DOM....which means that this code would just keep infinitely running as long as the page is open.
I'm on a nice, powerful, dev machine....so I'm wondering what the cost of this code is and whether there is a better way.