diff --git a/packages/ember-routing-views/lib/views/link.js b/packages/ember-routing-views/lib/views/link.js index 570f07e65b1..c177c07cba7 100644 --- a/packages/ember-routing-views/lib/views/link.js +++ b/packages/ember-routing-views/lib/views/link.js @@ -6,12 +6,12 @@ import Ember from "ember-metal/core"; // FEATURES, Logger, assert import { get } from "ember-metal/property_get"; -import { set } from "ember-metal/property_set"; import { computed } from "ember-metal/computed"; import { isSimpleClick } from "ember-views/system/utils"; import EmberComponent from "ember-views/views/component"; import inject from "ember-runtime/inject"; import ControllerMixin from "ember-runtime/mixins/controller"; +import getValue from 'ember-htmlbars/hooks/get-value'; import linkToTemplate from "ember-htmlbars/templates/link-to"; linkToTemplate.meta.revision = 'Ember@VERSION_STRING_PLACEHOLDER'; @@ -408,19 +408,11 @@ var LinkComponent = EmberComponent.extend({ queryParams = {}; } - if (attrs.disabledClass) { - this.set('disabledClass', attrs.disabledClass); - } - - if (attrs.activeClass) { - this.set('activeClass', attrs.activeClass); - } - if (attrs.disabledWhen) { - this.set('disabled', attrs.disabledWhen); + this.set('disabled', getValue(attrs.disabledWhen)); } - var currentWhen = attrs['current-when']; + var currentWhen = getValue(attrs['current-when']); if (attrs.currentWhen) { Ember.deprecate('Using currentWhen with {{link-to}} is deprecated in favor of `current-when`.', !attrs.currentWhen); @@ -436,10 +428,6 @@ var LinkComponent = EmberComponent.extend({ this.set('linkTitle', params.shift()); } - if (attrs.loadingClass) { - set(this, 'loadingClass', attrs.loadingClass); - } - for (let i = 0; i < params.length; i++) { var value = params[i]; diff --git a/packages/ember/tests/helpers/link_to_test.js b/packages/ember/tests/helpers/link_to_test.js index 3d85b47430d..0c943299ae1 100644 --- a/packages/ember/tests/helpers/link_to_test.js +++ b/packages/ember/tests/helpers/link_to_test.js @@ -250,6 +250,27 @@ QUnit.test("the {{link-to}} helper supports a custom disabledClass", function () }); +QUnit.test("the {{link-to}} helper supports a custom disabledClass set via bound param", function () { + Ember.TEMPLATES.index = compile('{{#link-to "about" id="about-link" disabledWhen=true disabledClass=disabledClass}}About{{/link-to}}'); + + Router.map(function() { + this.route("about"); + }); + + App.IndexController = Ember.Controller.extend({ + disabledClass: 'do-not-want' + }); + + bootApplication(); + + Ember.run(function() { + router.handleURL("/"); + }); + + equal(Ember.$('#about-link.do-not-want', '#qunit-fixture').length, 1, "The link can apply a custom disabled class"); + +}); + QUnit.test("the {{link-to}} helper does not respond to clicks when disabled", function () { Ember.TEMPLATES.index = compile('{{#link-to "about" id="about-link" disabledWhen=true}}About{{/link-to}}'); @@ -270,6 +291,30 @@ QUnit.test("the {{link-to}} helper does not respond to clicks when disabled", fu equal(Ember.$('h3:contains(About)', '#qunit-fixture').length, 0, "Transitioning did not occur"); }); +QUnit.test("the {{link-to}} helper does not respond to clicks when disabled via a bound param", function () { + Ember.TEMPLATES.index = compile('{{#link-to "about" id="about-link" disabledWhen=disabledWhen}}About{{/link-to}}'); + + Router.map(function() { + this.route("about"); + }); + + App.IndexController = Ember.Controller.extend({ + disabledWhen: true + }); + + bootApplication(); + + Ember.run(function() { + router.handleURL("/"); + }); + + Ember.run(function() { + Ember.$('#about-link', '#qunit-fixture').click(); + }); + + equal(Ember.$('h3:contains(About)', '#qunit-fixture').length, 0, "Transitioning did not occur"); +}); + QUnit.test("The {{link-to}} helper supports a custom activeClass", function() { Ember.TEMPLATES.index = compile("

