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;
});
|