all files / workbook/integrations/ image.js

100% Statements 32/32
90.91% Branches 20/22
100% Functions 8/8
100% Lines 32/32
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   882× 882×   39× 39×   39×   39× 39× 39× 39× 39× 39× 14× 14× 14×     39×   882×   881× 12×     881× 881×   126650×        
define(["require", "exports", "../common/index", "../base/index", "../common/event", "@syncfusion/ej2-base"], function (require, exports, index_1, index_2, event_1, ej2_base_1) {
    "use strict";
    Object.defineProperty(exports, "__esModule", { value: true });
    var WorkbookImage = (function () {
        function WorkbookImage(parent) {
            this.parent = parent;
            this.addEventListener();
        }
        WorkbookImage.prototype.setImage = function (args) {
            var lastIndex = args.range ? args.range.lastIndexOf('!') : -1;
            var imgRange = args.range ? (lastIndex > -1) ? args.range.substring(lastIndex + 1) : args.range
                : this.parent.getActiveSheet().selectedRange;
            var sheetIdx = (args.range && lastIndex > -1) ?
                index_2.getSheetIndex(this.parent, args.range.substring(0, lastIndex)) : this.parent.activeSheetIndex;
            var indexes = index_1.getRangeIndexes(imgRange);
            var sheet = ej2_base_1.isUndefined(sheetIdx) ? this.parent.getActiveSheet() : index_2.getSheet(this.parent, sheetIdx);
            var cell = index_2.getCell(indexes[0], indexes[1], sheet);
            var oldImgData;
            var imgData = args.options;
            if (cell && cell.image) {
                oldImgData = cell.image;
                for (var i = 0; i < imgData.length; i++) {
                    oldImgData.push(imgData[i]);
                }
            }
            index_2.setCell(indexes[0], indexes[1], sheet, { image: (cell && cell.image) ? oldImgData : imgData }, true);
        };
        WorkbookImage.prototype.addEventListener = function () {
            this.parent.on(event_1.setImage, this.setImage, this);
        };
        WorkbookImage.prototype.removeEventListener = function () {
            if (!this.parent.isDestroyed) {
                this.parent.off(event_1.setImage, this.setImage);
            }
        };
        WorkbookImage.prototype.destroy = function () {
            this.removeEventListener();
            this.parent = null;
        };
        WorkbookImage.prototype.getModuleName = function () {
            return 'workbookImage';
        };
        return WorkbookImage;
    }());
    exports.WorkbookImage = WorkbookImage;
});