-
Notifications
You must be signed in to change notification settings - Fork 176
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Provide first class support for showing/hiding elements #14
Comments
@kevindente I can see the use for this. Any ideas on how this could be configured in the api? Possibly // Configuration for model attributes that contain truthy values.
'#header': {
modelAttr: 'header',
toggle: true
}
// Overloaded with a callback, which should return a truthy value to toggle.
'#header': {
modelAttr: 'header',
toggle: function(modelVal, elVal, attrName) { return true; }
} |
Hmm, I'm not totally sure what "toggle" represents in your sample. Does that equate to "visible"? And does the value determining visibility come from the modelAttr header in that case (ie model.get('header') == true means visible, model.get('header') == false means invisible)? Or is visibility determined solely by the function return value, and independent of the property value? Actually, I'm unclear on this for readonly property as well (which I assume this is modeled after). The {param: true} setup is a tad confusing. |
Yeah, that is what I was going for in the first configuration style. When
The second example configuration is an overloaded value type for when the model attribute does not have a boolean value. In that case, when the model attribute is changed, the callback return value, true or false, will dictate whether it is shown or hidden. Make sense? Any suggestions/changes? FYI, |
OK, makes sense. I agree that toggle isn't the best name. It makes sense from a jQuery perspective, but isn't that obvious when you just read the bindings. Perhaps just "visible" would be better. BTW is there a way you'd be able to inject a transition animation into the showing and hiding (like making it collapse up instead of just disappearing)? |
@kevindente Starting to look into this now. I've settled on What were your ideas for injecting a transition animation? The cleanest and most flexible solution is to supply an extra callback which passes back the bindings: {
'#header': {
modelAttr: 'header',
visible: true,
visibleFn: 'fadeFast'
}
},
fadeFast: function($el, attrVal, attrName) {
if (attrVal) $el.fadeIn('fast');
else $el.fadeOut('fast');
} |
Hmm, maybe supporting arbitrary transitions is more than this needs. Seems like there isn't much difference between your visibleFn example and the afterUpdate function, and providing 2 ways to do the same thing probably doesn't make sense. What about just providing a path for passing through the standard parameters to jQuery's toggle/show/hide functions - duration, easing, and maybe callback? |
The The problem with configuring jQuery parameters for show/hide is that it doesn't cover enough ground and that you would need both show and hide option configurations. What if I wanted to use slideDown and slideUp or some other combination of UI animations? I think a single callback, like |
Ah, OK, I see what you're saying. afterUpdate fires after the DOM is updated, but visibleFn would fire after the model value changes (and then would enact the DOM change). I'm not totally convinced that passing through show/hide params wouldn't be helpful, even if it's just a single set for both show and hide (I think it would be pretty common for the duration and easing to be symmetrical for show/hide). But that's something that could easily be added later if other people request it. |
This is on master - I'll cut a tag soon. Thanks for the help @kevindente |
Awesome! Thanks! |
It's very common to show/hide UI elements based on properties of a model (especially common - a boolean value that maps to visible/hidden). You can currently do by binding class names with a formatter, but it's kind of clunky. It would be nice if there was first class support for controlling element visibility in stickit.
The text was updated successfully, but these errors were encountered: