Skip to content

Instantly share code, notes, and snippets.

@erikpantzar
Last active October 14, 2016 11:27
Show Gist options
  • Save erikpantzar/31894cf9dc1429138fa5bf3fe3edb264 to your computer and use it in GitHub Desktop.
Save erikpantzar/31894cf9dc1429138fa5bf3fe3edb264 to your computer and use it in GitHub Desktop.
Start of refactor all the atc into a flipout directive
<html>
<element-item attr="123"></element-item>
</html>
module.exports = module;
var module = {
toggleWindow: toggleWindow
scrollToPosition: scrollToPosition
}
// TODO remove all dependancies OR include them in this module
// TODO take block as in parameter to the functions
function toggleWindow() {
if (el.hasClass('atc--open')) {
el.removeClass('atc--open');
scope.cartItem.quantity = 1;
scrollToPosition(startPositionOfScroll);
document.body.classList.remove('atc--visible');
} else {
document.body.classList.add('atc--visible');
el.addClass('atc--open');
// Get the position of the add-to-cart window relative to the top of page.
ATCScrollPosition = $uibPosition.offset(el[0]).top - 60;
scrollToPosition(ATCScrollPosition);
}
}
function scrollToPosition(scrollToY) {
startPositionOfScroll = window.scrollY;
var hopCount = 50;
var gap = (scrollToY - startPositionOfScroll) / hopCount;
/* eslint no-loop-func: "off" */
for (var i = 1; i <= hopCount; i++) {
(function() {
var hopTopPosition = gap * i;
$timeout(function() {
header.classList.remove('js-hide-header--active');
window.scrollTo(0, hopTopPosition + startPositionOfScroll);
}, 10 * i);
}());
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment