Last active
October 21, 2015 07:38
-
-
Save spencer516/63119b6627282fcd6903 to your computer and use it in GitHub Desktop.
Expand / Collapse
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Ember from 'ember'; | |
export default Ember.Controller.extend({ | |
appName:'Ember Twiddle', | |
families: [ | |
{ | |
title:'parent a', | |
children: [ | |
{ title:'a son' },{ title:'a daughter' } | |
] | |
}, | |
{ | |
title:'parent b', | |
children: [ | |
{ title:'b son' } | |
] | |
}, | |
{ title:'single c' } | |
] | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Ember from 'ember'; | |
export default Ember.Component.extend({ | |
isExpanded: false, | |
didInitAttrs() { | |
this.set('isExpanded', this.getAttr('all-expanded').bool); | |
this.notifyParent(); | |
}, | |
didUpdateAttrs(attrs) { | |
if('all-expanded' in attrs.newAttrs) { | |
this.set('isExpanded', this.getAttr('all-expanded').bool); | |
this.notifyParent(); | |
} | |
}, | |
notifyParent() { | |
let isExpanded = this.get('isExpanded'); | |
this.getAttr('notify')(isExpanded); | |
}, | |
willDestroyElement() { | |
this.set('isExpanded', false); | |
this.notifyParent(); | |
}, | |
actions: { | |
toggleExpand() { | |
this.toggleProperty('isExpanded'); | |
this.notifyParent(); | |
} | |
} | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Ember from 'ember'; | |
export default Ember.Component.extend({ | |
allExpanded: false, | |
showCollapseAll: false, | |
totalExpanded: 0, | |
actions: { | |
expandAll() { | |
this.set('allExpanded', {bool: true}); | |
}, | |
collapseAll() { | |
this.set('allExpanded', {bool: false}); | |
} | |
}, | |
trackChild: function(isExpanded) { | |
if(isExpanded) { | |
this.incrementProperty('totalExpanded'); | |
} else { | |
this.decrementProperty('totalExpanded'); | |
} | |
let total = this.get('totalExpanded'); | |
this.set('showCollapseAll', total >= 0); | |
} | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"version": "0.4.13", | |
"dependencies": { | |
"jquery": "https://cdnjs.cloudflare.com/ajax/libs/jquery/1.11.3/jquery.js", | |
"ember": "https://cdnjs.cloudflare.com/ajax/libs/ember.js/1.13.10/ember.debug.js", | |
"ember-data": "https://cdnjs.cloudflare.com/ajax/libs/ember-data.js/1.13.13/ember-data.js", | |
"ember-template-compiler": "https://cdnjs.cloudflare.com/ajax/libs/ember.js/1.13.10/ember-template-compiler.js" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment