Last active
October 14, 2016 11:27
-
-
Save erikpantzar/31894cf9dc1429138fa5bf3fe3edb264 to your computer and use it in GitHub Desktop.
Start of refactor all the atc into a flipout directive
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<html> | |
<element-item attr="123"></element-item> | |
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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