Last active
November 9, 2016 09:32
-
-
Save fzed51/5a4d37d4c91523a8a3ba to your computer and use it in GitHub Desktop.
Tools JavaScript
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
var Q = function(querry){ | |
return document.querySelector(querry); | |
}; | |
var Qs = function(querry){ | |
querry=document.querySelectorAll(querry); | |
querry.forEach||(querry=Array.from(querry)); | |
return querry; | |
}; | |
var SE = function(item){ | |
return item.parentNode.removeChild(item); | |
}; | |
var NE = function(tag, id, classe){ | |
var item = document.createElement(tag); | |
if(id){ | |
item.setAttribute('id',id); | |
} | |
if(classe){ | |
item.className=classe; | |
} | |
return item; | |
}; | |
var Ap = function(Parent, Child){ | |
Parent.appendChild(Child); | |
}; | |
var Pr = function(Parent, Child){ | |
Parent.insertBefore(Child,Parent.firstChild); | |
}; | |
var St = function(item, styles){ | |
var camelCase = function(string){ | |
return string.replace(/^-ms-/, "ms-" ).replace(/-([\da-z])/gi, function(all, letter){ | |
return letter.toUpperCase(); | |
}); | |
}; | |
for(var prop in styles){ | |
try{ | |
item.style[camelCase(prop)]=styles[prop]; | |
}catch(e){} | |
} | |
}; | |
var AC = function(item, classe){ | |
var c=item.className; | |
c!=classe | |
&& c.substr(0,classe.length+1)!=classe+" " | |
&& c.substr(-1*(classe.length+1))!=" "+classe | |
&& 0>c.indexOf(" "+classe+" ") | |
&& (item.className=0<c.length?c+(" "+classe):classe); | |
}; | |
var SC = function(item, classe){ | |
var c=item.className; | |
c==classe&&(c=''); | |
c.substr(0,classe.length+1)==classe+" "&&(c=c.substr(classe.length+1)); | |
c.substr(-classe.length-1)==" "+classe&&(c=c.substr(0,c.length-classe.length-1)); | |
c.replace(' '+classe+' ',''); | |
item.className=c; | |
}; | |
function debounce(callback, delay){ | |
var timer; | |
return function(){ | |
var args = arguments; | |
var context = this; | |
clearTimeout(timer); | |
timer = setTimeout(function(){ | |
callback.apply(context, args); | |
}, delay) | |
} | |
} | |
function throttle(callback, delay) { | |
var last; | |
var timer; | |
return function () { | |
var context = this; | |
var now = +new Date(); | |
var args = arguments; | |
if (last && now < last + delay) { | |
// le délai n'est pas écoulé on reset le timer | |
clearTimeout(timer); | |
timer = setTimeout(function () { | |
last = now; | |
callback.apply(context, args); | |
}, delay); | |
} else { | |
last = now; | |
callback.apply(context, args); | |
} | |
}; | |
} | |
var isIE = function () { | |
var ua = window.navigator.userAgent, | |
msie = ua.indexOf("MSIE "); | |
return function () { | |
return msie >= 0; | |
}; | |
}(); | |
var isEdge = function () { | |
var ua = window.navigator.userAgent, | |
mse = ua.indexOf("Edge/"); | |
return function () { | |
return mse >= 0; | |
}; | |
}(); | |
var isChrome = function () { | |
var ua = window.navigator.userAgent, | |
chrome = ua.indexOf("Chrome/"), | |
mse = ua.indexOf("Edge/"); | |
return function () { | |
return chrome >= 0 && mse < 0; | |
}; | |
}(); | |
var isFF = function () { | |
var ua = window.navigator.userAgent, | |
ff = ua.indexOf("Firefox/"); | |
return function () { | |
return ff >= 0; | |
}; | |
}(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment