Last active
October 9, 2016 18:42
-
-
Save les2/9f1fc37e10e555858fa11abbc4ee5617 to your computer and use it in GitHub Desktop.
Attribute Bindings
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({ | |
ariaControls: null, | |
children: null, | |
api: null, | |
init() { | |
this._super(...arguments); | |
this.set('children', Ember.A()); | |
this.set('api', { | |
register: this.register.bind(this), | |
}); | |
}, | |
register(child) { | |
this.get('children').pushObject(child); | |
if (this.get('active') === child.name) { | |
child.setActiveState(true); | |
} | |
}, | |
// observer the active property | |
activateSelected: Ember.observer('active', function() { | |
let childApi = this.get('children').findBy('name', this.get('active')); | |
this.get('children').forEach(child => child.setActiveState(false)); | |
childApi.setActiveState(true); | |
}), | |
}); |
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({ | |
classNames: ['nested-component'], | |
tagName: 'button', | |
attributeBindings: ['ariaSelected:aria-selected', 'ariaControls:aria-controls'], | |
classNameBindings: [ | |
'active:my-active-class:my-inactive-class', | |
], | |
api: null, | |
active: false, | |
parentApi: null, | |
name: null, | |
demonstrateBug: true, | |
ariaSelected: Ember.computed('active', 'demonstrateBug', function() { | |
if (this.get('demonstrateBug')) { | |
return this.get('active'); | |
} | |
return this.get('active') ? 'true' : 'false'; | |
}), | |
init() { | |
this._super(...arguments); | |
Ember.assert('name required', this.get('name')); | |
this.set('api', { | |
name: this.get('name'), | |
setActiveState: this.setActiveState.bind(this), | |
}); | |
this.get('parentApi').register(this.get('api')); | |
}, | |
setActiveState(value) { | |
this.set('active', Boolean(value)); | |
}, | |
click() { | |
this.get('onselect')(this.get('name')); | |
} | |
}); |
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', | |
active: 'first', | |
showBug: true, | |
}); |
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
body { | |
margin: 12px 16px; | |
font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; | |
font-size: 12pt; | |
} | |
.nested-component { | |
position: relative; | |
padding: 20px; | |
margin: 20px; | |
background-color: transparent; | |
} | |
.nested-component[aria-selected=""] { | |
background-color: yellow; | |
} | |
.nested-component[aria-selected="true"] { | |
background-color: green; | |
color: yellow; | |
} | |
.nested-component[aria-selected="false"] { | |
background-color: blue; | |
color: while; | |
} | |
.nested-component.my-active-class { | |
border: 10px solid green; | |
} | |
.nested-component.my-active-class:before { | |
position: absolute; | |
display: block; | |
content: '⇩ Active ⇩'; | |
top: -40px; | |
left: 0; | |
background-color: green; | |
color: yellow; | |
} | |
.nested-component[aria-selected=""]:after { | |
position: absolute; | |
display: block; | |
white-space: nowrap; | |
content: '⇧ aria-selected=""'; | |
bottom: -40px; | |
left: 0; | |
background-color: green; | |
color: yellow; | |
} | |
.nested-component.my-inactive-class { | |
border: 10px solid blue; | |
} |
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 function destroyApp(application) { | |
Ember.run(application, 'destroy'); | |
} |
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 Resolver from '../../resolver'; | |
import config from '../../config/environment'; | |
const resolver = Resolver.create(); | |
resolver.namespace = { | |
modulePrefix: config.modulePrefix, | |
podModulePrefix: config.podModulePrefix | |
}; | |
export default resolver; |
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'; | |
import Application from '../../app'; | |
import config from '../../config/environment'; | |
const { run } = Ember; | |
const assign = Ember.assign || Ember.merge; | |
export default function startApp(attrs) { | |
let application; | |
let attributes = assign({rootElement: "#test-root"}, config.APP); | |
attributes = assign(attributes, attrs); // use defaults, but you can override; | |
run(() => { | |
application = Application.create(attributes); | |
application.setupForTesting(); | |
application.injectTestHelpers(); | |
}); | |
return application; | |
} |
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 resolver from './helpers/resolver'; | |
import { | |
setResolver | |
} from 'ember-qunit'; | |
setResolver(resolver); |
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.10.5", | |
"EmberENV": { | |
"FEATURES": {} | |
}, | |
"options": { | |
"use_pods": false, | |
"enable-testing": false | |
}, | |
"dependencies": { | |
"jquery": "https://cdnjs.cloudflare.com/ajax/libs/jquery/1.11.3/jquery.js", | |
"ember": "beta", | |
"ember-data": "2.8.0", | |
"ember-template-compiler": "beta", | |
"ember-testing": "beta" | |
}, | |
"addons": {} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment