all files / pdfviewer/base/ context-menu.js

15.96% Statements 60/376
1.9% Branches 6/315
15.15% Functions 5/33
16.35% Lines 60/367
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 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    
define(["require", "exports", "@syncfusion/ej2-base", "@syncfusion/ej2-navigations", "./types"], function (require, exports, ej2_base_1, ej2_navigations_1, types_1) {
    "use strict";
    Object.defineProperty(exports, "__esModule", { value: true });
    var ContextMenu = (function () {
        function ContextMenu(pdfViewer, pdfViewerBase) {
            this.copyContextMenu = [];
            this.contextMenuList = [];
            this.customMenuItems = [];
            this.filteredCustomItemsIds = [];
            this.mainCustomItemsIds = [];
            this.defaultContextMenuItems = [];
            this.pdfViewer = pdfViewer;
            this.pdfViewerBase = pdfViewerBase;
            this.defaultCutId = this.pdfViewer.element.id + '_contextmenu_cut';
            this.defaultCopyId = this.pdfViewer.element.id + '_contextmenu_copy';
            this.defaultPasteId = this.pdfViewer.element.id + '_contextmenu_paste';
            this.defaultDeleteId = this.pdfViewer.element.id + '_contextmenu_delete';
            this.defaultCommentId = this.pdfViewer.element.id + '_contextmenu_comment';
            this.defaultUnderlineId = this.pdfViewer.element.id + '_contextmenu_underline';
            this.defaultHighlightId = this.pdfViewer.element.id + '_contextmenu_highlight';
            this.defaultStrikethroughId = this.pdfViewer.element.id + '_contextmenu_strikethrough';
            this.defaultSquigglyId = this.pdfViewer.element.id + '_contextmenu_squiggly';
            this.defaultScaleratioId = this.pdfViewer.element.id + '_contextmenu_scaleratio';
            this.defaultPropertiesId = this.pdfViewer.element.id + '_contextmenu_properties';
            this.redactTextId = this.pdfViewer.element.id + '_contextmenu_redactText';
            this.applyRedactionsId = this.pdfViewer.element.id + '_contextmenu_redact';
            this.copyContextMenu = [
                { text: this.pdfViewer.localeObj.getConstant('Cut'), iconCss: 'e-pv-cut-icon', id: this.defaultCutId },
                { text: this.pdfViewer.localeObj.getConstant('Copy'), iconCss: 'e-pv-copy-icon', id: this.defaultCopyId },
                { text: this.pdfViewer.localeObj.getConstant('Highlight context'), iconCss: 'e-pv-highlight-icon', id: this.defaultHighlightId },
                { text: this.pdfViewer.localeObj.getConstant('Underline context'), iconCss: 'e-pv-underline-icon', id: this.defaultUnderlineId },
                { text: this.pdfViewer.localeObj.getConstant('Strikethrough context'), iconCss: 'e-pv-strikethrough-icon', id: this.defaultStrikethroughId },
                { text: this.pdfViewer.localeObj.getConstant('Squiggly context'), iconCss: 'e-pv-squiggly-icon', id: this.defaultSquigglyId },
                { text: this.pdfViewer.localeObj.getConstant('Redact Text'), iconCss: 'e-pv-text-redact-icon', id: this.redactTextId },
                { text: this.pdfViewer.localeObj.getConstant('Apply Redactions'), iconCss: 'e-pv-redaction-icon', id: this.applyRedactionsId },
                { text: this.pdfViewer.localeObj.getConstant('Paste'), iconCss: 'e-pv-paste-icon', id: this.defaultPasteId },
                { text: this.pdfViewer.localeObj.getConstant('Delete Context'), iconCss: 'e-pv-delete-icon', id: this.defaultDeleteId },
                { text: this.pdfViewer.localeObj.getConstant('Scale Ratio'), iconCss: 'e-pv-scale-ratio-icon', id: this.defaultScaleratioId },
                { separator: true, id: this.pdfViewer.element.id + '_context_menu_comment_separator' },
                { text: this.pdfViewer.localeObj.getConstant('Comment'), iconCss: 'e-pv-comment-icon', id: this.defaultCommentId },
                { separator: true, id: this.pdfViewer.element.id + '_context_menu_separator' },
                { text: this.pdfViewer.localeObj.getConstant('Properties'), iconCss: 'e-pv-property-icon', id: this.defaultPropertiesId }
            ];
            this.defaultLength = this.copyContextMenu.length;
        }
        ContextMenu.prototype.createContextMenu = function () {
            Iif (this.contextMenuElement) {
                this.contextMenuElement = null;
            }
            this.contextMenuElement = ej2_base_1.createElement('ul', { id: this.pdfViewer.element.id + '_context_menu', className: 'e-pv-context-menu' });
            this.pdfViewer.element.appendChild(this.contextMenuElement);
            Iif (this.contextMenuObj) {
                this.contextMenuObj.destroy();
                this.contextMenuObj = null;
            }
            this.contextMenuObj = new ej2_navigations_1.ContextMenu({
                target: '#' + this.pdfViewerBase.viewerContainer.id, items: this.copyContextMenu,
                beforeOpen: this.contextMenuOnBeforeOpen.bind(this), select: this.onMenuItemSelect.bind(this),
                created: this.contextMenuOnCreated.bind(this)
            });
            Iif (this.pdfViewer.enableRtl) {
                this.contextMenuObj.enableRtl = true;
            }
            this.contextMenuObj.appendTo(this.contextMenuElement);
            Iif (ej2_base_1.Browser.isDevice && !this.pdfViewer.enableDesktopMode) {
                this.contextMenuObj.animationSettings.effect = 'ZoomIn';
            }
            else {
                this.contextMenuObj.animationSettings.effect = 'SlideDown';
            }
        };
        ContextMenu.prototype.updateContextMenuItems = function (items, isEnable) {
            this.contextMenuObj.enableItems(items, isEnable, true);
        };
        ContextMenu.prototype.contextMenuOnCreated = function (args) {
            var items = [this.defaultHighlightId, this.defaultUnderlineId,
                this.defaultStrikethroughId, this.defaultSquigglyId, this.redactTextId];
            Iif (this.pdfViewer.annotationModule) {
                if (!this.pdfViewer.annotationModule.textMarkupAnnotationModule) {
                    this.contextMenuObj.enableItems(items, false, true);
                }
            }
            else {
                this.contextMenuObj.enableItems(items, false, true);
            }
        };
        ContextMenu.prototype.setTarget = function (args) {
            var target = null;
            if (args.event && args.event.target) {
                target = args.event.target;
                this.currentTarget = target;
            }
            return target;
        };
        ContextMenu.prototype.contextMenuOnBeforeOpen = function (args) {
            var _this = this;
            var _a;
            if (this.pdfViewerBase.preventContextmenu) {
                this.pdfViewerBase.preventContextmenu = false;
                args.cancel = true;
            }
            if (this.copyContextMenu.length === this.defaultLength) {
                (_a = this.customMenuItems).push.apply(_a, this.pdfViewer.customContextMenuItems);
                this.addCustomContextMenuItems();
            }
            else if (this.copyContextMenu.length !== this.defaultLength && this.copyShowCustomContextMenuBottom !==
                this.pdfViewer.showCustomContextMenuBottom) {
                this.customMenuItems.forEach(function (menuItem) {
                    var index = _this.copyContextMenu.findIndex(function (item) { return item.id === menuItem.id; });
                    if (index !== -1) {
                        _this.copyContextMenu.splice(index, 1);
                    }
                });
                this.addCustomContextMenuItems();
            }
            var target = this.setTarget(args);
            var currentAnnotSettings = this.pdfViewer.selectedItems.annotations.length !== 0 ?
                this.pdfViewer.selectedItems.annotations[0].annotationSettings : null;
            if (this.pdfViewer.annotationModule && this.pdfViewer.annotationModule.freeTextAnnotationModule && this.pdfViewer.annotationModule.freeTextAnnotationModule.isInuptBoxInFocus && target && target.className === 'free-text-input' && target.tagName === 'TEXTAREA') {
                this.pdfViewerBase.isFreeTextContextMenu = true;
            }
            this.defaultContextMenuItems = [this.pdfViewer.localeObj.getConstant('Cut'), this.pdfViewer.localeObj.getConstant('Copy'), this.pdfViewer.localeObj.getConstant('Highlight context'),
                this.pdfViewer.localeObj.getConstant('Underline context'), this.pdfViewer.localeObj.getConstant('Strikethrough context'), this.pdfViewer.localeObj.getConstant('Squiggly context'),
                this.pdfViewer.localeObj.getConstant('Redact Text'), this.pdfViewer.localeObj.getConstant('Paste'),
                this.pdfViewer.localeObj.getConstant('Delete Context'), this.pdfViewer.localeObj.getConstant('Scale Ratio'), this.pdfViewer.localeObj.getConstant('Comment'), this.pdfViewer.localeObj.getConstant('Properties')
            ];
            var customItems = this.customMenuItems.length > 0 ?
                this.contextMenuObj.items.slice(this.pdfViewer.showCustomContextMenuBottom ? -this.customMenuItems.length : 0, this.pdfViewer.showCustomContextMenuBottom ?
                    this.contextMenuObj.items.length : this.customMenuItems.length).map(function (item) { return item.text; }) : [];
            this.contextMenuObj.showItems(this.pdfViewer.showCustomContextMenuBottom ?
                this.defaultContextMenuItems.concat(customItems) : customItems.concat(this.defaultContextMenuItems));
            this.pdfViewerBase.getElement('_context_menu_separator').classList.remove('e-menu-hide');
            this.pdfViewerBase.getElement('_context_menu_comment_separator').classList.remove('e-menu-hide');
            this.contextMenuObj.enableItems([this.defaultCutId, this.defaultCopyId, this.defaultPasteId, this.defaultDeleteId], true, true);
            if (!ej2_base_1.isNullOrUndefined(customItems) && this.customMenuItems.length !== 0) {
                if (ej2_base_1.isNullOrUndefined(args.parentItem)) {
                    var commonIds_1 = [];
                    if (args.items.length < this.defaultLength) {
                        commonIds_1 = args.items.map(function (item) { return item.id; });
                    }
                    else {
                        commonIds_1 = this.customMenuItems.map(function (item) { return item.id; });
                    }
                    this.mainCustomItemsIds = commonIds_1.filter(function (id) { return !ej2_base_1.isNullOrUndefined(id); });
                    this.filteredCustomItemsIds = this.mainCustomItemsIds;
                    this.pdfViewer.firecustomContextMenuBeforeOpen(this.mainCustomItemsIds.filter(function (id) { return commonIds_1.indexOf(id) > -1; }));
                }
                else {
                    var subMenuIds = args.items.map(function (item) { return item.id; }).filter(function (id) { return !ej2_base_1.isNullOrUndefined(id); });
                    this.pdfViewer.firecustomContextMenuBeforeOpen(subMenuIds);
                    this.filteredCustomItemsIds = (this.mainCustomItemsIds || []).concat(subMenuIds);
                }
            }
            if (this.pdfViewer.annotationModule) {
                this.pdfViewer.annotationModule.checkContextMenuDeleteItem(this.contextMenuObj);
            }
            if (this.pdfViewer.textSelectionModule || this.pdfViewerBase.isShapeBasedAnnotationsEnabled()) {
                if (args.event || this.pdfViewerBase.isTouchDesignerMode) {
                    var isClickWithinSelectionBounds = this.pdfViewerBase.isClickWithinSelectionBounds(args.event);
                    if (this.pdfViewerBase.isFreeTextContextMenu) {
                        this.contextMenuObj.hideItems([this.defaultHighlightId, this.defaultUnderlineId, this.defaultStrikethroughId,
                            this.defaultSquigglyId, this.defaultPropertiesId, this.defaultCommentId,
                            this.defaultScaleratioId, this.defaultDeleteId, this.redactTextId, this.applyRedactionsId], true);
                        this.pdfViewerBase.getElement('_context_menu_separator').classList.add('e-menu-hide');
                        this.pdfViewerBase.getElement('_context_menu_comment_separator').classList.add('e-menu-hide');
                        if (this.pdfViewer.annotation.freeTextAnnotationModule &&
                            this.pdfViewer.annotation.freeTextAnnotationModule.isTextSelected) {
                            this.contextMenuObj.enableItems([this.defaultCopyId], true, true);
                            this.contextMenuObj.enableItems([this.defaultCutId], true, true);
                        }
                        else {
                            this.contextMenuObj.enableItems([this.defaultCopyId], false, true);
                            this.contextMenuObj.enableItems([this.defaultCutId], false, true);
                            window.getSelection().removeAllRanges();
                        }
                        if (this.pdfViewer.annotation.freeTextAnnotationModule && this.pdfViewer.annotation.freeTextAnnotationModule.selectedText !== '') {
                            this.contextMenuObj.enableItems([this.defaultPasteId], true, true);
                        }
                        else {
                            this.contextMenuObj.enableItems([this.defaultPasteId], false, true);
                        }
                    }
                    else if ((isClickWithinSelectionBounds && this.pdfViewer.textSelectionModule) || (this.pdfViewer.textSelectionModule && this.pdfViewer.textSelectionModule.selectionRangeArray.length > 0 && (this.pdfViewer.contextMenuSettings.contextMenuAction === 'MouseUp' || ((this.pdfViewer.contextMenuSettings.contextMenuAction === 'None' || this.pdfViewer.contextMenuSettings.contextMenuAction === 'RightClick') && this.pdfViewer.contextMenuOption === 'MouseUp')))) {
                        if ((!args.event.target.classList.contains('e-pv-maintaincontent') && args.event.target.classList.contains('e-pv-text') || args.event.target.classList.contains('e-pv-text-layer'))) {
                            if (this.pdfViewerBase.checkIsNormalText()) {
                                args.cancel = true;
                            }
                        }
                        else if ((ej2_base_1.Browser.isIE || ej2_base_1.Browser.info.name === 'edge') && args.event.target.classList.contains('e-pv-page-container')) {
                            args.cancel = true;
                        }
                        this.contextMenuObj.hideItems([this.defaultCutId, this.defaultPasteId, this.defaultDeleteId,
                            this.defaultScaleratioId, this.defaultCommentId, this.defaultPropertiesId, this.applyRedactionsId], true);
                        if (!this.pdfViewerBase.clientSideRendering) {
                            this.contextMenuObj.hideItems([this.redactTextId], true);
                        }
                        this.pdfViewerBase.getElement('_context_menu_separator').classList.add('e-menu-hide');
                        this.pdfViewerBase.getElement('_context_menu_comment_separator').classList.add('e-menu-hide');
                    }
                    else if (this.pdfViewer.selectedItems.annotations.length !== 0 && (this.pdfViewer.selectedItems.annotations[0].shapeAnnotationType === 'HandWrittenSignature' || this.pdfViewer.selectedItems.annotations[0].shapeAnnotationType === 'SignatureText' || this.pdfViewer.selectedItems.annotations[0].shapeAnnotationType === 'SignatureImage' || this.pdfViewer.selectedItems.annotations[0].shapeAnnotationType === 'Path')) {
                        this.onOpeningForShape(false, true);
                    }
                    else if (this.pdfViewer.selectedItems.annotations.length !== 0 && this.pdfViewer.selectedItems.annotations[0].shapeAnnotationType !== 'Path' && !currentAnnotSettings.isLock) {
                        this.onOpeningForShape(true);
                    }
                    else if (this.pdfViewer.selectedItems.annotations.length !== 0 && this.pdfViewer.selectedItems.annotations[0].shapeAnnotationType !== 'Path' && currentAnnotSettings.isLock) {
                        this.hideDefaultContextMenu();
                    }
                    else if (this.pdfViewer.selectedItems.formFields.length !== 0 &&
                        this.pdfViewer.selectedItems.formFields[0].formFieldAnnotationType && this.pdfViewer.designerMode) {
                        this.onOpeningForShape(true);
                        if (!ej2_base_1.isNullOrUndefined(this.pdfViewer.toolbar) &&
                            !ej2_base_1.isNullOrUndefined(this.pdfViewer.toolbar.formDesignerToolbarModule)) {
                            this.pdfViewer.toolbar.formDesignerToolbarModule.showHideDeleteIcon(true);
                        }
                    }
                    else if (this.customMenuItems.length !== 0 && this.pdfViewer.annotation.isShapeCopied &&
                        this.pdfViewer.selectedItems.annotations.length === 0 && this.pdfViewer.annotationModule &&
                        this.pdfViewer.annotationModule.textMarkupAnnotationModule &&
                        !this.pdfViewer.annotationModule.textMarkupAnnotationModule.currentTextMarkupAnnotation) {
                        this.onOpeningForShape(false);
                    }
                    else {
                        var target_1 = this.pdfViewerBase.designerModetarget;
                        var annotationModule = this.pdfViewer.annotationModule;
                        if (args.event && args.event.target) {
                            target_1 = args.event.target;
                        }
                        if (this.pdfViewer.annotation && this.pdfViewer.annotation.isShapeCopied && ((target_1).classList.contains('e-pv-text-layer') ||
                            (target_1).classList.contains('e-pv-text') || (target_1).classList.contains('e-pv-viewer-container')) && !this.pdfViewer.annotationModule.textMarkupAnnotationModule.currentTextMarkupAnnotation) {
                            this.onOpeningForShape(false);
                        }
                        else if (this.pdfViewer.formDesigner && this.pdfViewer.formDesigner.isShapeCopied && ((target_1).classList.contains('e-pv-text-layer') ||
                            (target_1).classList.contains('e-pv-text'))) {
                            this.onOpeningForShape(false);
                        }
                        else if (this.pdfViewerBase.isCalibrateAnnotationModule() &&
                            this.pdfViewer.annotationModule.measureAnnotationModule.currentAnnotationMode && !currentAnnotSettings) {
                            this.contextMenuObj.hideItems([this.defaultHighlightId, this.defaultUnderlineId,
                                this.defaultStrikethroughId, this.defaultSquigglyId, this.defaultPropertiesId,
                                this.redactTextId, this.applyRedactionsId], true);
                            this.pdfViewerBase.getElement('_context_menu_separator').classList.add('e-menu-hide');
                            this.pdfViewerBase.getElement('_context_menu_comment_separator').classList.remove('e-menu-hide');
                            this.contextMenuObj.enableItems([this.defaultCutId, this.defaultCopyId, this.defaultPasteId,
                                this.defaultDeleteId, this.defaultCommentId], false, true);
                        }
                        else if (annotationModule && annotationModule.textMarkupAnnotationModule &&
                            annotationModule.textMarkupAnnotationModule.currentTextMarkupAnnotation &&
                            annotationModule.textMarkupAnnotationModule.currentTextMarkupAnnotation.shapeAnnotationType === 'Redaction' &&
                            !annotationModule.textMarkupAnnotationModule.currentTextMarkupAnnotation.annotationSettings.isLock) {
                            this.contextMenuObj.hideItems([this.defaultHighlightId, this.defaultUnderlineId, this.defaultStrikethroughId,
                                this.defaultSquigglyId, this.defaultCutId,
                                this.defaultCopyId, this.defaultPasteId, this.defaultScaleratioId, this.redactTextId], true);
                            this.pdfViewerBase.getElement('_context_menu_separator').classList.add('e-menu-hide');
                            this.pdfViewerBase.getElement('_context_menu_comment_separator').classList.remove('e-menu-hide');
                            this.contextMenuObj.showItems([this.defaultDeleteId, this.defaultCommentId, this.defaultPropertiesId,
                                this.applyRedactionsId], true);
                        }
                        else if (annotationModule && annotationModule.textMarkupAnnotationModule &&
                            annotationModule.textMarkupAnnotationModule.currentTextMarkupAnnotation &&
                            !annotationModule.textMarkupAnnotationModule.currentTextMarkupAnnotation.annotationSettings.isLock) {
                            this.contextMenuObj.hideItems([this.defaultHighlightId, this.defaultUnderlineId, this.defaultStrikethroughId,
                                this.defaultSquigglyId, this.defaultPropertiesId, this.defaultCutId,
                                this.defaultCopyId, this.defaultPasteId, this.defaultScaleratioId, this.redactTextId,
                                this.applyRedactionsId], true);
                            this.pdfViewerBase.getElement('_context_menu_separator').classList.add('e-menu-hide');
                            this.pdfViewerBase.getElement('_context_menu_comment_separator').classList.remove('e-menu-hide');
                            this.contextMenuObj.showItems([this.defaultDeleteId, this.defaultCommentId], true);
                        }
                        else if (args.items && args.items.length > 0 && this.pdfViewer.textSelectionModule &&
                            this.pdfViewer.textSelectionModule.isTextSelection && isClickWithinSelectionBounds) {
                            this.contextMenuObj.hideItems([this.defaultCutId, this.defaultPasteId, this.defaultDeleteId,
                                this.defaultScaleratioId, this.defaultCommentId, this.defaultPropertiesId, this.applyRedactionsId], true);
                            this.pdfViewerBase.getElement('_context_menu_separator').classList.add('e-menu-hide');
                            this.pdfViewerBase.getElement('_context_menu_comment_separator').classList.add('e-menu-hide');
                        }
                        else {
                            args.cancel = true;
                        }
                    }
                }
                else if (this.pdfViewer.textSelectionModule && (this.pdfViewer.contextMenuOption === 'MouseUp')) {
                    this.contextMenuObj.hideItems([this.defaultCutId, this.defaultPasteId, this.defaultDeleteId,
                        this.defaultScaleratioId, this.defaultCommentId, this.defaultPropertiesId, this.applyRedactionsId], true);
                    this.pdfViewerBase.getElement('_context_menu_separator').classList.add('e-menu-hide');
                    this.pdfViewerBase.getElement('_context_menu_comment_separator').classList.add('e-menu-hide');
                }
                else {
                    this.hideContextItems();
                }
                this.enableCommentPanelItem();
            }
            else {
                args.cancel = true;
            }
            if (this.pdfViewer.contextMenuSettings.contextMenuAction === 'None' || (this.pdfViewer.contextMenuSettings.contextMenuAction === 'RightClick' && this.pdfViewer.contextMenuOption === 'None') ||
                (this.pdfViewer.contextMenuSettings.contextMenuItems && this.pdfViewer.contextMenuSettings.contextMenuItems.length === 0)) {
                args.cancel = true;
            }
            else {
                this.contextMenuItems(args);
            }
            if (this.pdfViewer.annotationModule && this.pdfViewer.annotationModule.restrictContextMenu()) {
                args.cancel = true;
            }
            if (this.pdfViewer.disableDefaultContextMenu === true) {
                this.hideDefaultContextMenu();
            }
            this.pdfViewerBase.isTouchDesignerMode = false;
        };
        ContextMenu.prototype.contextMenuItems = function (args) {
            if (this.pdfViewer.contextMenuSettings.contextMenuItems &&
                this.pdfViewer.contextMenuSettings.contextMenuItems.length) {
                var hideMenuItems = [];
                var contextMenuList = this.contextMenuCollection();
                var ul = this.contextMenuObj.getRootElement();
                for (var j = 0; j < this.pdfViewer.contextMenuSettings.contextMenuItems.length; j++) {
                    for (var i = 0; i < this.contextMenuList.length; i++) {
                        var menuItem = this.contextMenuList[parseInt(i.toString(), 10)].text;
                        switch (menuItem) {
                            case 'Highlight':
                                menuItem = 'Highlight context';
                                break;
                            case 'Underline':
                                menuItem = 'Underline context';
                                break;
                            case 'Strikethrough':
                                menuItem = 'Strikethrough context';
                                break;
                            case 'Squiggly':
                                menuItem = 'Squiggly context';
                                break;
                            case 'Delete':
                                menuItem = 'Delete Context';
                                break;
                            case 'Scale Ratio':
                                menuItem = 'Scale Ratio';
                                break;
                            case 'Comment':
                                this.pdfViewerBase.getElement('_context_menu_comment_separator').classList.add('e-menu-hide');
                                break;
                            case 'Properties':
                                this.pdfViewerBase.getElement('_context_menu_separator').classList.add('e-menu-hide');
                                break;
                        }
                        var menuName = this.contextMenuList[parseInt(i.toString(), 10)].text;
                        if (j === 0 && menuName !== types_1.ContextMenuItem[this.pdfViewer.contextMenuSettings.
                            contextMenuItems[parseInt(j.toString(), 10)]]) {
                            hideMenuItems.push(menuName);
                        }
                        if (j > 0 && menuName === types_1.ContextMenuItem[this.pdfViewer.contextMenuSettings.
                            contextMenuItems[parseInt(j.toString(), 10)]]) {
                            for (var k = 0; k < hideMenuItems.length; k++) {
                                if (hideMenuItems[parseInt(k.toString(), 10)] === menuName) {
                                    if (this.pdfViewer.disableContextMenuItems && this.pdfViewer.disableContextMenuItems.length > 0) {
                                        var isDisabled = false;
                                        for (var l = 0; l < this.pdfViewer.disableContextMenuItems.length; l++) {
                                            if (hideMenuItems[parseInt(k.toString(), 10)] ===
                                                types_1.ContextMenuItem[this.pdfViewer.disableContextMenuItems[parseInt(l.toString(), 10)]]) {
                                                isDisabled = true;
                                            }
                                        }
                                        if (!isDisabled) {
                                            hideMenuItems.splice(k, 1);
                                        }
                                    }
                                    else {
                                        hideMenuItems.splice(k, 1);
                                    }
                                }
                            }
                        }
                    }
                }
                if (this.pdfViewer.disableContextMenuItems && this.pdfViewer.disableContextMenuItems.length > 0) {
                    for (var m = 0; m < this.pdfViewer.disableContextMenuItems.length; m++) {
                        var name_1 = types_1.ContextMenuItem[this.pdfViewer.disableContextMenuItems[parseInt(m.toString(), 10)]];
                        if (!ej2_base_1.isNullOrUndefined(name_1) && hideMenuItems.indexOf(name_1) === -1) {
                            hideMenuItems.push(name_1);
                        }
                    }
                }
                if (hideMenuItems.indexOf('Comment') !== -1) {
                    this.pdfViewerBase.getElement('_context_menu_comment_separator').classList.add('e-menu-hide');
                }
                if (hideMenuItems.indexOf('Properties') !== -1) {
                    this.pdfViewerBase.getElement('_context_menu_separator').classList.add('e-menu-hide');
                }
                var hideLocaleItem = this.processLocaleContent(hideMenuItems);
                this.contextMenuObj.hideItems(hideLocaleItem);
                if (this.getEnabledItemCount(ul) === 0) {
                    args.cancel = true;
                }
            }
        };
        ContextMenu.prototype.processLocaleContent = function (hideMenuItems) {
            var contextMenuLocaleContent = [];
            if (hideMenuItems.length > 0) {
                for (var i = 0; i < hideMenuItems.length; i++) {
                    var menuItem = hideMenuItems[parseInt(i.toString(), 10)];
                    switch (menuItem) {
                        case 'Highlight':
                            menuItem = 'Highlight context';
                            break;
                        case 'Underline':
                            menuItem = 'Underline context';
                            break;
                        case 'Strikethrough':
                            menuItem = 'Strikethrough context';
                            break;
                        case 'Squiggly':
                            menuItem = 'Squiggly context';
                            break;
                        case 'TextRedact':
                            menuItem = 'Redact Text';
                            break;
                        case 'Delete':
                            menuItem = 'Delete Context';
                            break;
                        case 'ScaleRatio':
                            menuItem = 'Scale Ratio';
                            break;
                    }
                    contextMenuLocaleContent.push(this.pdfViewer.localeObj.getConstant(menuItem));
                }
            }
            return contextMenuLocaleContent;
        };
        ContextMenu.prototype.contextMenuCollection = function () {
            return this.contextMenuList = [{ text: 'Cut' }, { text: 'Copy' }, { text: 'Highlight' }, { text: 'Underline' }, { text: 'Strikethrough' },
                { text: 'Squiggly' }, { text: 'TextRedact' }, { text: 'Paste' }, { text: 'Delete' }, { text: 'ScaleRatio' }, { text: 'Comment' }, { text: 'Properties' }];
        };
        ContextMenu.prototype.getEnabledItemCount = function (ul) {
            var enabledItemCount = this.copyContextMenu.length;
            var liCollection = ul.children;
            for (var i = 0; i < liCollection.length; i++) {
                var li = liCollection[parseInt(i.toString(), 10)];
                if (li.classList.contains('e-menu-hide') || li.classList.contains('e-disabled')) {
                    enabledItemCount = enabledItemCount - 1;
                }
            }
            return enabledItemCount;
        };
        ContextMenu.prototype.hideContextItems = function () {
            if (this.pdfViewer.selectedItems.annotations.length === 0) {
                this.contextMenuObj.hideItems([this.defaultCutId, this.defaultPasteId, this.defaultDeleteId,
                    this.defaultScaleratioId, this.defaultPropertiesId], true);
                this.pdfViewerBase.getElement('_context_menu_separator').classList.add('e-menu-hide');
            }
        };
        ContextMenu.prototype.enableCommentPanelItem = function () {
            if (this.pdfViewer.enableCommentPanel) {
                this.contextMenuObj.enableItems([this.defaultCommentId], true, true);
            }
            else {
                this.contextMenuObj.enableItems([this.defaultCommentId], false, true);
            }
            if (this.pdfViewer.selectedItems.formFields.length !== 0) {
                this.contextMenuObj.enableItems([this.defaultCommentId], false, true);
            }
        };
        ContextMenu.prototype.onOpeningForShape = function (isProp, isSignature) {
            if (this.pdfViewer.annotation && this.pdfViewer.annotation.isShapeCopied) {
                this.contextMenuObj.enableItems([this.defaultPasteId], true, true);
            }
            else if (this.pdfViewer.formDesigner && this.pdfViewer.formDesigner.isShapeCopied) {
                this.contextMenuObj.enableItems([this.defaultPasteId], true, true);
            }
            else {
                this.contextMenuObj.enableItems([this.defaultPasteId], false, true);
            }
            this.contextMenuObj.hideItems([this.defaultHighlightId, this.defaultUnderlineId, this.defaultStrikethroughId,
                this.defaultSquigglyId, this.defaultScaleratioId, this.redactTextId, this.applyRedactionsId], true);
            if (isProp) {
                if (this.pdfViewer.selectedItems.annotations.length !== 0 && (this.pdfViewer.selectedItems.annotations[0].shapeAnnotationType === 'Distance' || this.pdfViewer.selectedItems.annotations[0].measureType === 'Perimeter' ||
                    this.pdfViewer.selectedItems.annotations[0].subject === 'Perimeter calculation')) {
                    this.contextMenuObj.showItems([this.defaultPropertiesId, this.defaultScaleratioId], true);
                }
                else if (this.pdfViewer.selectedItems.annotations.length !== 0 && ((this.pdfViewer.selectedItems.annotations[0].shapeAnnotationType === 'Polygon' && this.pdfViewer.selectedItems.annotations[0].measureType !== '') ||
                    this.pdfViewer.selectedItems.annotations[0].shapeAnnotationType === 'Radius')) {
                    this.contextMenuObj.showItems([this.defaultScaleratioId], true);
                    this.contextMenuObj.hideItems([this.defaultPropertiesId], true);
                }
                else if (this.pdfViewer.selectedItems.annotations.length !== 0 &&
                    (this.pdfViewer.selectedItems.annotations[0].shapeAnnotationType === 'Redaction' ||
                        this.pdfViewer.selectedItems.annotations[0].shapeAnnotationType === 'Line' ||
                        this.pdfViewer.selectedItems.annotations[0].shapeAnnotationType === 'LineWidthArrowHead')) {
                    this.contextMenuObj.showItems([this.defaultPropertiesId], true);
                    if (this.pdfViewer.selectedItems.annotations[0].shapeAnnotationType === 'Redaction') {
                        this.contextMenuObj.showItems([this.applyRedactionsId], true);
                    }
                }
                else if (this.pdfViewer.selectedItems.formFields.length !== 0 &&
                    this.pdfViewer.selectedItems.formFields[0].formFieldAnnotationType) {
                    this.contextMenuObj.hideItems([this.defaultCommentId], true);
                    this.pdfViewerBase.getElement('_context_menu_separator').classList.add('e-menu-hide');
                    this.contextMenuObj.showItems([this.defaultPropertiesId], true);
                }
                else if (ej2_base_1.isNullOrUndefined(isSignature) && this.pdfViewer.selectedItems.annotations[0].shapeAnnotationType === 'Image' && !this.pdfViewer.selectedItems.annotations[0].id.startsWith('stamp')) {
                    this.contextMenuObj.hideItems([this.defaultPropertiesId, this.defaultCommentId, this.defaultCutId,
                        this.defaultCopyId, this.defaultPasteId], true);
                    this.pdfViewerBase.getElement('_context_menu_separator').classList.add('e-menu-hide');
                    this.pdfViewerBase.getElement('_context_menu_comment_separator').classList.add('e-menu-hide');
                }
                else {
                    this.contextMenuObj.hideItems([this.defaultPropertiesId], true);
                    this.pdfViewerBase.getElement('_context_menu_separator').classList.add('e-menu-hide');
                }
            }
            else if (isSignature) {
                if ((this.pdfViewer.selectedItems.annotations[0].annotName === 'SignatureField' || this.pdfViewer.selectedItems.annotations[0].annotName === 'InitialField' || this.pdfViewer.selectedItems.annotations[0].annotName === 'SignatureText')) {
                    this.contextMenuObj.hideItems([this.defaultPropertiesId, this.defaultCommentId, this.defaultCutId,
                        this.defaultCopyId, this.defaultPasteId], true);
                    this.pdfViewerBase.getElement('_context_menu_separator').classList.add('e-menu-hide');
                    this.pdfViewerBase.getElement('_context_menu_comment_separator').classList.add('e-menu-hide');
                }
                else {
                    this.contextMenuObj.hideItems([this.defaultPropertiesId, this.defaultCommentId], true);
                    this.pdfViewerBase.getElement('_context_menu_separator').classList.add('e-menu-hide');
                    this.pdfViewerBase.getElement('_context_menu_comment_separator').classList.add('e-menu-hide');
                }
            }
            else {
                this.contextMenuObj.hideItems([this.defaultCutId, this.defaultCopyId, this.defaultDeleteId,
                    this.defaultPropertiesId, this.defaultCommentId], true);
                this.pdfViewerBase.getElement('_context_menu_separator').classList.add('e-menu-hide');
                this.pdfViewerBase.getElement('_context_menu_comment_separator').classList.add('e-menu-hide');
            }
        };
        ContextMenu.prototype.OnItemSelected = function (selectedMenu) {
            this.pdfViewerBase.OnItemSelected(selectedMenu);
        };
        ContextMenu.prototype.onMenuItemSelect = function (args) {
            var foundItem = this.filteredCustomItemsIds.find(function (item) { return item === args.item.id; });
            var matchingItemId = ej2_base_1.isNullOrUndefined(foundItem) ? undefined : foundItem.toString();
            if (matchingItemId) {
                this.pdfViewer.firecustomContextMenuSelect(matchingItemId);
            }
            else {
                this.pdfViewerBase.OnItemSelected(args.item.text);
            }
        };
        ContextMenu.prototype.destroy = function () {
            if (this.contextMenuObj) {
                this.previousAction = '';
                this.contextMenuObj.destroy();
                this.contextMenuObj = null;
            }
            this.contextMenuElement = null;
            this.copyContextMenu = null;
            this.contextMenuList = null;
            this.customMenuItems = null;
            this.defaultLength = null;
            this.filteredCustomItemsIds = null;
            this.mainCustomItemsIds = null;
            this.defaultContextMenuItems = null;
            this.defaultCopyId = null;
            this.defaultCutId = null;
            this.defaultPasteId = null;
            this.defaultDeleteId = null;
            this.defaultCommentId = null;
            this.defaultUnderlineId = null;
            this.defaultHighlightId = null;
            this.redactTextId = null;
            this.defaultStrikethroughId = null;
            this.defaultScaleratioId = null;
            this.defaultPropertiesId = null;
            this.copyShowCustomContextMenuBottom = null;
            this.currentTarget = null;
        };
        ContextMenu.prototype.close = function () {
            this.contextMenuObj.close();
        };
        ContextMenu.prototype.open = function (top, left, target) {
            this.contextMenuObj.open(top, left, target);
        };
        ContextMenu.prototype.addCustomContextMenuItems = function () {
            var idSet = new Set();
            this.customMenuItems = this.customMenuItems.reverse().filter(function (item) { return !idSet.has(item.id) && idSet.add(item.id); }).reverse();
            var length = this.customMenuItems.length;
            if (length > 0) {
                if (this.pdfViewer.showCustomContextMenuBottom === true) {
                    for (var i = 0; i < length; i++) {
                        this.copyContextMenu.push(this.customMenuItems[parseInt(i.toString(), 10)]);
                    }
                }
                else {
                    for (var i = length - 1; i >= 0; i--) {
                        this.copyContextMenu.unshift(this.customMenuItems[parseInt(i.toString(), 10)]);
                    }
                }
                this.contextMenuObj.items = this.copyContextMenu;
                this.contextMenuObj.dataBind();
            }
            this.copyShowCustomContextMenuBottom = this.pdfViewer.showCustomContextMenuBottom;
        };
        ContextMenu.prototype.hideDefaultContextMenu = function () {
            this.contextMenuObj.hideItems(this.defaultContextMenuItems);
            this.pdfViewerBase.getElement('_context_menu_separator').classList.add('e-menu-hide');
            this.pdfViewerBase.getElement('_context_menu_comment_separator').classList.add('e-menu-hide');
        };
        return ContextMenu;
    }());
    exports.ContextMenu = ContextMenu;
});