all files / workbook/actions/ hyperlink.js

100% Statements 55/55
97.22% Branches 35/36
100% Functions 8/8
100% Lines 55/55
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   883× 883×   882× 882×   883×   882× 12×     63× 63× 63× 63× 38× 38× 38× 38×       25× 25×   62× 62×   61× 61× 20× 15×       41× 14×     61× 61× 61× 69× 74×   73× 73× 22× 14×           73× 73×       126650×        
define(["require", "exports", "../base/index", "../common/index", "@syncfusion/ej2-base"], function (require, exports, index_1, index_2, ej2_base_1) {
    "use strict";
    Object.defineProperty(exports, "__esModule", { value: true });
    var WorkbookHyperlink = (function () {
        function WorkbookHyperlink(parent) {
            this.parent = parent;
            this.addEventListener();
        }
        WorkbookHyperlink.prototype.destroy = function () {
            this.removeEventListener();
            this.parent = null;
        };
        WorkbookHyperlink.prototype.addEventListener = function () {
            this.parent.on(index_2.setLinkModel, this.setLinkHandler, this);
        };
        WorkbookHyperlink.prototype.removeEventListener = function () {
            if (!this.parent.isDestroyed) {
                this.parent.off(index_2.setLinkModel, this.setLinkHandler);
            }
        };
        WorkbookHyperlink.prototype.setLinkHandler = function (args) {
            var hyperlink = args.hyperlink;
            var cellAddr = args.cell;
            var sheet;
            if (cellAddr && cellAddr.indexOf('!') !== -1) {
                var lastIndex = cellAddr.lastIndexOf('!');
                sheet = index_1.getSheet(this.parent, index_1.getSheetIndex(this.parent, cellAddr.substring(0, lastIndex)));
                cellAddr = cellAddr.substring(lastIndex + 1);
                if (!sheet) {
                    return;
                }
            }
            else {
                sheet = this.parent.getActiveSheet();
                cellAddr = cellAddr || sheet.selectedRange;
            }
            var isProtected = !args.triggerEvt && sheet.isProtected;
            if (isProtected && !sheet.protectSettings.insertLink) {
                return;
            }
            var cellIdx = index_2.getSwapRange(index_2.getRangeIndexes(cellAddr));
            if (typeof (hyperlink) === 'string') {
                if (hyperlink.toLowerCase().indexOf('www.') === 0) {
                    hyperlink = 'http://' + hyperlink;
                }
            }
            else {
                if (hyperlink.address.toLowerCase().indexOf('www.') === 0) {
                    hyperlink.address = 'http://' + hyperlink.address;
                }
            }
            var cellModel;
            var activeCell = index_2.getRangeIndexes(sheet.activeCell);
            for (var rIdx = cellIdx[0]; rIdx <= cellIdx[2]; rIdx++) {
                for (var cIdx = cellIdx[1]; cIdx <= cellIdx[3]; cIdx++) {
                    if (isProtected && index_2.isLocked(index_1.getCell(rIdx, cIdx, sheet), index_1.getColumn(sheet, cIdx))) {
                        continue;
                    }
                    cellModel = { hyperlink: hyperlink };
                    if (!ej2_base_1.isNullOrUndefined(args.displayText)) {
                        if (args.triggerEvt || args.isUndoRedo) {
                            if (rIdx === activeCell[0] && cIdx === activeCell[1]) {
                                cellModel.value = args.displayText;
                                delete cellModel.formattedText;
                            }
                        }
                        else {
                            cellModel.value = args.displayText;
                            delete cellModel.formattedText;
                        }
                    }
                    cellModel.style = { textDecoration: 'underline', color: '#00e' };
                    index_2.updateCell(this.parent, sheet, { cell: cellModel, rowIdx: rIdx, colIdx: cIdx, preventEvt: !args.triggerEvt });
                }
            }
        };
        WorkbookHyperlink.prototype.getModuleName = function () {
            return 'workbookHyperlink';
        };
        return WorkbookHyperlink;
    }());
    exports.WorkbookHyperlink = WorkbookHyperlink;
});