all files / base/ splitter.js

95.08% Statements 116/122
89.06% Branches 57/64
100% Functions 17/17
95% Lines 114/120
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   1137× 1137×   1137× 1137× 1137× 1137× 1137× 1137× 1137× 23× 23×     1114× 1114×   1137×                                                               1137× 1137× 1137× 1137× 1137× 1137× 1137×     2295×   2290×   2284×     2279× 617×   1662× 504× 504×             1158× 1158× 1158× 1158×       4570× 4570× 2284× 1667× 1667×       617×     611×         4570×   504× 504× 504× 4393× 4024× 504× 504× 504× 20× 62×   20×     484× 1934×     504×   1149× 1149× 1149× 1149× 1149× 1149× 232×                           2272× 2272×        
define(["require", "exports", "@syncfusion/ej2-base", "../base/css-constants", "@syncfusion/ej2-layouts", "@syncfusion/ej2-data"], function (require, exports, ej2_base_1, cls, ej2_layouts_1, ej2_data_1) {
    "use strict";
    Object.defineProperty(exports, "__esModule", { value: true });
    var Splitter = (function () {
        function Splitter(ganttObj) {
            this.parent = ganttObj;
            this.parent.on('destroy', this.destroy, this);
        }
        Splitter.prototype.renderSplitter = function () {
            var _this = this;
            var splitterPosition = this.calculateSplitterPosition(this.parent.splitterSettings);
            this.parent.splitterElement = ej2_base_1.createElement('div', { className: cls.splitter });
            this.parent.treeGridPane = ej2_base_1.createElement('div', { className: cls.treeGridPane });
            this.parent.chartPane = ej2_base_1.createElement('div', { className: cls.ganttChartPane });
            ej2_base_1.addClass([this.parent.chartPane], 'e-droppable');
            if (this.parent.enableRtl) {
                this.parent.splitterElement.appendChild(this.parent.chartPane);
                this.parent.splitterElement.appendChild(this.parent.treeGridPane);
            }
            else {
                this.parent.splitterElement.appendChild(this.parent.treeGridPane);
                this.parent.splitterElement.appendChild(this.parent.chartPane);
            }
            this.splitterObject = new ej2_layouts_1.Splitter({
                height: null,
                width: this.parent.ganttWidth.toString(),
                enableRtl: this.parent.enableRtl,
                separatorSize: this.parent.splitterSettings.separatorSize,
                paneSettings: [
                    {
                        resizable: true,
                        size: splitterPosition,
                        min: this.getSpliterPositionInPercentage(this.parent.splitterSettings.minimum)
                    },
                    {
                        resizable: true
                    }
                ],
                orientation: 'Horizontal',
                resizeStart: function (args) {
                    Iif (_this.parent.contextMenuModule && _this.parent.contextMenuModule.isOpen) {
                        _this.parent.contextMenuModule.contextMenu.close();
                    }
                    var leftPane = args.pane[0];
                    var rightPane = args.pane[1];
                    _this.splitterPreviousPositionGrid = leftPane.scrollWidth + 1 + 'px';
                    _this.splitterPreviousPositionChart = rightPane.scrollWidth + 1 + 'px';
                    var callBackPromise = new ej2_data_1.Deferred();
                    _this.parent.trigger('splitterResizeStart', args, function (resizeStartArgs) {
                        callBackPromise.resolve(resizeStartArgs);
                    });
                    return callBackPromise;
                },
                resizing: function (args) {
                    _this.parent.trigger('splitterResizing', args);
                    Iif (_this.parent.timelineModule.isZoomToFit) {
                        _this.parent.timelineModule.updateTimelineAfterZooming(_this.parent.timelineModule.timelineEndDate, true);
                    }
                },
                resizeStop: function (args) {
                    _this.parent['calculateDimensions']();
                    var leftPane = args.pane[0];
                    _this.splitterPreviousPositionGrid = leftPane.scrollWidth + 1 + 'px';
                    _this.splitterObject.paneSettings[0].size = _this.getSpliterPositionInPercentage(_this.splitterPreviousPositionGrid);
                    _this.parent.splitterSettings.position = _this.splitterObject.paneSettings[0].size;
                    _this.splitterObject.paneSettings[1].size = (_this.parent.ganttWidth - parseInt(_this.splitterPreviousPositionGrid, 10) - 4) + 'px';
                    var callBackPromise = new ej2_data_1.Deferred();
                    _this.parent.trigger('splitterResized', args, function (splitterResizedArgs) {
                        if (splitterResizedArgs.cancel === true) {
                            _this.splitterObject.paneSettings[0].size = null;
                            _this.splitterObject.paneSettings[0].size = _this.getSpliterPositionInPercentage(_this.splitterPreviousPositionGrid);
                            _this.splitterObject.paneSettings[1].size = null;
                            _this.splitterObject.paneSettings[1].size = _this.getSpliterPositionInPercentage(_this.splitterPreviousPositionChart);
                        }
                        Iif (ej2_base_1.isNullOrUndefined(_this.parent.projectEndDate)) {
                            _this.parent.timelineModule.updateTimelineAfterZooming(_this.parent.timelineModule.timelineEndDate, true);
                        }
                        callBackPromise.resolve(splitterResizedArgs);
                    });
                    return callBackPromise;
                }
            });
            this.parent.element.appendChild(this.parent.splitterElement);
            this.splitterObject.appendTo(this.parent.splitterElement);
            var splitterLeftPane = this.splitterObject.element.querySelector('.e-split-bar');
            Eif (splitterLeftPane) {
                var numericValue = parseFloat(splitterPosition.replace('%', ''));
                var ariaValueNow = Math.min(100, Math.max(0, numericValue));
                splitterLeftPane.setAttribute('aria-valuenow', ariaValueNow.toString());
            }
        };
        Splitter.prototype.calculateSplitterPosition = function (splitter) {
            if (!ej2_base_1.isNullOrUndefined(this.splitterObject) && this.parent.enablePersistence) {
                return this.splitterObject.paneSettings[0].size;
            }
            if (splitter.view === 'Grid') {
                return this.parent.enableRtl ? '0%' : '100%';
            }
            else if (splitter.view === 'Chart') {
                return this.parent.enableRtl ? '100%' : '0%';
            }
            else {
                if (!ej2_base_1.isNullOrUndefined(splitter.position) && splitter.position !== '') {
                    return this.getSpliterPositionInPercentage(splitter.position);
                }
                else if (!ej2_base_1.isNullOrUndefined(splitter.columnIndex) && splitter.columnIndex >= 0) {
                    Eif ((splitter.columnIndex * 150) < this.parent.ganttWidth || !this.parent.element.classList.contains('e-device')) {
                        return this.getSpliterPositionInPercentage(this.getTotalColumnWidthByIndex(splitter.columnIndex).toString() + 'px');
                    }
                    else {
                        return this.getSpliterPositionInPercentage((splitter.columnIndex * 130) + 'px');
                    }
                }
                else {
                    var ganttWidth = this.parent.ganttWidth;
                    var width = ganttWidth - 250;
                    var widthAsString = width + 'px';
                    return (this.parent.enableRtl) ? this.getSpliterPositionInPercentage(widthAsString) : this.getSpliterPositionInPercentage('250px');
                }
            }
        };
        Splitter.prototype.getSpliterPositionInPercentage = function (position) {
            var value = !ej2_base_1.isNullOrUndefined(position) && position !== '' ? position : null;
            if (!ej2_base_1.isNullOrUndefined(value)) {
                if (position.indexOf('px') !== -1) {
                    var intValue = parseInt(position, 10);
                    value = (((intValue / this.parent.ganttWidth) * 100) <= 100 ? ((intValue / this.parent.ganttWidth) * 100) + '%' :
                        '25%');
                }
                else {
                    if (this.parent.enableRtl) {
                        var newPosition = 100 - parseFloat(position);
                        value = newPosition + '%';
                    }
                    else {
                        value = position.indexOf('%') === -1 ?
                            position + '%' : position;
                    }
                }
            }
            return value;
        };
        Splitter.prototype.getTotalColumnWidthByIndex = function (index) {
            var width = 0;
            var ganttWidth = this.parent.ganttWidth;
            var originalArray = this.parent.ganttColumns;
            var newArray = originalArray.filter(function (obj) { return obj.visible === undefined || obj.visible === true; });
            var deepCopiedArray = newArray.map(function (obj) { return Object.assign({}, obj); });
            var tr = deepCopiedArray;
            index = tr.length > index ? index : tr.length;
            if (this.parent.enableRtl) {
                for (var column = 0; column < index; column++) {
                    width += parseInt(tr[column].width, 10);
                }
                width = ganttWidth - width;
            }
            else {
                for (var column = 0; column < index; column++) {
                    width += parseInt(tr[column].width, 10);
                }
            }
            return width;
        };
        Splitter.prototype.updateSplitterPosition = function () {
            this.splitterObject.separatorSize = this.parent.splitterSettings.separatorSize;
            var splitterPosition = this.calculateSplitterPosition(this.parent.splitterSettings);
            this.splitterObject.paneSettings[0].min = this.getSpliterPositionInPercentage(this.parent.splitterSettings.minimum);
            this.splitterObject.dataBind();
            this.splitterObject.paneSettings[0].size = splitterPosition;
            if (ej2_base_1.isNullOrUndefined(this.parent.projectEndDate)) {
                this.parent.timelineModule.updateTimelineAfterZooming(this.parent.timelineModule.timelineEndDate, true);
            }
        };
        Splitter.prototype.triggerCustomResizedEvent = function () {
            var pane1 = this.splitterObject.element.querySelectorAll('.e-pane')[0];
            var pane2 = this.splitterObject.element.querySelectorAll('.e-pane')[1];
            var eventArgs = {
                event: null,
                element: this.splitterObject.element,
                pane: [pane1, pane2],
                index: [0, 1],
                separator: this.splitterObject.element.querySelector('.e-split-bar'),
                paneSize: [pane1.offsetWidth, pane2.offsetWidth]
            };
            this.parent.trigger('splitterResized', eventArgs);
            Iif (eventArgs.cancel === true) {
                this.splitterObject.paneSettings[0].size = this.getSpliterPositionInPercentage(this.splitterPreviousPositionGrid);
                this.splitterObject.paneSettings[1].size = this.getSpliterPositionInPercentage(this.splitterPreviousPositionChart);
            }
        };
        Splitter.prototype.destroy = function () {
            this.splitterObject.destroy();
            this.parent.off('destroy', this.destroy);
        };
        return Splitter;
    }());
    exports.Splitter = Splitter;
});