all files / rich-text-editor/renderer/ link-module.js

96.72% Statements 324/335
91.19% Branches 207/227
100% Functions 31/31
96.72% Lines 324/335
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 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550   1794× 1794× 1794× 1794× 1794× 1794× 1794× 1794× 1794×   1794×     1794× 1794× 1794× 1794× 1794× 1794× 1794× 1794× 1794× 1794× 1794× 1794× 1794× 1794×   15× 15×           1793× 1793× 1793× 1793× 1793× 1793× 1793× 1793× 1793× 1793× 1793× 1793× 1793× 1793×   11×     3610×             1805× 1805×   72×   72× 72× 72×   38×   34× 34× 34× 34× 34× 34× 37× 34×     34×       25× 25× 25× 25×   34× 34×       186×     333×       333× 333× 333× 21×   312× 202× 202× 202× 202× 202× 202×     32×   26× 25×                                             170×       605× 605×   14×   14×                                                       11×     70× 70×   68×       65× 65× 65× 65× 65× 65× 65×     65× 65×     65×         65×         65× 65× 65× 65× 65× 65× 65× 65×   65× 65× 65× 65×   65× 65× 65× 65× 65×                               55× 55× 15× 14×         55× 55× 55× 55× 55×     65× 65× 65× 65× 65×   62× 14× 14× 14× 14× 14× 14×   62× 62×     23×   62× 62×           40× 40× 40× 40× 40× 39×   40× 40× 40×   40×   36×                 32×   36× 36×       36×       36× 36×   36×   36× 35×   36× 25×   36× 36×                   36×   36×   36×   36× 36× 36×   98× 98× 98×     94×                                     244× 244×   15× 15× 15× 15× 14× 14×         14×               11× 11×               3560× 1767×   1793× 1793× 1793× 1793×   32202×        
define(["require", "exports", "@syncfusion/ej2-base", "@syncfusion/ej2-base", "../base/constant", "../base/classes", "@syncfusion/ej2-buttons", "../base/enum", "../base/util", "../../common/util"], function (require, exports, ej2_base_1, ej2_base_2, events, classes_1, ej2_buttons_1, enum_1, util_1, util_2) {
    "use strict";
    Object.defineProperty(exports, "__esModule", { value: true });
    var Link = (function () {
        function Link(parent, serviceLocator) {
            this.parent = parent;
            this.rteID = parent.element.id;
            this.i10n = serviceLocator.getService('rteLocale');
            this.addEventListener();
            this.serviceLocator = serviceLocator;
            this.rendererFactory = serviceLocator.getService('rendererFactory');
            this.dialogRenderObj = serviceLocator.getService('dialogRenderObject');
            this.isDestroyed = false;
            this.mouseDown = this.onDocumentClick.bind(this);
        }
        Link.prototype.addEventListener = function () {
            Iif (this.parent.isDestroyed) {
                return;
            }
            this.parent.on(events.insertLink, this.linkDialog, this);
            this.parent.on(events.showLinkDialog, this.showDialog, this);
            this.parent.on(events.closeLinkDialog, this.closeDialog, this);
            this.parent.on(events.keyDown, this.onKeyDown, this);
            this.parent.on(events.insertCompleted, this.showLinkQuickToolbar, this);
            this.parent.on(events.clearDialogObj, this.clearDialogObj, this);
            this.parent.on(events.linkToolbarAction, this.onToolbarAction, this);
            this.parent.on(events.iframeMouseDown, this.onIframeMouseDown, this);
            this.parent.on(events.unLink, this.removeLink, this);
            this.parent.on(events.editLink, this.editLink, this);
            this.parent.on(events.openLink, this.openLink, this);
            this.parent.on(events.editAreaClick, this.editAreaClickHandler, this);
            this.parent.on(events.bindCssClass, this.setCssClass, this);
            this.parent.on(events.destroy, this.destroy, this);
        };
        Link.prototype.onToolbarAction = function (args) {
            var item = args.args.item;
            switch (item.subCommand) {
                case 'OpenLink':
                    this.parent.notify(events.openLink, args);
                    break;
                case 'EditLink':
                    this.parent.notify(events.editLink, args);
                    break;
                case 'RemoveLink':
                    this.parent.notify(events.unLink, args);
                    break;
            }
        };
        Link.prototype.removeEventListener = function () {
            this.parent.off(events.insertLink, this.linkDialog);
            this.parent.off(events.showLinkDialog, this.showDialog);
            this.parent.off(events.closeLinkDialog, this.closeDialog);
            this.parent.off(events.keyDown, this.onKeyDown);
            this.parent.off(events.insertCompleted, this.showLinkQuickToolbar);
            this.parent.off(events.clearDialogObj, this.clearDialogObj);
            this.parent.off(events.linkToolbarAction, this.onToolbarAction);
            this.parent.off(events.unLink, this.removeLink);
            this.parent.off(events.iframeMouseDown, this.onIframeMouseDown);
            this.parent.off(events.editLink, this.editLink);
            this.parent.off(events.openLink, this.openLink);
            this.parent.off(events.editAreaClick, this.editAreaClickHandler);
            this.parent.off(events.bindCssClass, this.setCssClass);
            this.parent.off(events.destroy, this.destroy);
        };
        Link.prototype.onIframeMouseDown = function () {
            if (this.dialogObj) {
                this.dialogObj.hide({ returnValue: true });
            }
        };
        Link.prototype.updateCss = function (currentObj, e) {
            if (currentObj && e.cssClass) {
                Iif (ej2_base_1.isNullOrUndefined(e.oldCssClass)) {
                    currentObj.setProperties({ cssClass: (currentObj.cssClass + ' ' + e.cssClass).trim() });
                }
                else {
                    currentObj.setProperties({ cssClass: (currentObj.cssClass.replace(e.oldCssClass, '').trim() + ' ' + e.cssClass).trim() });
                }
            }
        };
        Link.prototype.setCssClass = function (e) {
            this.updateCss(this.checkBoxObj, e);
            this.updateCss(this.dialogObj, e);
        };
        Link.prototype.showLinkQuickToolbar = function (e) {
            Eif (!ej2_base_1.isNullOrUndefined(e.args) && e.args.action !== 'enter' &&
                e.args.action !== 'space') {
                var pageX = void 0;
                var pageY = void 0;
                if (e.type !== 'Links' || ej2_base_1.isNullOrUndefined(this.parent.quickToolbarModule) ||
                    ej2_base_1.isNullOrUndefined(this.parent.quickToolbarModule.linkQTBar)) {
                    return;
                }
                this.quickToolObj = this.parent.quickToolbarModule;
                var parentTop = this.parent.element.getBoundingClientRect().top;
                var parentLeft = this.parent.element.getBoundingClientRect().left;
                var range = this.parent.formatter.editorManager.nodeSelection.getRange(this.parent.contentModule.getDocument());
                var target_1;
                [].forEach.call(e.elements, function (element, index) {
                    if (index === 0) {
                        target_1 = ((element.nodeName === '#text') ? (element.parentNode) : element);
                    }
                });
                if (e.isNotify) {
                    var tbElement = this.parent.toolbarModule.getToolbarElement();
                    var linkTop = target_1.getBoundingClientRect().top;
                    var linkLeft = target_1.getBoundingClientRect().left;
                    var linkPos = linkTop - parentTop;
                    var tbHeight = (tbElement) ? (tbElement.offsetHeight + this.parent.toolbarModule.getExpandTBarPopHeight()) : 0;
                    pageX = (this.parent.iframeSettings.enable) ? parentLeft + linkLeft : target_1.getBoundingClientRect().left;
                    pageY = window.pageYOffset + ((this.parent.iframeSettings.enable) ?
                        (parentTop + tbHeight + linkTop) : (parentTop + linkPos));
                }
                else {
                    var args = void 0;
                    args = e.args.touches ? e.args.changedTouches[0] : args = e.args;
                    pageX = (this.parent.iframeSettings.enable) ? window.pageXOffset + parentLeft + args.clientX : args.pageX;
                    pageY = (this.parent.iframeSettings.enable) ? window.pageYOffset + parentTop + args.clientY : args.pageY;
                }
                Eif (this.quickToolObj.linkQTBar) {
                    this.quickToolObj.linkQTBar.showPopup(pageX, pageY, range.endContainer, 'link');
                }
            }
        };
        Link.prototype.hideLinkQuickToolbar = function () {
            if (this.quickToolObj && this.quickToolObj.linkQTBar && document.body.contains(this.quickToolObj.linkQTBar.element)) {
                this.quickToolObj.linkQTBar.hidePopup();
            }
        };
        Link.prototype.editAreaClickHandler = function (e) {
            Iif (this.parent.readonly) {
                this.hideLinkQuickToolbar();
                return;
            }
            var args = e.args;
            var showOnRightClick = this.parent.quickToolbarSettings.showOnRightClick;
            if (args.which === 2 || (showOnRightClick && args.which === 1) || (!showOnRightClick && args.which === 3)) {
                return;
            }
            if (this.parent.editorMode === 'HTML' && this.parent.quickToolbarModule && this.parent.quickToolbarModule.linkQTBar) {
                this.quickToolObj = this.parent.quickToolbarModule;
                var target = args.target;
                target = this.getAnchorNode(target);
                this.contentModule = this.rendererFactory.getRenderer(enum_1.RenderType.Content);
                var isPopupOpen = this.quickToolObj.linkQTBar.element.classList.contains('e-rte-pop');
                if (target.nodeName === 'A' && (target.childNodes.length > 0 && target.childNodes[0].nodeName !== 'IMG') &&
                    e.args.target.nodeName !== 'IMG' &&
                    !ej2_base_1.isNullOrUndefined(ej2_base_2.closest(this.parent.getRange().startContainer.parentElement, 'A')) && !ej2_base_1.isNullOrUndefined(ej2_base_2.closest(this.parent.getRange().endContainer.parentElement, 'A'))) {
                    if (isPopupOpen) {
                        return;
                    }
                    if (e.args.ctrlKey === false) {
                        this.showLinkQuickToolbar({
                            args: args,
                            isNotify: false,
                            type: 'Links',
                            elements: [args.target]
                        });
                    }
                    else {
                        var selection = this.parent.formatter.editorManager.nodeSelection;
                        var range = selection.getRange(this.parent.contentModule.getDocument());
                        var args_1 = {
                            args: {
                                item: {
                                    subCommand: 'OpenLink',
                                    command: 'Links',
                                    name: ''
                                },
                                originalEvent: e.args
                            },
                            selectNode: selection.getNodeCollection(range),
                            selectParent: selection.getParentNodeCollection(range),
                            selection: selection.save(range, this.parent.contentModule.getDocument())
                        };
                        this.parent.notify(events.openLink, args_1);
                    }
                }
                else {
                    this.hideLinkQuickToolbar();
                }
            }
        };
        Link.prototype.onKeyDown = function (event) {
            var originalEvent = event.args;
            switch (originalEvent.action) {
                case 'escape':
                    if (!ej2_base_1.isNullOrUndefined(this.dialogObj)) {
                        this.dialogObj.close();
                    }
                    break;
                case 'insert-link':
                    this.openDialog(true, event);
                    originalEvent.preventDefault();
                    break;
            }
        };
        Link.prototype.openDialog = function (isInternal, event) {
            if (!isInternal) {
                this.parent.contentModule.getEditPanel().focus();
            }
            if (this.parent.editorMode === 'HTML') {
                var range = this.parent.formatter.editorManager.nodeSelection.getRange(this.parent.contentModule.getDocument());
                var save = this.parent.formatter.editorManager.nodeSelection.save(range, this.parent.contentModule.getDocument());
                var selectNodeEle = this.parent.formatter.editorManager.nodeSelection.getNodeCollection(range);
                var selectParentEle = this.parent.formatter.editorManager.nodeSelection.getParentNodeCollection(range);
                var eventArgs = {
                    args: event ? event.args : {
                        item: { command: 'Links', subCommand: 'CreateLink' },
                        originalEvent: undefined,
                        name: !isInternal ? 'showDialog' : null
                    },
                    selectNode: selectNodeEle, selection: save, selectParent: selectParentEle
                };
                this.linkDialog(eventArgs);
            }
            else {
                var textArea = this.parent.contentModule.getEditPanel();
                this.parent.formatter.editorManager.markdownSelection.save(textArea.selectionStart, textArea.selectionEnd);
                this.linkDialog({
                    args: {
                        item: { command: 'Links', subCommand: 'Link' },
                        originalEvent: event && event.args
                    },
                    member: 'link',
                    text: this.parent.formatter.editorManager.markdownSelection.getSelectedText(this.parent.contentModule.getEditPanel()),
                    module: 'Markdown',
                    name: 'insertLink'
                });
            }
        };
        Link.prototype.showDialog = function () {
            this.openDialog(false);
            this.setCssClass({ cssClass: this.parent.getCssClass() });
        };
        Link.prototype.closeDialog = function () {
            Eif (this.dialogObj) {
                this.dialogObj.hide({ returnValue: true });
            }
        };
        Link.prototype.clearDialogObj = function () {
            if (this.dialogObj) {
                this.dialogObj.destroy();
                ej2_base_1.detach(this.dialogObj.element);
                this.dialogObj = null;
            }
        };
        Link.prototype.linkDialog = function (e, inputDetails) {
            var _this = this;
            if (this.dialogObj) {
                this.dialogObj.hide({ returnValue: true });
                return;
            }
            if (this.parent.editorMode === 'HTML' && (e.selectParent.length > 0 &&
                !ej2_base_1.isNullOrUndefined(e.selectParent[0].classList) &&
                e.selectParent[0].classList.contains('e-rte-anchor')) && ej2_base_1.isNullOrUndefined(inputDetails)) {
                this.editLink(e);
                return;
            }
            var linkWebAddress = this.i10n.getConstant('linkWebUrl');
            var linkDisplayText = this.i10n.getConstant('linkText');
            var linkTooltip = this.i10n.getConstant('linkTooltipLabel');
            var urlPlace = this.i10n.getConstant('linkurl');
            var textPlace = this.i10n.getConstant('textPlaceholder');
            var title = this.i10n.getConstant('linkTitle');
            var linkDialogEle = this.parent.createElement('div', {
                className: 'e-rte-link-dialog' + this.parent.getCssClass(true), id: this.rteID + '_rtelink'
            });
            this.parent.rootContainer.appendChild(linkDialogEle);
            var linkContent = this.parent.createElement('div', {
                className: 'e-rte-linkcontent' + this.parent.getCssClass(true), id: this.rteID + '_linkContent'
            });
            var htmlTextbox = (this.parent.editorMode === 'HTML') ? '<label>' + linkTooltip +
                '</label></div><div class="e-rte-field' + this.parent.getCssClass(true) + '">' +
                '<input type="text" data-role ="none" spellcheck="false" placeholder = "' + title + '"aria-label="' + this.i10n.getConstant('linkTitle') + '" class="e-input e-rte-linkTitle' + this.parent.getCssClass(true) + '"></div>' +
                '<div class="e-rte-label' + this.parent.getCssClass(true) + '"></div>' + '<div class="e-rte-field' + this.parent.getCssClass(true) + '">' +
                '<input type="checkbox" class="e-rte-linkTarget' + this.parent.getCssClass(true) + '"  data-role ="none"></div>' : '';
            var content = '<div class="e-rte-label' + this.parent.getCssClass(true) + '"><label>' + linkWebAddress + '</label></div>' + '<div class="e-rte-field' + this.parent.getCssClass(true) + '">' +
                '<input type="text" data-role ="none" spellcheck="false" placeholder="' + urlPlace + '"aria-label="' + this.i10n.getConstant('linkWebUrl') + '" class="e-input e-rte-linkurl' + this.parent.getCssClass(true) + '"/></div>' +
                '<div class="e-rte-label' + this.parent.getCssClass(true) + '">' + '<label>' + linkDisplayText + '</label></div><div class="e-rte-field' + this.parent.getCssClass(true) + '"> ' +
                '<input type="text" data-role ="none" spellcheck="false" class="e-input e-rte-linkText' + this.parent.getCssClass(true) + '"aria-label="' + this.i10n.getConstant('linkText') + '" placeholder="' + textPlace + '">' +
                '</div><div class="e-rte-label' + this.parent.getCssClass(true) + '">' + htmlTextbox;
            var contentElem = util_1.parseHtml(content);
            linkContent.appendChild(contentElem);
            var linkTarget = linkContent.querySelector('.e-rte-linkTarget');
            var linkUrl = linkContent.querySelector('.e-rte-linkurl');
            var linkText = linkContent.querySelector('.e-rte-linkText');
            var linkTitle = linkContent.querySelector('.e-rte-linkTitle');
            var linkOpenLabel = this.i10n.getConstant('linkOpenInNewWindow');
            this.checkBoxObj = new ej2_buttons_1.CheckBox({ label: linkOpenLabel, checked: true, enableRtl: this.parent.enableRtl,
                cssClass: this.parent.getCssClass() });
            this.checkBoxObj.isStringTemplate = true;
            this.checkBoxObj.createElement = this.parent.createElement;
            this.checkBoxObj.appendTo(linkTarget);
            var selectText = (this.parent.editorMode === 'HTML') ?
                e.selection.getRange(this.parent.contentModule.getDocument()).toString() : e.text;
            var linkInsert = this.i10n.getConstant('dialogInsert');
            var linkCancel = this.i10n.getConstant('dialogCancel');
            var selection = e.selection;
            var selectObj = { selfLink: this, selection: e.selection, selectParent: e.selectParent, args: e.args };
            var dialogModel = {
                header: this.i10n.getConstant('linkHeader'),
                content: linkContent,
                cssClass: classes_1.CLS_RTE_ELEMENTS + this.parent.getCssClass(true),
                enableRtl: this.parent.enableRtl,
                locale: this.parent.locale,
                showCloseIcon: true, closeOnEscape: true, width: (ej2_base_2.Browser.isDevice) ? '290px' : '310px',
                isModal: ej2_base_2.Browser.isDevice,
                buttons: [{
                        click: this.insertlink.bind(selectObj),
                        buttonModel: { content: linkInsert, cssClass: 'e-flat e-insertLink' + this.parent.getCssClass(true), isPrimary: true }
                    },
                    { click: this.cancelDialog.bind(selectObj), buttonModel: { cssClass: 'e-flat' + this.parent.getCssClass(true), content: linkCancel } }],
                target: (ej2_base_2.Browser.isDevice) ? document.body : this.parent.element,
                animationSettings: { effect: 'None' },
                close: function (event) {
                    _this.parent.isBlur = false;
                    if (event && event.event.returnValue) {
                        if (_this.parent.editorMode === 'HTML') {
                            selection.restore();
                        }
                        else {
                            _this.parent.formatter.editorManager.markdownSelection.restore(_this.parent.contentModule.getEditPanel());
                        }
                    }
                    _this.dialogObj.destroy();
                    ej2_base_1.detach(_this.dialogObj.element);
                    var args = _this.dialogObj;
                    _this.dialogRenderObj.close(args);
                    _this.dialogObj = null;
                }
            };
            this.dialogObj = this.dialogRenderObj.render(dialogModel);
            this.dialogObj.createElement = this.parent.createElement;
            this.dialogObj.appendTo(linkDialogEle);
            linkDialogEle.style.maxHeight = 'inherit';
            if (ej2_base_1.isNullOrUndefined(this.dialogObj)) {
                return;
            }
            if (!ej2_base_1.isNullOrUndefined(inputDetails)) {
                linkUrl.value = inputDetails.url;
                linkText.value = inputDetails.text;
                linkTitle.value = inputDetails.title;
                (inputDetails.target) ? this.checkBoxObj.checked = true : this.checkBoxObj.checked = false;
                this.dialogObj.header = inputDetails.header;
                this.dialogObj.element.querySelector('.e-insertLink').textContent = inputDetails.btnText;
            }
            this.checkUrl(false);
            if ((this.parent.editorMode === 'HTML' && ej2_base_1.isNullOrUndefined(inputDetails) && ((!ej2_base_1.isNullOrUndefined(selectText)
                && selectText !== '') && (e.selection.range.startOffset === 0) || e.selection.range.startOffset !==
                e.selection.range.endOffset)) || e.module === 'Markdown') {
                linkText.value = selectText;
            }
            this.parent.element.ownerDocument.addEventListener('mousedown', this.mouseDown);
            if (this.quickToolObj) {
                this.hideLinkQuickToolbar();
                Iif (this.quickToolObj.inlineQTBar && document.body.contains(this.quickToolObj.inlineQTBar.element)) {
                    this.quickToolObj.inlineQTBar.hidePopup();
                }
                if (this.quickToolObj.textQTBar && this.parent.element.ownerDocument.body.contains(this.quickToolObj.textQTBar.element)) {
                    this.quickToolObj.textQTBar.hidePopup();
                }
            }
        };
        Link.prototype.insertlink = function (e) {
            var linkEle = this.selfLink.dialogObj.element;
            var linkUrl = linkEle.querySelector('.e-rte-linkurl').value.trim();
            var linkText = linkEle.querySelector('.e-rte-linkText').value;
            var linkTitle;
            if (this.selfLink.parent.editorMode === 'HTML') {
                linkTitle = linkEle.querySelector('.e-rte-linkTitle').value;
            }
            var target = (this.selfLink.checkBoxObj.checked) ? '_blank' : null;
            var linkLabel = (this.selfLink.checkBoxObj.checked) ? this.selfLink.i10n.getConstant('linkAriaLabel') : null;
            if (this.selfLink.parent.editorMode === 'Markdown' && linkUrl === '') {
                linkUrl = 'http://';
            }
            if (linkUrl === '') {
                this.selfLink.checkUrl(true);
                return;
            }
            if (!this.selfLink.isUrl(linkUrl)) {
                if (this.selfLink.parent.editorMode === 'Markdown') {
                    linkText = (linkText !== '') ? linkText : '';
                }
                else {
                    linkText = (linkText === '') ? linkUrl : linkText;
                }
                if (!this.selfLink.parent.enableAutoUrl) {
                    linkUrl = linkUrl.indexOf('http') > -1 ? linkUrl : 'http://' + linkUrl;
                }
                else {
                    linkUrl = linkUrl;
                }
            }
            else {
                this.selfLink.checkUrl(false);
            }
            var proxy = this.selfLink;
            if (proxy.parent.editorMode === 'HTML' && ej2_base_1.isNullOrUndefined(ej2_base_2.closest(this.selection.range.startContainer.parentNode, '[id='
                + "'" + proxy.parent.contentModule.getPanel().id + "'" + ']'))) {
                proxy.parent.contentModule.getEditPanel().focus();
                if (ej2_base_2.Browser.isIE && proxy.parent.iframeSettings.enable) {
                    this.selection.restore();
                }
                var range = proxy.parent.formatter.editorManager.nodeSelection.getRange(proxy.parent.contentModule.getDocument());
                this.selection = proxy.parent.formatter.editorManager.nodeSelection.save(range, proxy.parent.contentModule.getDocument());
                this.selectParent = proxy.parent.formatter.editorManager.nodeSelection.getParentNodeCollection(range);
            }
            var value = {
                url: linkUrl, text: linkText, title: linkTitle, target: target, ariaLabel: linkLabel,
                selection: this.selection, selectParent: this.selectParent
            };
            Eif (document.body.contains(proxy.dialogObj.element)) {
                this.selfLink.dialogObj.hide({ returnValue: false });
            }
            if (util_2.isIDevice() && proxy.parent.iframeSettings.enable) {
                ej2_base_1.select('iframe', proxy.parent.element).contentWindow.focus();
            }
            if (proxy.parent.editorMode === 'HTML') {
                this.selection.restore();
            }
            if (proxy.parent.formatter.getUndoRedoStack().length === 0) {
                proxy.parent.formatter.saveData();
            }
            var argsValue;
            Iif (!ej2_base_1.isNullOrUndefined(this.args) &&
                this.args.code === 'KeyK') {
                var originalEvent = this.args;
                ej2_base_1.extend(this.args, { item: { command: 'Links', subCommand: 'CreateLink' }, originalEvent: originalEvent }, true);
                var argsVal = {
                    item: { command: 'Links', subCommand: 'CreateLink' }, originalEvent: originalEvent
                };
                argsValue = argsVal;
            }
            else {
                argsValue = this.args;
            }
            this.selfLink.parent.formatter.process(this.selfLink.parent, argsValue, (!ej2_base_1.isNullOrUndefined(this.args) &&
                this.args.originalEvent), value);
            this.selfLink.parent.contentModule.getEditPanel().focus();
        };
        Link.prototype.isUrl = function (url) {
            var regExp = RegExp;
            var regexp = new regExp('(ftp|http|https)://(\\w+:{0,1}\\w*@)?(\\S+)(:[0-9]+)?(/|/([\\w#!:.?+=&%@\\-\\/]))?', 'gi');
            return regexp.test(url);
        };
        Link.prototype.checkUrl = function (e) {
            var linkEle = this.dialogObj.element;
            var linkUrl = linkEle.querySelector('.e-rte-linkurl');
            if (e) {
                ej2_base_2.addClass([linkUrl], 'e-error');
                linkUrl.setSelectionRange(0, linkUrl.value.length);
                linkUrl.focus();
            }
            else {
                ej2_base_2.removeClass([linkUrl], 'e-error');
            }
        };
        Link.prototype.removeLink = function (e) {
            if (this.parent.formatter.getUndoRedoStack().length === 0) {
                this.parent.formatter.saveData();
            }
            var selectParentEle = this.getAnchorNode(e.selectParent[0]);
            this.parent.formatter.process(this.parent, e.args, e.args, {
                selectNode: e.selectNode, selectParent: e.selectParent, selection: e.selection,
                text: selectParentEle.innerText,
                subCommand: e.args.item.subCommand
            });
            Iif (util_2.isIDevice() && this.parent.iframeSettings.enable) {
                ej2_base_1.select('iframe', this.parent.element).contentWindow.focus();
            }
            else {
                this.parent.contentModule.getEditPanel().focus();
            }
            this.hideLinkQuickToolbar();
        };
        Link.prototype.openLink = function (e) {
            var selectParentEle = this.getAnchorNode(e.selectParent[0]);
            if (selectParentEle.classList.contains('e-rte-anchor') || selectParentEle.tagName === 'A') {
                this.parent.formatter.process(this.parent, e.args, e.args, {
                    url: selectParentEle.href, text: selectParentEle.innerText,
                    target: selectParentEle.target === '' ? '_self' : '_blank', selectNode: e.selectNode,
                    subCommand: e.args.item.subCommand
                });
            }
        };
        Link.prototype.getAnchorNode = function (element) {
            var selectParent = ej2_base_2.closest(element, 'a');
            return (selectParent ? selectParent : element);
        };
        Link.prototype.editLink = function (e) {
            var selectedNode = this.getAnchorNode(e.selectNode[0]);
            var selectParentEle = this.getAnchorNode(e.selectParent[0]);
            selectParentEle = selectedNode.nodeName === 'A' ? selectedNode : selectParentEle;
            if (selectParentEle.classList.contains('e-rte-anchor') || selectParentEle.tagName === 'A') {
                var linkUpdate = this.i10n.getConstant('dialogUpdate');
                var inputDetails = {
                    url: selectParentEle.getAttribute('href'), text: selectParentEle.innerText,
                    title: selectParentEle.title, target: selectParentEle.target,
                    header: this.i10n.getConstant('editLink'), btnText: linkUpdate
                };
                this.linkDialog(e, inputDetails);
            }
        };
        Link.prototype.cancelDialog = function (e) {
            this.selfLink.parent.isBlur = false;
            this.selfLink.dialogObj.hide({ returnValue: true });
            Iif (util_2.isIDevice()) {
                this.selection.restore();
            }
            else {
                var x = window.scrollX;
                var y = window.scrollY;
                this.selfLink.parent.contentModule.getEditPanel().focus();
                window.scrollTo(x, y);
            }
        };
        Link.prototype.onDocumentClick = function (e) {
            var target = e.target;
            if (!ej2_base_1.isNullOrUndefined(this.dialogObj) && ((!ej2_base_2.closest(target, '[id=' + "'" + this.dialogObj.element.id + "'" + ']') && this.parent.toolbarSettings.enable &&
                this.parent.getToolbarElement() && !this.parent.getToolbarElement().contains(e.target)) ||
                (((this.parent.getToolbarElement() && this.parent.getToolbarElement().contains(e.target)) ||
                    this.parent.inlineMode.enable && !ej2_base_2.closest(target, '#' + this.dialogObj.element.id)) &&
                    !ej2_base_2.closest(target, '#' + this.parent.getID() + '_toolbar_CreateLink') &&
                    !target.querySelector('#' + this.parent.getID() + '_toolbar_CreateLink')))) {
                this.parent.notify(events.documentClickClosedBy, { closedBy: 'outside click' });
                this.dialogObj.hide({ returnValue: true });
                this.parent.element.ownerDocument.removeEventListener('mousedown', this.mouseDown);
                this.mouseDown = null;
                this.parent.isBlur = true;
                util_1.dispatchEvent(this.parent.element, 'focusout');
            }
        };
        Link.prototype.destroy = function () {
            if (this.isDestroyed) {
                return;
            }
            this.parent.element.ownerDocument.removeEventListener('mousedown', this.mouseDown);
            this.mouseDown = null;
            this.removeEventListener();
            this.isDestroyed = true;
        };
        Link.prototype.getModuleName = function () {
            return 'link';
        };
        return Link;
    }());
    exports.Link = Link;
});