Skip to content

Instantly share code, notes, and snippets.

View vanaf1979's full-sized avatar

VA79 vanaf1979

View GitHub Profile
@vanaf1979
vanaf1979 / find.js
Created July 16, 2017 13:33
find an ellement
function find( selector , context = null )
{
return ( context || document ).querySelector( selector );
}
@vanaf1979
vanaf1979 / findAll.js
Created July 16, 2017 13:35
Find a group of ellements
function findAll( selector , context = null )
{
return ( context || document ).querySelectorAll( selector );
}
@vanaf1979
vanaf1979 / wrap.js
Created July 16, 2017 13:36
Wrap an ellement with another
function wrap( ellement , wrapper )
{
ellement.parentNode.insertBefore( wrapper , ellement )
wrapper.appendChild( ellement )
}
@vanaf1979
vanaf1979 / parseBool.js
Created July 16, 2017 13:37
Parse a velue to a bool
function parseBool( value )
{
return value == "true" || value == true || value == 1 ? true : false;
}
@vanaf1979
vanaf1979 / inArray.js
Created July 16, 2017 13:38
Is a value present in a givven array
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 July 16, 2017 13:39
Loop throu a list of ellement / array
function loop( list , callback )
{
for ( var i = 0 ; i < list.length ; i++ )
{
callback( list[i] );
}
}
@vanaf1979
vanaf1979 / setCookie.js
Created July 16, 2017 13:40
Set a cookie value
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 July 16, 2017 13:41
Get a cookie value
function getCookie( name )
{
var v = document.cookie.match( '(^|;) ?' + name + '=([^;]*)(;|$)' );
return v ? v[2] : null;
}
@vanaf1979
vanaf1979 / deleteCookie.js
Created July 16, 2017 13:42
Delete a cookie value
function deleteCookie( name )
{
setCookie( name, '' , -1 );
}
@vanaf1979
vanaf1979 / addEvent.js
Created July 16, 2017 13:42
Add an event listner
function addEvent( ellement , type , callback )
{
if ( ellement.attachEvent )
{
ellement.attachEvent( 'on' + type , callback );
}
else
{
ellement.addEventListener( type , callback );
}