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

Fix #104 Toggling renderInPlace #107

Merged
merged 1 commit into from
Sep 20, 2018
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
33 changes: 17 additions & 16 deletions addon/components/ember-wormhole.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,26 @@ export default Component.extend({
*/
to: alias('destinationElementId'),
destinationElementId: null,
destinationElement: computed('destinationElementId', 'renderInPlace', function() {
destinationElement: null,

_destination: computed('destinationElement', 'destinationElementId', 'renderInPlace', function() {
let renderInPlace = this.get('renderInPlace');
if (renderInPlace) {
return this._element;
}
let id = this.get('destinationElementId');
if (!id) {
return null;

let destinationElement = this.get('destinationElement');
if (destinationElement) {
return destinationElement;
}
let destinationElementId = this.get('destinationElementId');
if (destinationElementId) {
return findElementById(this._dom, destinationElementId);
}
return findElementById(this._dom, id);
// no element found
return null;
}),

renderInPlace: false,

/*
Expand Down Expand Up @@ -66,15 +75,15 @@ export default Component.extend({
});
},

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

_appendToDestination() {
var destinationElement = this._getDestinationElement();
var destinationElement = this.get('_destination');
if (!destinationElement) {
var destinationElementId = this.get('destinationElementId');
if (destinationElementId) {
Expand Down Expand Up @@ -111,12 +120,4 @@ 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: 4 additions & 2 deletions testem.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,10 @@ module.exports = {
'--disable-gpu',
'--headless',
'--remote-debugging-port=0',
'--window-size=1440,900'
]
'--window-size=1440,900',
// --no-sandbox is needed when running Chrome inside a container
process.env.TRAVIS ? '--no-sandbox' : null,
].filter(Boolean)
}
}
};
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.contentNotIn('othersidebar');
assert.contentIn('example-sidebar');
assert.contentIn('othersidebar');
assert.contentNotIn('example-sidebar');
});
click('#sidebarWormhole button:contains(Hide)');
click('button:contains(Hide)');
andThen(function() {
assert.contentNotIn('sidebar');
assert.contentNotIn('othersidebar');
Expand Down
33 changes: 33 additions & 0 deletions tests/integration/components/ember-wormhole-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,37 @@ test('if `renderInPlace` is truthy, the given `destinationElement` is ignored',

let content = document.querySelector('#wormhole-content');
assert.notEqual(content.parentElement.id, 'wormhole-destination-element');

Ember.run(() => {
this.set('renderInPlace', false);
});

assert.equal(content.parentElement.id, 'wormhole-destination-element');
});

test('can switch `renderInPlace` with `destinationElementId`', function(assert) {
this.renderInPlace = true;

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

let content = document.querySelector('#wormhole-content');
assert.notEqual(content.parentElement.id, 'wormhole-destination-element');

Ember.run(() => {
this.set('renderInPlace', false);
});

assert.equal(content.parentElement.id, 'wormhole-destination-element');

Ember.run(() => {
// switch back
this.set('renderInPlace', true);
});

assert.notEqual(content.parentElement.id, 'wormhole-destination-element');
});