Skip to content

Instantly share code, notes, and snippets.

@xvw
Last active January 15, 2016 14:03
Show Gist options
  • Save xvw/a77ca996cbf4ac7af6c7 to your computer and use it in GitHub Desktop.
Save xvw/a77ca996cbf4ac7af6c7 to your computer and use it in GitHub Desktop.
<?php
protected static function hide_show($button, $code, $h='Hide', $s='Show') {
$js_trigger = new Js\Callback(function($e) use($code, $h, $s) {
$value = $e->get('target')->get('value');
$text = Js\Variable::createFresh(Js\string($h));
$disp = Js\Variable::createFresh(Js\string('flex'));
return $text->onTop() . $disp->onTop() . new Js\IfElse(
$value->equals(Js\string($h)),
function() use ($text, $disp, $h, $s) {
return $disp->set(Js\string('none')) .';'
. $text->set(Js\string($s)) .';';
},
function(){}
) . $value->set($text) . ';'
. $code->js()->v()
->get('style')
->get('display')
->set($disp);
});
$js_var = Js\Variable::createFresh($js_trigger);
client(
$js_var,
$button->js()->addEventListener(
Js\CLICK,
$js_var,
Js\_FALSE_
)
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment