Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

portal-tag-name support to PortForComponent #7

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion addon/components/portal-for.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
Expand Down
16 changes: 16 additions & 0 deletions tests/acceptance/portal-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
});
Expand All @@ -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');
});
Expand All @@ -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');
});
Expand All @@ -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');
});
Expand Down
4 changes: 3 additions & 1 deletion tests/dummy/app/templates/application.hbs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
<div class="section">
<span class="template-name">application.hbs</span>

<h2 id="title">ember-portal</h2>
<h2 id="title">
ember-portal {{portal-for name="title-append" tagName="span" portal-tag-name="span" portal-class="title-portal"}}
</h2>

<div class="info">
<p>Render content to portals on the page &amp; override them in child templates.</p>
Expand Down
4 changes: 4 additions & 0 deletions tests/dummy/app/templates/example.hbs
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
<div class="section">
<span class="template-name">example.hbs</span>

{{#portal-content for="title-append"}}
example
{{/portal-content}}

{{#portal-content for="header"}}
<div id="examples-header" class="header">
Examples Header - defined in example.hbs
Expand Down
4 changes: 4 additions & 0 deletions tests/dummy/app/templates/example/bar.hbs
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
<div class="section">
<span class="template-name">example/bar.hbs</span>

{{#portal-content for="title-append"}}
bar
{{/portal-content}}

{{#portal-content for="footer"}}
<div id="bar-footer" class="footer">
Bar Footer - defined in example/bar.hbs
Expand Down
4 changes: 4 additions & 0 deletions tests/dummy/app/templates/example/bar/baz.hbs
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
<div class="section">
<span class="template-name">example/bar/baz.hbs</span>

{{#portal-content for="title-append"}}
baz
{{/portal-content}}

{{#portal-content for="header"}}
<div id="baz-header" class="header">
Baz Header - defined in example/bar/baz.hbs
Expand Down
4 changes: 4 additions & 0 deletions tests/dummy/app/templates/example/foo.hbs
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
<div class="section">
<span class="template-name">example/foo.hbs</span>

{{#portal-content for="title-append"}}
foo
{{/portal-content}}

{{#portal-content for="header"}}
<div id="foo-header" class="header">
Foo Header - defined in example/foo.hbs
Expand Down