unclecheese / silverstripe-display-logic

The Display Logic module allows you to add conditions for displaying or hiding certain form fields based on client-side behavior.
BSD 3-Clause "New" or "Revised" License
74 stars 71 forks source link

Added animation effects for fade and slide #68

Closed colintucker closed 7 years ago

colintucker commented 8 years ago

Hey UC!

I started using your handy module today for a project and I felt inspired to add some animation effects. These are just regular old-fashioned jQuery animations, nothing special. I've added a method to DisplayLogicCriteria called useAnimation(). It works like so:

$toggle->displayIf('ToggleMe')->isChecked()->useAnimation('toggle');
$fade->displayIf('FadeMe')->isChecked()->useAnimation('fade');
$slide->displayIf('SlideMe')->isChecked()->useAnimation('slide');

The default animation method is toggle if useAnimation is not called (i.e. the default display logic behaviour). My JavaScript is not the best so hopefully you can review that and see if I've done anything silly, though it seems to work. 😜

I hope the PR can be of some benefit! 😃

Cheers,

Colin.

colintucker commented 8 years ago

Hmm, I just noticed a problem in my testing with an undefined animation data attribute, I'll update the branch with a fix.

unclecheese commented 8 years ago

Nice one! I'll have a look at this. I was actually thinking recently that the toggling is a bit jarring!

colintucker commented 8 years ago

Okie dokes, I think that fixed the attribute bug. As a bonus, I also added config for the default animation method, which can be set in the YAML, or via:

DisplayLogicCriteria::set_default_animation('fade');

That way, you won't need to use ->useAnimation('fade') on everything if you like that animation.