Home

{{#link-to 'about' id='about-link'}}About{{/link-to}}{{#link-to 'index' id='self-link' activeClass='zomg-active'}}Self{{/link-to}}"); @@ -288,6 +333,28 @@ QUnit.test("The {{link-to}} helper supports a custom activeClass", function() { equal(Ember.$('#about-link:not(.active)', '#qunit-fixture').length, 1, "The other link was rendered without active class"); }); +QUnit.test("The {{link-to}} helper supports a custom activeClass from a bound param", function() { + Ember.TEMPLATES.index = compile("

Home

{{#link-to 'about' id='about-link'}}About{{/link-to}}{{#link-to 'index' id='self-link' activeClass=activeClass}}Self{{/link-to}}"); + + Router.map(function() { + this.route("about"); + }); + + App.IndexController = Ember.Controller.extend({ + activeClass: 'zomg-active' + }); + + bootApplication(); + + Ember.run(function() { + router.handleURL("/"); + }); + + equal(Ember.$('h3:contains(Home)', '#qunit-fixture').length, 1, "The home template was rendered"); + equal(Ember.$('#self-link.zomg-active', '#qunit-fixture').length, 1, "The self-link was rendered with active class"); + equal(Ember.$('#about-link:not(.active)', '#qunit-fixture').length, 1, "The other link was rendered without active class"); +}); + QUnit.test('The {{link-to}} helper supports \'classNameBindings\' with custom values [GH #11699]', function() { Ember.TEMPLATES.index = compile('

Home

{{#link-to \'about\' id=\'about-link\' classNameBindings=\'foo:foo-is-true:foo-is-false\'}}About{{/link-to}}'); @@ -400,6 +467,33 @@ QUnit.test("The {{link-to}} helper does not disregard current-when when it is gi equal(Ember.$('#other-link.active', '#qunit-fixture').length, 1, "The link is active when current-when is given for explicitly for a resource"); }); +QUnit.test("The {{link-to}} helper does not disregard current-when when it is set via a bound param", function() { + Router.map(function(match) { + this.resource("index", { path: "/" }, function() { + this.route("about"); + }); + + this.resource("items", function() { + this.route('item'); + }); + }); + + App.IndexAboutController = Ember.Controller.extend({ + currentWhen: 'index' + }); + + Ember.TEMPLATES.index = compile("

Home

{{outlet}}"); + Ember.TEMPLATES['index/about'] = compile("{{#link-to 'items' id='other-link' current-when=currentWhen}}ITEM{{/link-to}}"); + + bootApplication(); + + Ember.run(function() { + router.handleURL("/about"); + }); + + equal(Ember.$('#other-link.active', '#qunit-fixture').length, 1, "The link is active when current-when is set via a bound param"); +}); + QUnit.test("The {{link-to}} helper supports multiple current-when routes", function() { Router.map(function(match) { this.resource("index", { path: "/" }, function() { @@ -793,13 +887,14 @@ QUnit.test("link-to with null/undefined dynamic parameters are put in a loading var oldWarn = Ember.Logger.warn; var warnCalled = false; Ember.Logger.warn = function() { warnCalled = true; }; - Ember.TEMPLATES.index = compile("{{#link-to destinationRoute routeContext loadingClass='i-am-loading' id='context-link'}}string{{/link-to}}{{#link-to secondRoute loadingClass='i-am-loading' id='static-link'}}string{{/link-to}}"); + Ember.TEMPLATES.index = compile("{{#link-to destinationRoute routeContext loadingClass='i-am-loading' id='context-link'}}string{{/link-to}}{{#link-to secondRoute loadingClass=loadingClass id='static-link'}}string{{/link-to}}"); var thing = Ember.Object.create({ id: 123 }); App.IndexController = Ember.Controller.extend({ destinationRoute: null, - routeContext: null + routeContext: null, + loadingClass: 'i-am-loading' }); App.AboutRoute = Ember.Route.extend({