Skip to content

Instantly share code, notes, and snippets.

@tytskyi
tytskyi / add jQuery to the page.js
Last active August 29, 2015 14:01
Copy-paste to console
(function (global) {
var script = document.createElement('script');
script.src = "http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js";
script.onload = function () {
global.myQuery = global.jQuery.noConflict();
console.log('jQuery has been loaded');
};
global.document.getElementsByTagName('head')[0].appendChild(script);
})(window);
@tytskyi
tytskyi / $.scrollbarWidth.js
Created January 24, 2014 18:34
Extend jQuery with `scrollbarWidth` property.
(function ($) {
var scrollDiv = document.createElement("div");
scrollDiv.style.width = "100px";
scrollDiv.style.height = "100px";
scrollDiv.style.position = "absolute";
scrollDiv.style.top = "-9999px";
scrollDiv.style.overflow= "scroll";
document.body.appendChild(scrollDiv);
@tytskyi
tytskyi / wait.js
Last active January 3, 2016 14:18
wait = function (data) {
var check, context, fail, freq, isResetFunction, reset, resetAllTimers, success, timers, waitInner;
timers = {};
resetAllTimers = function () {
clearTimeout(timers.timer);
return clearTimeout(timers.resetTimer);
};
check = data.check || null;
freq = data.frequency || data.freq || 0;
reset = data.reset || null;
(function ($) {
var ids = [],
sorted = [],
repeated = [];
$('[id]').each(function () {
ids.push(this.id);
});
var sorted = ids.sort();
$.expr[':'].closest = function (elem, index, match) {
return $(elem).closest(match[3]).length;
};
$.expr[':'].containsInsensitive = function (elem, index, match) {
return $(elem).text().toLowerCase().indexOf(match[3].toLowerCase()) > -1;
};