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

[BUGFIX] If renderInPlace is true, destinationElement is ignored #101

Merged
Merged
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
13 changes: 10 additions & 3 deletions addon/components/ember-wormhole.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,14 +67,14 @@ export default Component.extend({
},

_destinationDidChange: observer('destinationElement', function() {
var destinationElement = this.get('destinationElement');
var destinationElement = this._getDestinationElement();
if (destinationElement !== this._wormholeHeadNode.parentNode) {
run.schedule('render', this, '_appendToDestination');
}
}),

_appendToDestination() {
var destinationElement = this.get('destinationElement');
var destinationElement = this._getDestinationElement();
if (!destinationElement) {
var destinationElementId = this.get('destinationElementId');
if (destinationElementId) {
Expand Down Expand Up @@ -110,6 +110,13 @@ export default Component.extend({
}
node = next;
} while (node);
}
},

_getDestinationElement() {
let renderInPlace = this.get('renderInPlace');
if (renderInPlace) {
return this._element;
}
return this.get('destinationElement');
}
});
6 changes: 3 additions & 3 deletions tests/acceptance/wormhole-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,10 +105,10 @@ test('sidebar example in place', function(assert) {
click('button:contains(Toggle In Place)');
andThen(function() {
assert.contentNotIn('sidebar');
assert.contentIn('othersidebar');
assert.contentNotIn('example-sidebar');
assert.contentNotIn('othersidebar');
assert.contentIn('example-sidebar');
});
click('#othersidebar button:contains(Hide)');
click('#sidebarWormhole button:contains(Hide)');
andThen(function() {
assert.contentNotIn('sidebar');
assert.contentNotIn('othersidebar');
Expand Down
23 changes: 23 additions & 0 deletions tests/integration/components/ember-wormhole-test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { moduleForComponent, test } from 'ember-qunit';
import hbs from 'htmlbars-inline-precompile';
import Ember from 'ember';

moduleForComponent('ember-wormhole', 'Integration | Component | ember wormhole', {
integration: true
Expand All @@ -19,3 +20,25 @@ test('it renders', function(assert) {

assert.equal(this.$('#wormhole').text().trim(), 'template block text');
});

test('if `renderInPlace` is truthy, the given `destinationElement` is ignored', function(assert) {
this.renderEnabled = false;
this.renderInPlace = true;

this.render(hbs`
<div id="wormhole-destination-element"></div>
{{#if renderEnabled}}
{{#ember-wormhole renderInPlace=renderInPlace destinationElement=destinationElement}}
<span id="wormhole-content">template block text</span>
{{/ember-wormhole}}
{{/if}}
`);

Ember.run(() => {
this.set('destinationElement', document.querySelector('#wormhole-destination-element'));
this.set('renderEnabled', true);
});

let content = document.querySelector('#wormhole-content');
assert.notEqual(content.parentElement.id, 'wormhole-destination-element');
});
65 changes: 44 additions & 21 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,10 @@ ansi-escapes@^3.0.0:
version "3.0.0"
resolved "https://registry.yarnpkg.com/ansi-escapes/-/ansi-escapes-3.0.0.tgz#ec3e8b4e9f8064fc02c3ac9b65f1c275bda8ef92"

ansi-regex@*, ansi-regex@^3.0.0:
version "3.0.0"
resolved "https://registry.yarnpkg.com/ansi-regex/-/ansi-regex-3.0.0.tgz#ed0317c322064f79466c02966bddb605ab37d998"

ansi-regex@^0.2.0, ansi-regex@^0.2.1:
version "0.2.1"
resolved "https://registry.yarnpkg.com/ansi-regex/-/ansi-regex-0.2.1.tgz#0d8e946967a3d8143f93e24e298525fc1b2235f9"
Expand All @@ -161,10 +165,6 @@ ansi-regex@^2.0.0:
version "2.1.1"
resolved "https://registry.yarnpkg.com/ansi-regex/-/ansi-regex-2.1.1.tgz#c3b33ab5ee360d86e0e628f0468ae7ef27d654df"

ansi-regex@^3.0.0:
version "3.0.0"
resolved "https://registry.yarnpkg.com/ansi-regex/-/ansi-regex-3.0.0.tgz#ed0317c322064f79466c02966bddb605ab37d998"

ansi-styles@^1.1.0:
version "1.1.0"
resolved "https://registry.yarnpkg.com/ansi-styles/-/ansi-styles-1.1.0.tgz#eaecbf66cd706882760b2f4691582b8f55d7a7de"
Expand Down Expand Up @@ -2220,7 +2220,7 @@ debug@^3.0.1, debug@^3.1.0:
dependencies:
ms "2.0.0"

debuglog@^1.0.1:
debuglog@*, debuglog@^1.0.1:
version "1.0.1"
resolved "https://registry.yarnpkg.com/debuglog/-/debuglog-1.0.1.tgz#aa24ffb9ac3df9a2351837cfb2d279360cd78492"

Expand Down Expand Up @@ -4035,7 +4035,7 @@ ignore@^3.3.3:
version "3.3.7"
resolved "https://registry.yarnpkg.com/ignore/-/ignore-3.3.7.tgz#612289bfb3c220e186a58118618d5be8c1bab021"

imurmurhash@^0.1.4:
imurmurhash@*, imurmurhash@^0.1.4:
version "0.1.4"
resolved "https://registry.yarnpkg.com/imurmurhash/-/imurmurhash-0.1.4.tgz#9218b9b2b928a238b13dc4fb6b6d576f231453ea"

Expand Down Expand Up @@ -4657,7 +4657,7 @@ lodash._basefor@^3.0.0:
version "3.0.3"
resolved "https://registry.yarnpkg.com/lodash._basefor/-/lodash._basefor-3.0.3.tgz#7550b4e9218ef09fad24343b612021c79b4c20c2"

lodash._baseindexof@^3.0.0:
lodash._baseindexof@*, lodash._baseindexof@^3.0.0:
version "3.1.0"
resolved "https://registry.yarnpkg.com/lodash._baseindexof/-/lodash._baseindexof-3.1.0.tgz#fe52b53a1c6761e42618d654e4a25789ed61822c"

Expand All @@ -4669,6 +4669,13 @@ lodash._baseisequal@^3.0.0:
lodash.istypedarray "^3.0.0"
lodash.keys "^3.0.0"

lodash._baseuniq@*:
version "4.6.0"
resolved "https://registry.yarnpkg.com/lodash._baseuniq/-/lodash._baseuniq-4.6.0.tgz#0ebb44e456814af7905c6212fa2c9b2d51b841e8"
dependencies:
lodash._createset "~4.0.0"
lodash._root "~3.0.0"

lodash._baseuniq@^3.0.0:
version "3.0.3"
resolved "https://registry.yarnpkg.com/lodash._baseuniq/-/lodash._baseuniq-3.0.3.tgz#2123fa0db2d69c28d5beb1c1f36d61522a740234"
Expand All @@ -4677,11 +4684,11 @@ lodash._baseuniq@^3.0.0:
lodash._cacheindexof "^3.0.0"
lodash._createcache "^3.0.0"

lodash._bindcallback@^3.0.0:
lodash._bindcallback@*, lodash._bindcallback@^3.0.0:
version "3.0.1"
resolved "https://registry.yarnpkg.com/lodash._bindcallback/-/lodash._bindcallback-3.0.1.tgz#e531c27644cf8b57a99e17ed95b35c748789392e"

lodash._cacheindexof@^3.0.0:
lodash._cacheindexof@*, lodash._cacheindexof@^3.0.0:
version "3.0.2"
resolved "https://registry.yarnpkg.com/lodash._cacheindexof/-/lodash._cacheindexof-3.0.2.tgz#3dc69ac82498d2ee5e3ce56091bafd2adc7bde92"

Expand All @@ -4693,12 +4700,16 @@ lodash._createassigner@^3.0.0:
lodash._isiterateecall "^3.0.0"
lodash.restparam "^3.0.0"

lodash._createcache@^3.0.0:
lodash._createcache@*, lodash._createcache@^3.0.0:
version "3.1.2"
resolved "https://registry.yarnpkg.com/lodash._createcache/-/lodash._createcache-3.1.2.tgz#56d6a064017625e79ebca6b8018e17440bdcf093"
dependencies:
lodash._getnative "^3.0.0"

lodash._createset@~4.0.0:
version "4.0.3"
resolved "https://registry.yarnpkg.com/lodash._createset/-/lodash._createset-4.0.3.tgz#0f4659fbb09d75194fa9e2b88a6644d363c9fe26"

lodash._createwrapper@~2.3.0:
version "2.3.0"
resolved "https://registry.yarnpkg.com/lodash._createwrapper/-/lodash._createwrapper-2.3.0.tgz#d1aae1102dadf440e8e06fc133a6edd7fe146075"
Expand All @@ -4717,7 +4728,7 @@ lodash._escapestringchar@~2.3.0:
version "2.3.0"
resolved "https://registry.yarnpkg.com/lodash._escapestringchar/-/lodash._escapestringchar-2.3.0.tgz#cce73ae60fc6da55d2bf8a0679c23ca2bab149fc"

lodash._getnative@^3.0.0:
lodash._getnative@*, lodash._getnative@^3.0.0:
version "3.9.1"
resolved "https://registry.yarnpkg.com/lodash._getnative/-/lodash._getnative-3.9.1.tgz#570bc7dede46d61cdcde687d65d3eecbaa3aaff5"

Expand Down Expand Up @@ -4752,6 +4763,10 @@ lodash._reunescapedhtml@~2.3.0:
lodash._htmlescapes "~2.3.0"
lodash.keys "~2.3.0"

lodash._root@~3.0.0:
version "3.0.1"
resolved "https://registry.yarnpkg.com/lodash._root/-/lodash._root-3.0.1.tgz#fba1c4524c19ee9a5f8136b4609f017cf4ded692"

lodash._setbinddata@~2.3.0:
version "2.3.0"
resolved "https://registry.yarnpkg.com/lodash._setbinddata/-/lodash._setbinddata-2.3.0.tgz#e5610490acd13277d59858d95b5f2727f1508f04"
Expand Down Expand Up @@ -4863,10 +4878,14 @@ lodash.identity@~2.3.0:
version "2.3.0"
resolved "https://registry.yarnpkg.com/lodash.identity/-/lodash.identity-2.3.0.tgz#6b01a210c9485355c2a913b48b6711219a173ded"

lodash.isarguments@^3.0.0:
lodash.isarguments@*, lodash.isarguments@^3.0.0:
version "3.1.0"
resolved "https://registry.yarnpkg.com/lodash.isarguments/-/lodash.isarguments-3.1.0.tgz#2f573d85c6a24289ff00663b491c1d338ff3458a"

lodash.isarray@*:
version "4.0.0"
resolved "https://registry.yarnpkg.com/lodash.isarray/-/lodash.isarray-4.0.0.tgz#2aca496b28c4ca6d726715313590c02e6ea34403"

lodash.isarray@^3.0.0:
version "3.0.4"
resolved "https://registry.yarnpkg.com/lodash.isarray/-/lodash.isarray-3.0.4.tgz#79e4eb88c36a8122af86f844aa9bcd851b5fbb55"
Expand All @@ -4885,6 +4904,10 @@ lodash.istypedarray@^3.0.0:
version "3.0.6"
resolved "https://registry.yarnpkg.com/lodash.istypedarray/-/lodash.istypedarray-3.0.6.tgz#c9a477498607501d8e8494d283b87c39281cef62"

lodash.keys@*:
version "4.2.0"
resolved "https://registry.yarnpkg.com/lodash.keys/-/lodash.keys-4.2.0.tgz#a08602ac12e4fb83f91fc1fb7a360a4d9ba35205"

lodash.keys@^3.0.0:
version "3.1.2"
resolved "https://registry.yarnpkg.com/lodash.keys/-/lodash.keys-3.1.2.tgz#4dbc0472b156be50a0b286855d1bd0b0c656098a"
Expand Down Expand Up @@ -4931,7 +4954,7 @@ lodash.pairs@^3.0.0:
dependencies:
lodash.keys "^3.0.0"

lodash.restparam@^3.0.0:
lodash.restparam@*, lodash.restparam@^3.0.0:
version "3.6.1"
resolved "https://registry.yarnpkg.com/lodash.restparam/-/lodash.restparam-3.6.1.tgz#936a4e309ef330a7645ed4145986c85ae5b20805"

Expand Down Expand Up @@ -6148,7 +6171,7 @@ readable-stream@~2.0.5:
string_decoder "~0.10.x"
util-deprecate "~1.0.1"

readdir-scoped-modules@^1.0.0:
readdir-scoped-modules@*, readdir-scoped-modules@^1.0.0:
version "1.0.2"
resolved "https://registry.yarnpkg.com/readdir-scoped-modules/-/readdir-scoped-modules-1.0.2.tgz#9fafa37d286be5d92cbaebdee030dc9b5f406747"
dependencies:
Expand Down Expand Up @@ -6923,6 +6946,12 @@ stringstream@~0.0.4, stringstream@~0.0.5:
version "0.0.5"
resolved "https://registry.yarnpkg.com/stringstream/-/stringstream-0.0.5.tgz#4e484cd4de5a0bbbee18e46307710a8a81621878"

strip-ansi@*, strip-ansi@^4.0.0:
version "4.0.0"
resolved "https://registry.yarnpkg.com/strip-ansi/-/strip-ansi-4.0.0.tgz#a8479022eb1ac368a871389b635262c505ee368f"
dependencies:
ansi-regex "^3.0.0"

strip-ansi@^0.3.0:
version "0.3.0"
resolved "https://registry.yarnpkg.com/strip-ansi/-/strip-ansi-0.3.0.tgz#25f48ea22ca79187f3174a4db8759347bb126220"
Expand All @@ -6935,12 +6964,6 @@ strip-ansi@^3.0.0, strip-ansi@^3.0.1:
dependencies:
ansi-regex "^2.0.0"

strip-ansi@^4.0.0:
version "4.0.0"
resolved "https://registry.yarnpkg.com/strip-ansi/-/strip-ansi-4.0.0.tgz#a8479022eb1ac368a871389b635262c505ee368f"
dependencies:
ansi-regex "^3.0.0"

strip-bom@^3.0.0:
version "3.0.0"
resolved "https://registry.yarnpkg.com/strip-bom/-/strip-bom-3.0.0.tgz#2334c18e9c759f7bdd56fdef7e9ae3d588e68ed3"
Expand Down Expand Up @@ -7384,7 +7407,7 @@ uuid@^3.0.0, uuid@^3.1.0:
version "3.1.0"
resolved "https://registry.yarnpkg.com/uuid/-/uuid-3.1.0.tgz#3dd3d3e790abc24d7b0d3a034ffababe28ebbc04"

validate-npm-package-license@^3.0.1:
validate-npm-package-license@*, validate-npm-package-license@^3.0.1:
version "3.0.1"
resolved "https://registry.yarnpkg.com/validate-npm-package-license/-/validate-npm-package-license-3.0.1.tgz#2804babe712ad3379459acfbe24746ab2c303fbc"
dependencies:
Expand Down