app/assets/javascripts/hooch.js in hooch-0.0.8 vs app/assets/javascripts/hooch.js in hooch-0.1.0
- old
+ new
@@ -138,57 +138,71 @@
})
},
expand: function(){
if(this.collapsers.length > 0){
- this.hide_expanders();
this.show_collapsers();
}
+ this.hide_expanders();
if(this.expand_class){
this.$expandable.addClass(this.expand_class)
+ this.$expandable.removeClass(this.collapse_class)
}else{
- this.$expandable.show(10);
+ this.$expandable.show();
}
+ this.state = 'expanded'
},
collapse: function(){
if(this.collapsers.length > 0){
this.hide_collapsers();
- this.show_expanders();
}
- if(this.collapse_class){
+ this.show_expanders();
+ if(this.collapse_class || this.expand_class){
this.$expandable.addClass(this.collapse_class)
+ this.$expandable.removeClass(this.expand_class)
}else{
- this.$expandable.hide(10);
+ this.$expandable.hide();
}
+ this.state = 'collapsed'
},
toggle: function(){
- this.$expandable.toggle(10);
+ if(this.state == 'collapsed'){
+ this.expand();
+ } else {
+ this.collapse();
+ }
}
}),
Expander: Class.extend({
init: function($expander,target){
this.$expander = $expander;
+ this.target = target;
+ this.expand_class = $expander.data('expand-class')
if($expander.data('fake-dropdown')){
target.$expandable.on('click',function(){
target.toggle();
})
target.$expandable.on('mouseleave',function(){
target.collapse();
})
}
$expander.bind('click',function(){
- if(target.collapsers.length > 0){
- target.expand();
- } else {
- target.toggle();
- }
+ target.toggle();
})
},
hide: function(){
- this.$expander.hide();
+ if(this.expand_class){
+ this.$expander.addClass(this.expand_class)
+ } else if(this.target.collapsers.length > 0) {
+ this.$expander.hide();
+ }
},
show: function(){
- this.$expander.show();
+ if(this.expand_class){
+ this.$expander.removeClass(this.expand_class)
+ } else if(this.target.collapsers.length > 0) {
+ this.$expander.show();
+ }
}
}),
Collapser: Class.extend({
init: function($collapser,target){
this.$collapser = $collapser;