Skip to content

Instantly share code, notes, and snippets.

@oelmekki
Created March 27, 2009 14:57
Show Gist options
  • Save oelmekki/86727 to your computer and use it in GitHub Desktop.
Save oelmekki/86727 to your computer and use it in GitHub Desktop.
(function($)
{
/**
* Get a cookie
* @param string
* @return string
*/
function getCookie( name )
{
var nameEQ = name + "=";
var ca = document.cookie.split( ';' );
for (var i=0; i<ca.length; i++)
{
var c = ca[i];
while ( c.charAt(0)==' ' )
{
c = c.substring( 1, c.length );
}
if ( c.indexOf( nameEQ ) == 0)
{
return c.substring( nameEQ.length, c.length );
}
}
return null;
}
/**
* Set a cookie
* @param string
* @param string
*/
function setCookie( name, value, expires, path, domain, secure )
{
// set time, it's in milliseconds
var today = new Date();
today.setTime( today.getTime() );
/*
if the expires variable is set, make the correct
expires time, the current script below will set
it for x number of days, to make it for hours,
delete * 24, for minutes, delete * 60 * 24
*/
if ( expires )
{
expires = expires * 1000 * 60 * 60 * 24;
}
var expires_date = new Date( today.getTime() + (expires) );
document.cookie = name + "=" +escape( value ) +
( ( expires ) ? ";expires=" + expires_date.toGMTString() : "" ) +
( ( path ) ? ";path=" + path : "" ) +
( ( domain ) ? ";domain=" + domain : "" ) +
( ( secure ) ? ";secure" : "" );
}
/**
* Return the string capitalized
* @param string
* @return string
*/
function capitalize( str )
{
var capital = str[0].toUpperCase();
var rest = str.substring( 1 );
return ( capital + rest );
}
/**
* Toggle the head block
*/
function toggle_tools()
{
var element = $( '.head-quote' ) ;
$( '.head-quote_links', element ).slideToggle( 'normal', function(){
var image = $( '#head-quote_more img', element );
var state = /quote-moins/.exec( image.attr( 'src' ) );
var src = ( state ? 'quote-moins' : 'quote-plus' );
var dest = ( state ? 'quote-plus' : 'quote-moins' );
image.attr( 'src', image.attr( 'src' ).replace( src, dest ) );
image.attr( 'alt', capitalize( dest.replace( 'quote-', '' ) ) );
setCookie( 'header_quote_state', dest.replace( 'quote-', '' ), 2, '/' );
});
}
/**
* DOM ready
*/
$( function()
{
// init tools
if ( getCookie( 'header_quote_state' ) == 'plus' )
{
$( '.head-quote .head-quote_links' ).hide() ;
var image = $( '.head-quote #head-quote_more img' );
image.attr( 'src', image.attr( 'src' ).replace( 'moins', 'plus' ) );
image.attr( 'alt', 'Plus' );
}
$( '.head-quote #head-quote_more' ).click( function(){ toggle_tools(); return false; } ) ;
}) ;
}
)(jQuery);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment