Skip to content

Instantly share code, notes, and snippets.

Avatar

VA79 vanaf1979

View GitHub Profile
@vanaf1979
vanaf1979 / find.js
Created Jul 16, 2017
find an ellement
View find.js
function find( selector , context = null )
{
return ( context || document ).querySelector( selector );
}
@vanaf1979
vanaf1979 / findAll.js
Created Jul 16, 2017
Find a group of ellements
View findAll.js
function findAll( selector , context = null )
{
return ( context || document ).querySelectorAll( selector );
}
@vanaf1979
vanaf1979 / wrap.js
Created Jul 16, 2017
Wrap an ellement with another
View wrap.js
function wrap( ellement , wrapper )
{
ellement.parentNode.insertBefore( wrapper , ellement )
wrapper.appendChild( ellement )
}
@vanaf1979
vanaf1979 / parseBool.js
Created Jul 16, 2017
Parse a velue to a bool
View parseBool.js
function parseBool( value )
{
return value == "true" || value == true || value == 1 ? true : false;
}
@vanaf1979
vanaf1979 / inArray.js
Created Jul 16, 2017
Is a value present in a givven array
View inArray.js
function inArray( needle , haystack )
{
for( var i = 0 ; i < haystack.length ; i++ )
{
if( haystack[i] == needle ) return i;
}
return -1;
}
@vanaf1979
vanaf1979 / loop.js
Created Jul 16, 2017
Loop throu a list of ellement / array
View loop.js
function loop( list , callback )
{
for ( var i = 0 ; i < list.length ; i++ )
{
callback( list[i] );
}
}
@vanaf1979
vanaf1979 / setCookie.js
Created Jul 16, 2017
Set a cookie value
View setCookie.js
function setCookie( name , value , days )
{
var d = new Date;
d.setTime( d.getTime() + 24 * 60 * 60 * 1000 * days );
document.cookie = name + "=" + value + ";path=/;expires=" + d.toGMTString();
}
@vanaf1979
vanaf1979 / getCookie.js
Created Jul 16, 2017
Get a cookie value
View getCookie.js
function getCookie( name )
{
var v = document.cookie.match( '(^|;) ?' + name + '=([^;]*)(;|$)' );
return v ? v[2] : null;
}
@vanaf1979
vanaf1979 / deleteCookie.js
Created Jul 16, 2017
Delete a cookie value
View deleteCookie.js
function deleteCookie( name )
{
setCookie( name, '' , -1 );
}
@vanaf1979
vanaf1979 / addEvent.js
Created Jul 16, 2017
Add an event listner
View addEvent.js
function addEvent( ellement , type , callback )
{
if ( ellement.attachEvent )
{
ellement.attachEvent( 'on' + type , callback );
}
else
{
ellement.addEventListener( type , callback );
}