Last active
December 22, 2015 12:39
-
-
Save theodorton/6474283 to your computer and use it in GitHub Desktop.
Handlebars li-to helper that let's you wrap a link in a parent element that gets the class name bindings (active, loading etc.) Useful for twitter-bootstrap + ember.js
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
ul.nav.navbar-nav | |
= liTo 'index' | Home | |
= liTo 'about | Index | |
= liTo 'contact' | Contact | |
footer | |
= liTo 'privacy' tagName="p" | |
| I'm a link wrapped in a p, and when you click on the p you get routed to my link! |
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.Handlebars.registerHelper 'li-to', (name) -> | |
options = [].slice.call(arguments, -1)[0] | |
params = [].slice.call(arguments, 0, -1) | |
hash = options.hash | |
hash.disabledBinding = hash.disabledWhen | |
hash.parameters = | |
context: this | |
options: options | |
params: params | |
Ember.Handlebars.helpers.view.call this, LinkLiView, options |
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
LinkLiView = module.exports = Ember.LinkView.extend | |
tagName: 'li' | |
# TODO: Use a binding here... | |
layout: (-> | |
Ember.Handlebars.compile('<a href="'+@get('url')+'">{{yield}}</a>') | |
).property('url') | |
url: (-> | |
router = @get('router') | |
routeArgs = @get('routeArgs') | |
if routeArgs | |
router.generate.apply(router, routeArgs) | |
else | |
@get('loadingHref') | |
).property('routeArgs') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment