Skip to content

Instantly share code, notes, and snippets.

@jonpitch
Last active April 2, 2016 13:53
Show Gist options
  • Save jonpitch/9dceff8d40897c5e6077f0d4581916f1 to your computer and use it in GitHub Desktop.
Save jonpitch/9dceff8d40897c5e6077f0d4581916f1 to your computer and use it in GitHub Desktop.
Ember Theming - Service
import Ember from 'ember';
export default Ember.Service.extend({
base: 'default',
theme: 'first',
// the property used as a reference for styles
name: Ember.computed('base', function() {
const base = this.get('base');
const theme = this.get('theme');
return `${base}-${theme}`;
}),
// update things that may be using data-theme
themeChanged: Ember.observer('base', 'theme', function() {
this.notifyPropertyChange('name');
}),
// set the base theme for the application
setBase: function(base) {
this.set('base', Ember.isEmpty(base) ? 'default' : base);
},
// set theme to use within base theme
setTheme: function(theme) {
this.set('theme', Ember.isEmpty(theme) ? 'first' : theme);
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment