all files / schedule/actions/ touch.js

98.21% Statements 165/168
86.21% Branches 100/116
100% Functions 17/17
98.21% Lines 165/168
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259   68× 68× 68×           68× 68× 68×   33×   33× 33×     30× 23×   30×   30× 29× 29× 29×   28× 28×       28× 28× 28×     29× 18× 16× 16×           16×   18× 18×   11× 10× 10×             10× 10×     25×     21× 21×   21×   20× 20× 20× 20× 20×   20×         20× 20×       21×                   24× 21×           21×       24× 24× 23×   24× 24×   21× 15× 15× 15×         20× 20×   20×     20× 20×     19× 19× 19× 19×       16×   19× 19× 19× 19× 19× 18×   19× 19×         25×   21× 21× 21× 21×   21× 16× 16× 16× 16×   21× 21×   28× 28×   45×   203× 203× 203× 203× 203× 203× 203× 203×   68× 68× 68×   68× 68×        
define(["require", "exports", "@syncfusion/ej2-base", "@syncfusion/ej2-base", "../base/constant", "../base/css-constant", "../base/util"], function (require, exports, ej2_base_1, ej2_base_2, events, cls, util) {
    "use strict";
    Object.defineProperty(exports, "__esModule", { value: true });
    var ScheduleTouch = (function () {
        function ScheduleTouch(parent) {
            this.parent = parent;
            this.element = this.parent.element.querySelector('.' + cls.TABLE_CONTAINER_CLASS);
            this.touchObj = new ej2_base_1.Touch(this.element, {
                scroll: this.scrollHandler.bind(this),
                swipe: this.swipeHandler.bind(this),
                tapHold: this.tapHoldHandler.bind(this),
                swipeSettings: { swipeThresholdDistance: 1 }
            });
            ej2_base_1.EventHandler.add(this.element, 'transitionend', this.onTransitionEnd, this);
            this.touchLeftDirection = this.parent.enableRtl ? 'Right' : 'Left';
            this.touchRightDirection = this.parent.enableRtl ? 'Left' : 'Right';
        }
        ScheduleTouch.prototype.scrollHandler = function (e) {
            var blockSwipe = !this.parent.isAdaptive && e.originalEvent && e.originalEvent.target &&
                !ej2_base_2.isNullOrUndefined(ej2_base_2.closest(e.originalEvent.target, '.' + cls.APPOINTMENT_CLASS));
            this.parent.uiStateValues.isTouchScroll = blockSwipe && e.originalEvent.type === 'touchmove' && !this.parent.uiStateValues.action;
            if (blockSwipe || this.parent.currentView === 'Agenda' || this.parent.uiStateValues.action || !this.parent.allowSwiping ||
                this.parent.uiStateValues.isTapHold) {
                return;
            }
            if (!this.timeStampStart) {
                this.timeStampStart = Date.now();
            }
            if (this.element.classList.contains(cls.TRANSLATE_CLASS)) {
                this.onTransitionEnd();
            }
            if (e.scrollDirection === 'Left' || e.scrollDirection === 'Right') {
                var args = { requestType: 'dateNavigate', cancel: false, event: e.originalEvent };
                this.parent.trigger(events.actionBegin, args);
                if (args.cancel) {
                    return;
                }
                var scrollDiv = this.element.querySelector('.' + cls.CONTENT_WRAP_CLASS);
                Iif (scrollDiv && scrollDiv.scrollWidth > scrollDiv.clientWidth) {
                    return;
                }
                else {
                    this.isScrollTriggered = true;
                    e.originalEvent.preventDefault();
                    e.originalEvent.stopPropagation();
                }
            }
            if (e.scrollDirection === this.touchLeftDirection) {
                if (!this.nextPanel) {
                    this.renderPanel(cls.NEXT_PANEL_CLASS, 'next');
                    this.nextPanel = {
                        element: this.parent.activeView.getPanel(),
                        selectedDate: new Date(this.parent.selectedDate.getTime()),
                        renderDates: this.parent.activeView.renderDates,
                        colLevels: this.parent.activeView.colLevels
                    };
                    this.setDimensions(this.nextPanel.element);
                }
                var x = this.parent.enableRtl ? e.distanceX : -e.distanceX;
                this.element.style.transform = 'translatex(' + (this.getTranslateX(this.element) + x) + 'px)';
            }
            else if (e.scrollDirection === this.touchRightDirection) {
                var prevWidth = 0;
                if (!this.previousPanel) {
                    this.renderPanel(cls.PREVIOUS_PANEL_CLASS, 'previous');
                    this.previousPanel = {
                        element: this.parent.activeView.getPanel(),
                        selectedDate: new Date(this.parent.selectedDate.getTime()),
                        renderDates: this.parent.activeView.renderDates,
                        colLevels: this.parent.activeView.colLevels
                    };
                    this.setDimensions(this.previousPanel.element);
                    prevWidth = this.previousPanel.element.offsetWidth;
                }
                var x = this.parent.enableRtl ? prevWidth - e.distanceX : -prevWidth + e.distanceX;
                this.element.style.transform = 'translatex(' + (this.getTranslateX(this.element) + x) + 'px)';
            }
        };
        ScheduleTouch.prototype.swipeHandler = function (e) {
            if (!this.isScrollTriggered || this.parent.uiStateValues.action || !this.parent.allowSwiping ||
                this.parent.uiStateValues.isTapHold) {
                return;
            }
            this.isScrollTriggered = false;
            var swipeDate = e.swipeDirection === 'Left' ?
                this.parent.activeView.renderDates[0] : this.parent.activeView.renderDates.slice(-1)[0];
            if ((e.swipeDirection === 'Left' && swipeDate < this.parent.maxDate) ||
                (e.swipeDirection === 'Right' && swipeDate >= this.parent.minDate)) {
                var time = Date.now() - this.timeStampStart;
                var offsetDist = (e.distanceX * (ej2_base_1.Browser.isDevice ? 6 : 1.66));
                Eif (offsetDist > time || (e.distanceX > (this.parent.element.offsetWidth / 2))) {
                    this.swapPanels(e.swipeDirection);
                    if (offsetDist > time && (e.distanceX > (this.parent.element.offsetWidth / 2))) {
                        this.element.style.transitionDuration = (((ej2_base_1.Browser.isDevice ? e.distanceX : offsetDist) / time) / 10) + 's';
                    }
                    this.confirmSwipe(e.swipeDirection);
                }
                else {
                    this.cancelSwipe();
                }
                var args = { requestType: 'dateNavigate', cancel: false, event: e.originalEvent };
                this.parent.trigger(events.actionComplete, args);
            }
            else {
                this.cancelSwipe();
            }
            this.timeStampStart = null;
        };
        ScheduleTouch.prototype.tapHoldHandler = function (e) {
            var target = ej2_base_2.closest(e.originalEvent.target, '.' + cls.APPOINTMENT_CLASS);
            Eif (!ej2_base_2.isNullOrUndefined(target)) {
                this.parent.uiStateValues.isTapHold = true;
                if (this.parent.isAdaptive) {
                    if (ej2_base_1.Browser.isIos) {
                        ej2_base_1.EventHandler.add(this.element, 'touchend', this.preventEventClick, this);
                    }
                    this.parent.quickPopup.tapHoldEventPopup(e.originalEvent);
                }
                else Eif (['Agenda', 'MonthAgenda', 'Year'].indexOf(this.parent.currentView) < 0) {
                    this.parent.selectedElements = [];
                    this.parent.eventBase.getSelectedEventElements(target);
                    Iif (this.parent.resizeModule && ej2_base_2.closest(e.originalEvent.target, '.' + cls.EVENT_RESIZE_CLASS)) {
                        this.parent.resizeModule.resizeStart(e.originalEvent);
                    }
                }
            }
        };
        ScheduleTouch.prototype.preventEventClick = function (e) {
            e.preventDefault();
            ej2_base_1.EventHandler.remove(this.element, 'touchend', this.preventEventClick);
        };
        ScheduleTouch.prototype.renderPanel = function (clsName, nextPrevType) {
            if (!this.currentPanel) {
                this.currentPanel = {
                    element: this.parent.activeView.getPanel(),
                    selectedDate: new Date(this.parent.selectedDate.getTime()),
                    renderDates: this.parent.activeView.renderDates,
                    colLevels: this.parent.activeView.colLevels
                };
                this.setDimensions(this.currentPanel.element);
            }
            else {
                this.parent.setProperties({ selectedDate: this.currentPanel.selectedDate }, true);
            }
            this.parent.setProperties({ selectedDate: this.parent.activeView.getNextPreviousDate(nextPrevType) }, true);
            if (this.parent.headerModule) {
                this.parent.headerModule.setCalendarDate(this.parent.selectedDate);
            }
            this.parent.activeView.getRenderDates();
            this.parent.activeView.renderLayout(clsName);
        };
        ScheduleTouch.prototype.swapPanels = function (direction) {
            if (direction === this.touchLeftDirection) {
                var temp = this.nextPanel;
                this.nextPanel = this.currentPanel;
                this.currentPanel = temp;
            }
            else {
                var temp = this.previousPanel;
                this.previousPanel = this.currentPanel;
                this.currentPanel = temp;
            }
        };
        ScheduleTouch.prototype.confirmSwipe = function (swipeDirection) {
            var _this = this;
            var previousDate = swipeDirection === this.touchLeftDirection ?
                this.nextPanel.selectedDate : this.previousPanel.selectedDate;
            var args = {
                action: 'date', cancel: false, previousDate: previousDate, currentDate: this.currentPanel.selectedDate
            };
            this.parent.trigger(events.navigating, args, function (navArgs) {
                if (navArgs.cancel) {
                    _this.swapPanels(swipeDirection);
                    _this.cancelSwipe();
                }
                else {
                    _this.parent.activeView.setPanel(_this.currentPanel.element);
                    _this.parent.setProperties({ selectedDate: _this.currentPanel.selectedDate }, true);
                    var translateX = void 0;
                    if (_this.parent.enableRtl) {
                        translateX = swipeDirection === _this.touchLeftDirection ?
                            (_this.previousPanel ? _this.previousPanel.element.offsetLeft : _this.currentPanel.element.offsetWidth) : 0;
                    }
                    else {
                        translateX = swipeDirection === _this.touchLeftDirection ? -_this.currentPanel.element.offsetLeft : 0;
                    }
                    _this.parent.activeView.renderDates = _this.currentPanel.renderDates;
                    _this.parent.activeView.colLevels = _this.currentPanel.colLevels;
                    ej2_base_1.addClass([_this.element], cls.TRANSLATE_CLASS);
                    _this.element.style.transform = 'translatex(' + translateX + 'px)';
                    if (_this.parent.headerModule) {
                        _this.parent.headerModule.updateDateRange();
                    }
                    _this.parent.renderTemplates();
                    _this.parent.crudModule.refreshDataManager();
                }
            });
        };
        ScheduleTouch.prototype.cancelSwipe = function () {
            this.parent.activeView.setPanel(this.currentPanel.element);
            this.parent.setProperties({ selectedDate: this.currentPanel.selectedDate }, true);
            this.parent.activeView.renderDates = this.currentPanel.renderDates;
            this.parent.activeView.colLevels = this.currentPanel.colLevels;
            ej2_base_1.addClass([this.element], cls.TRANSLATE_CLASS);
            var prevWidth = this.previousPanel ? this.previousPanel.element.offsetWidth : 0;
            this.element.style.transform = 'translatex(' + (this.parent.enableRtl ? prevWidth : -this.currentPanel.element.offsetLeft) + 'px)';
        };
        ScheduleTouch.prototype.onTransitionEnd = function () {
            if (!ej2_base_2.isNullOrUndefined(this.element) && !this.element.classList.contains(cls.TRANSLATE_CLASS)) {
                return;
            }
            ej2_base_1.removeClass([this.element], cls.TRANSLATE_CLASS);
            this.element.style.transitionDuration = '';
            this.element.style.transform = '';
            if (this.previousPanel) {
                ej2_base_1.remove(this.previousPanel.element);
                this.previousPanel = null;
                ej2_base_1.removeClass([this.currentPanel.element], cls.PREVIOUS_PANEL_CLASS);
                ej2_base_1.addClass([this.currentPanel.element], cls.CURRENT_PANEL_CLASS);
            }
            if (this.nextPanel) {
                ej2_base_1.remove(this.nextPanel.element);
                this.nextPanel = null;
                ej2_base_1.removeClass([this.currentPanel.element], cls.NEXT_PANEL_CLASS);
                ej2_base_1.addClass([this.currentPanel.element], cls.CURRENT_PANEL_CLASS);
            }
            this.currentPanel = null;
            this.parent.activeView.getPanel().style.width = '';
        };
        ScheduleTouch.prototype.getTranslateX = function (element) {
            var style = window.getComputedStyle(element);
            return new WebKitCSSMatrix(style.webkitTransform).m41;
        };
        ScheduleTouch.prototype.setDimensions = function (element) {
            element.style.width = (this.parent.element.clientWidth) + 'px';
        };
        ScheduleTouch.prototype.resetValues = function () {
            this.currentPanel = null;
            this.previousPanel = null;
            this.nextPanel = null;
            this.timeStampStart = null;
            this.element.style.transform = '';
            this.element.style.transitionDuration = '';
            util.removeChildren(this.element);
            ej2_base_1.removeClass([this.element], cls.TRANSLATE_CLASS);
        };
        ScheduleTouch.prototype.destroy = function () {
            Eif (this.touchObj) {
                this.touchObj.destroy();
                this.touchObj = null;
            }
            ej2_base_1.EventHandler.remove(this.element, 'transitionend', this.onTransitionEnd);
            this.resetValues();
        };
        return ScheduleTouch;
    }());
    exports.ScheduleTouch = ScheduleTouch;
});