Created
March 11, 2016 10:51
-
-
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.
This file contains 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
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
https://medium.com/@leo/ember-adding-a-body-class-based-on-the-current-route-name-5d48cf16148f#.5x9fkcjpy