php and jquery cookie mixture?
hey guys, i'm confused, i have the following 开发者_如何转开发jquery script in my header:
forceAnim: <?php echo ($iphone || is_singular()) ? 0 : 1; ?>
which meanst, that either on the iphone or on a singular-type page forceAnim is 0. However i want to include an additional query if a jquery cookie is saved.
if the jquery.cookie exists (and equals true) OR it's viewed on the iphone OR its a singular type post forceAnim should be true.
i have just no idea how to mix php with jquery in that case. to query if the jquery.cookie returns true i can just use:
if($.cookie('animate') == 'true'){
//yes the cookie returns true.
}
any idea how i can query all three things? thank you for your help.
@Joel Alejandro's answer is incorrect (it accidentaly reverses the result of the first two conditions). Correct version:
forceAnim: (<?php echo ($iphone || is_singular()) ? 'true' : 'false';
?> || $.cookie('animate') == 'true') ? 0 : 1;
This is parsed by PHP to either of this (with true or false respectively):
forceAnim: (true || $.cookie('animate') == 'true') ? 0 : 1;
forceAnim: (false || $.cookie('animate') == 'true') ? 0 : 1;
So forceAnim will be 1 only if none of the conditions are true (and will be 0 if any of them is true).
Truth table:
A B C D E F
iphone is_singular cookie_animate (A || B) (C || D) (E ? 0 : 1)
0 0 0 0 0 1
0 0 1 0 1 0
0 1 0 1 1 0
0 1 1 1 1 0
1 0 0 1 1 0
1 0 1 1 1 0
1 1 0 1 1 0
1 1 1 1 1 0
I think you can do something like this:
forceAnim: (<?php echo ($iphone || is_singular()) ? 0 : 1; ?> || $.cookie('animate') == 'true') ? 0 : 1
精彩评论