Skip to content

Instantly share code, notes, and snippets.

@pcperini
Created July 9, 2020 15:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pcperini/ae956a8844df35eb2f34fd7b541021e1 to your computer and use it in GitHub Desktop.
Save pcperini/ae956a8844df35eb2f34fd7b541021e1 to your computer and use it in GitHub Desktop.
(function (e, f) {
var b = {};
var g = function (a) {
if(b[a]) {
f.clearInterval(b[a]);
b[a] = null;
};
};
e.fn.waitUntilExists = function (s, h, o, c) {
if(o == null || o == undefined) o = 0;
var d = e(s)
var k = d.not(function () {
return e(this).data("waitUntilExists.found");
});
if (h === "remove") {
g(s);
} else {
k.each(h).data("waitUntilExists.found", !0);
if (o && d.length) {
g(s);
}
else if (!c) {
b[s] = f.setInterval(function () {
console.log(s + " handler is running");
d.waitUntilExists(s, h, o, !0);
}, 500);
}
}
return d
}
})(jQuery, window);
jQuery.expr[':'].regex = function(elem, index, match) {
var matchParams = match[3].split(','),
validLabels = /^(data|css):/,
attr = {
method: matchParams[0].match(validLabels) ?
matchParams[0].split(':')[0] : 'attr',
property: matchParams.shift().replace(validLabels,'')
},
regexFlags = 'ig',
regex = new RegExp(matchParams.join('').replace(/^\s+|\s+$/g,''), regexFlags);
return regex.test(jQuery(elem)[attr.method](attr.property));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment