Skip to content

Instantly share code, notes, and snippets.

@leo
Created March 11, 2016 10:51
Show Gist options
  • Save leo/2bdb74cb1242f9766a25 to your computer and use it in GitHub Desktop.
Save leo/2bdb74cb1242f9766a25 to your computer and use it in GitHub Desktop.
The easiest way to add the name of the current route as class to the body.
Ember.Route.reopen({
activate () {
var classes = this.genClasses()
if (classes !== 'application') {
Ember.$('body').addClass(classes)
}
},
deactivate () {
Ember.$('body').removeClass(this.genClasses())
},
genClasses () {
var classes = this.routeName.split('.')
if (this.classNames) {
for (var name of this.classNames) {
classes.push(name)
}
}
return classes.join(' ')
}
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment