Instantly share code, notes, and snippets.

View clearTimeouts.js
// isolated layer wrapper (for the local variables)
(function(_W){
var cache = [], // will store all timeouts IDs
_set = _W.setTimeout, // save original reference
_clear = _W.clearTimeout; // save original reference
// Wrap original setTimeout with a function
_W.setTimeout = function( CB, duration, ...args ){
// also, wrap the callback, so the cache referece will be removed
View jquery.scrollTo.js
/**
* Scroll To / jQuery plugin (this plugin is written poorly)
* @author Yair Even Or
* @version 1.0.1 (April 3, 2013)
*/
(function($){
"use strict";
var root = $('html, body');
View events.namespace.js
var events = {
on(event, cb, opts){
if( !this.namespaces ) // save the namespaces on the DOM element itself
this.namespaces = {};
this.namespaces[event] = cb;
var options = opts || false;
this.addEventListener( event.split('.')[0], cb, options );
return this;
View easing.js
/*
* Easing Functions - inspired from http://gizma.com/easing/
* only considering the t value for the range [0, 1] => [0, 1]
*/
EasingFunctions = {
// no easing, no acceleration
linear: function (t) { return t },
// accelerating from zero velocity
easeInQuad: function (t) { return t*t },
// decelerating to zero velocity
View jQuery.toggle2classes.js
$.fn.toggle2classes = function(class1, class2){
if( !class1 || !class2 )
return this;
return this.each(function(){
var $elm = $(this);
if( $elm.hasClass(class1) || $elm.hasClass(class2) )
$elm.toggleClass(class1 +' '+ class2);
View jQuery.addTempClass.js
$.fn.addTempClass = function(tempClass, duration){
if( !tempClass )
return this;
return this.each(function(){
var $elm = $(this),
timer;
$elm.addClass(tempClass);
View lodash.formatBytes.js
_.mixin({
"formatBytes" : function(kiloBytes, decimals){
if(kiloBytes == 0) return ['0', 'KB'];
var k = 1024,
dm = decimals + 1 || 1,
sizes = ['KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'],
i = Math.floor(Math.log(kiloBytes) / Math.log(k));
return [parseFloat((kiloBytes / Math.pow(k, i)).toFixed(dm)).toLocaleString() , sizes[i]]; // parseFloat((bytes / Math.pow(k, i)).toFixed(dm)) + ' ' +
View dependencies.js
/**
* By - Yair Even-Or (2017) MIT license
* loads, using jQuery, dependency files.
* @param {Object} settings [files (Array), baseDir (String), sync (Boolean)]
* @return {Object} [promise]
*/
window.dependencies = {
/**
* @param {Object/Array} settings [either a "settings" object or a simple Array of files to load]
* @return {Object} [jQuery AJAX (promise)]
View jQuery.clickLimit.js
jQuery.event.special.clickLimit = {
delegateType: "mousedown",
bindType: "mousedown",
handle: function( event ) {
var handleObj = event.handleObj,
startTime = new Date().getTime(),
threshold = event.data.threshold || 500;
$(this)
.unbind('mouseup.clickLimit')
View jQuery.findClosest.js
// http://stackoverflow.com/a/29823718/104380
jQuery.fn.findClosest = function (selector) {
// If we have a :this selector
var output = $(),
down = this.find(selector),
siblings,
recSearch,
foundCount = 0;