From 9558294fa3b49f05d8d969354bbcc5a7e51a99e8 Mon Sep 17 00:00:00 2001 From: Thomas Chen Date: Tue, 22 Mar 2016 10:42:47 -0700 Subject: [PATCH] added 'portal-tag-name' feature to portal for to allow for yielding to different tags and added tests for this. Removed the ^ from the jquery requirement to fix a bug with ember 1.13 where it wouldn't build --- addon/components/portal-for.js | 4 +++- bower.json | 2 +- tests/acceptance/portal-test.js | 16 ++++++++++++++++ tests/dummy/app/templates/application.hbs | 4 +++- tests/dummy/app/templates/example.hbs | 4 ++++ tests/dummy/app/templates/example/bar.hbs | 4 ++++ tests/dummy/app/templates/example/bar/baz.hbs | 4 ++++ tests/dummy/app/templates/example/foo.hbs | 4 ++++ 8 files changed, 39 insertions(+), 3 deletions(-) diff --git a/addon/components/portal-for.js b/addon/components/portal-for.js index afc2066..c12b323 100644 --- a/addon/components/portal-for.js +++ b/addon/components/portal-for.js @@ -6,12 +6,14 @@ export default Ember.Component.extend({ 'portal-class': null, + 'portal-tag-name': 'div', + portalElement() { const elementID = portalIdForName(this.get("name")); let element = document.getElementById(elementID); if (!element) { - element = document.createElement('div'); + element = document.createElement(this.get('portal-tag-name')); element.id = elementID; } diff --git a/bower.json b/bower.json index 8f91311..b231b0e 100644 --- a/bower.json +++ b/bower.json @@ -9,7 +9,7 @@ "ember-qunit": "0.4.9", "ember-qunit-notifications": "0.0.7", "ember-resolver": "~0.1.18", - "jquery": "^1.11.3", + "jquery": "1.11.3", "loader.js": "ember-cli/loader.js#3.2.1", "qunit": "~1.18.0" } diff --git a/tests/acceptance/portal-test.js b/tests/acceptance/portal-test.js index ed7a11a..6ae2af7 100644 --- a/tests/acceptance/portal-test.js +++ b/tests/acceptance/portal-test.js @@ -21,6 +21,10 @@ test('visiting /', function(assert) { assert.equal(find(".header").length, 1, 'Has 1 header'); assert.equal(find(".footer").length, 1, 'Has 1 footer'); + assert.equal(find("#title > span > span.title-portal").text().trim(), + "example", + "Shows the correct title"); + assert.equal(find("#examples-header").length, 1, 'Shows the example header'); assert.equal(find("#examples-footer").length, 1, 'Shows the example footer'); }); @@ -33,6 +37,10 @@ test('visiting /foo', function(assert) { assert.equal(find(".header").length, 1, 'Has 1 header'); assert.equal(find(".footer").length, 1, 'Has 1 footer'); + assert.equal(find("#title > span > span.title-portal").text().trim(), + "foo", + "Shows the correct title"); + assert.equal(find("#foo-header").length, 1, 'Shows the foo header'); assert.equal(find("#examples-footer").length, 1, 'Shows the example footer'); }); @@ -46,6 +54,10 @@ test('visiting /bar', function(assert) { assert.equal(find(".header").length, 1, 'Has 1 header'); assert.equal(find(".footer").length, 1, 'Has 1 footer'); + assert.equal(find("#title > span > span.title-portal").text().trim(), + "bar", + "Shows the correct title"); + assert.equal(find("#examples-header").length, 1, 'Shows the example header'); assert.equal(find("#bar-footer").length, 1, 'Shows the bar footer'); }); @@ -58,6 +70,10 @@ test('visiting /bar/baz', function(assert) { assert.equal(find(".header").length, 1, 'Has 1 header'); assert.equal(find(".footer").length, 1, 'Has 1 footer'); + assert.equal(find("#title > span > span.title-portal").text().trim(), + "baz", + "Shows the correct title"); + assert.equal(find("#baz-header").length, 1, 'Shows the baz header'); assert.equal(find("#baz-footer").length, 1, 'Shows the baz footer'); }); diff --git a/tests/dummy/app/templates/application.hbs b/tests/dummy/app/templates/application.hbs index 405a1ca..8c0d2e8 100644 --- a/tests/dummy/app/templates/application.hbs +++ b/tests/dummy/app/templates/application.hbs @@ -1,7 +1,9 @@
application.hbs -

ember-portal

+

+ ember-portal {{portal-for name="title-append" tagName="span" portal-tag-name="span" portal-class="title-portal"}} +

Render content to portals on the page & override them in child templates.

diff --git a/tests/dummy/app/templates/example.hbs b/tests/dummy/app/templates/example.hbs index a6c25ff..aad5559 100644 --- a/tests/dummy/app/templates/example.hbs +++ b/tests/dummy/app/templates/example.hbs @@ -1,6 +1,10 @@
example.hbs + {{#portal-content for="title-append"}} + example + {{/portal-content}} + {{#portal-content for="header"}}
Examples Header - defined in example.hbs diff --git a/tests/dummy/app/templates/example/bar.hbs b/tests/dummy/app/templates/example/bar.hbs index c5698dd..bce6757 100644 --- a/tests/dummy/app/templates/example/bar.hbs +++ b/tests/dummy/app/templates/example/bar.hbs @@ -1,6 +1,10 @@
example/bar.hbs + {{#portal-content for="title-append"}} + bar + {{/portal-content}} + {{#portal-content for="footer"}}