Created
June 3, 2016 23:39
-
-
Save paulvanbuuren/f828d75785bcc4ad931860ed79726a9c to your computer and use it in GitHub Desktop.
conditionally load animation CSS
This file contains 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
define( 'ANIMATIONCOOKIEKEY', 'mag_animatie_tonen' ); | |
//======================================================================================================== | |
add_action( 'init', 'gist_check_if_cookies_are_enabled' ); | |
//======================================================================================================== | |
function gist_if_cookies_are_enabled_and_animation_is_allowed_load_animation_css() { | |
wp_enqueue_style( | |
'header-animation', | |
YOUR_THEME_FOLDER . '/css/header-animation-for-browsers-that-accept-cookies.css', | |
'', | |
'', | |
'screen and (min-width: 1020px)' | |
); | |
} | |
//======================================================================================================== | |
function gist_check_if_cookies_are_enabled() { | |
// check even of de gebruiker heeft aangegeven geen animatie te willen via de knop | |
if ( isset( $_GET[ANIMATIONCOOKIEKEY] ) ) { | |
if ( $_GET[ANIMATIONCOOKIEKEY] == 'nee' ) { | |
setcookie( ANIMATIONCOOKIEKEY ,'nee', time() + 3600, '/'); | |
} | |
else { | |
setcookie( ANIMATIONCOOKIEKEY ,'ja', time() + 3600, '/'); | |
} | |
} | |
else { | |
setcookie( ANIMATIONCOOKIEKEY ,"ja", time() + 3600, '/'); | |
} | |
if(count($_COOKIE) > 0) { | |
// er kunnen dus blijkbaar cookies gezet worden | |
//* toon keuzeknop voor animatie | |
add_action( 'genesis_site_description', 'gist_add_header_animatiekeuzeknop' ); | |
return true; | |
} | |
else { | |
// er kunnen geen cookies getoond worden. | |
// We tonen dus geen animatie | |
return false; | |
} | |
} | |
//======================================================================================================== | |
function gist_add_header_animatiekeuzeknop() { | |
$mag_animatie_tonen = ''; | |
$label = __( "Stop animatie", 'your-theme-translation' ); | |
if ( isset( $_GET[ANIMATIONCOOKIEKEY] ) ) { | |
$mag_animatie_tonen = $_GET[ANIMATIONCOOKIEKEY]; | |
} | |
else { | |
if ( isset($_COOKIE[ANIMATIONCOOKIEKEY] ) ) { | |
$mag_animatie_tonen = $_COOKIE[ANIMATIONCOOKIEKEY]; | |
} | |
} | |
if ( $mag_animatie_tonen !== 'nee' ) { | |
$mag_animatie_tonen = 'ja'; | |
} | |
else { | |
$mag_animatie_tonen = 'nee'; | |
} | |
if ( $mag_animatie_tonen !== 'nee' ) { | |
gist_if_cookies_are_enabled_and_animation_is_allowed_load_animation_css(); | |
$mag_animatie_tonen = 'nee'; | |
$legend = __( "Er zijn kleine wolkjes toegevoegd aan deze header. Deze bewegen langzaam van links naar rechts. Eentje laat af en toe een bliksempje zien.", 'your-theme-translation' ); | |
} | |
else { | |
// animatie niet tonen | |
$legend = __( "Er worden kleine wolkjes toegevoegd aan deze header. Deze bewegen langzaam van links naar rechts. Eentje laat af en toe een bliksempje zien.", 'your-theme-translation' ); | |
$label = __( "Sta animatie toe", 'your-theme-translation' ); | |
$mag_animatie_tonen = 'ja'; | |
} | |
echo '<form id="' . ANIMATIONCOOKIEKEY . '_form"><fieldset><legend>' . $legend . '</legend><input type="hidden" name="' . ANIMATIONCOOKIEKEY . '" value="' . $mag_animatie_tonen . '"><button type="submit" id="' . ANIMATIONCOOKIEKEY . '_button">' . $label . '</button></fieldset></form>'; | |
} | |
//======================================================================================================== | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment