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

Re-position 'highlightElement' on window resize #45

Merged
merged 1 commit into from
Jun 21, 2016
Merged
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
32 changes: 24 additions & 8 deletions addon/services/tour.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,6 @@ export default Service.extend(Evented, {
$('#highlightOverlay').remove();
const currentElement = this.getElementForStep(step);
if (currentElement) {
const elementPosition = getElementPosition(currentElement);
const highlightElement = $(currentElement).clone();
highlightElement.attr('id', 'highlightOverlay');
$('body').append(highlightElement);
Expand All @@ -132,13 +131,10 @@ export default Service.extend(Evented, {
window.getComputedStyle(children[i]).cssText;
}

highlightElement.css({
'position': 'absolute',
'left': elementPosition.left,
'top': elementPosition.top,
'width': elementPosition.width,
'height': elementPosition.height,
'z-index': 10002
this.setPositionForHighlightElement({currentElement, highlightElement});

Ember.$(window).on('resize', () => {
run.debounce(this, 'setPositionForHighlightElement', {currentElement, highlightElement}, 50);
});
}
},
Expand Down Expand Up @@ -290,6 +286,26 @@ export default Service.extend(Evented, {
return allElementsPresent;
},

/**
* Set position of the highlighted element
*
* @param currentElement The element that belongs to the step
* @param highlightElement The cloned element that is above the overlay
* @private
*/
setPositionForHighlightElement({currentElement, highlightElement}) {
const elementPosition = getElementPosition(currentElement);

highlightElement.css({
'position': 'absolute',
'left': elementPosition.left,
'top': elementPosition.top,
'width': elementPosition.width,
'height': elementPosition.height,
'z-index': 10002
});
},

/**
* Create a tour object based on the current configuration
*/
Expand Down