export interface IscrollData { elem: any; x: any; y: any; animationstartedcallback?: any, } import {Helpers as helpers} from './Helpers'; export class Scrolling{ static getExistingScrollData($root, $scroll) { let scrollData = $root.data("original-scroll"); if (!scrollData) { scrollData = { "elem": $scroll, "x": 0, "y:": 0 }; } return scrollData; } static storeNewScrollData($root, $scroll, useScrollResetBeforeZoom) { // safari let scrollY = $root.scrollTop(); let scrollX = $root.scrollLeft(); let elem = $root; // moz if (!scrollY) { scrollY = $scroll.scrollTop(); scrollX = $scroll.scrollLeft(); elem = $scroll; } let scrollData:IscrollData = { "elem": elem, "x": scrollX, "y": scrollY }; $root.data("original-scroll", scrollData); $(document).on("touchmove", function (e) { e.preventDefault(); }); let transformStr = "translate(-" + scrollX + "px,-" + scrollY + "px)"; helpers.forEachPrefix(function (prefix) { $root.css(prefix + "transform", transformStr); }); elem.addClass("noScroll"); if (useScrollResetBeforeZoom) { scrollData.animationstartedcallback = function () { // this needs to be after the setTransformation and // done with window.scrollTo to not have iPhone repaints if (elem[0] == document.body || elem[0] == document) { window.scrollTo(0, 0); } else { elem.scrollLeft(0); elem.scrollTop(0); } }; } return scrollData; } static getOuterWidth(elem) { let outerWidth = elem.outerWidth(); if (outerWidth == 0) { outerWidth = elem.prop('scrollWidth'); } return outerWidth; } static getOuterHeight(elem) { let outerHeight = elem.outerHeight(); if (outerHeight == 0) { outerHeight = elem.prop('scrollHeight'); } return outerHeight; } }