all files / document-editor/implementation/dialogs/ pic-contentControl-dialog.js

32.76% Statements 19/58
25% Branches 2/8
41.67% Functions 5/12
32.76% Lines 19/58
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   144× 144×       144×                       144×   14486×                                                                         197× 197×       197×              
define(["require", "exports", "@syncfusion/ej2-base"], function (require, exports, ej2_base_1) {
    "use strict";
    Object.defineProperty(exports, "__esModule", { value: true });
    var PicContentControlDialog = (function () {
        function PicContentControlDialog(documentHelper) {
            var _this = this;
            this.onCancelButtonClick = function () {
                _this.documentHelper.dialog2.hide();
                _this.documentHelper.updateFocus();
            };
            this.onInsertPicClick = function () {
                _this.documentHelper.dialog2.hide();
                _this.imagePicker = ej2_base_1.createElement('input', {
                    attrs: { type: 'file', accept: '.jpg,.jpeg,.png,.bmp,.svg' }, className: 'e-de-ctnr-file-picker'
                });
                if (ej2_base_1.Browser.isIE) {
                    document.body.appendChild(_this.imagePicker);
                }
                _this.imagePicker.value = '';
                _this.imagePicker.click();
                ej2_base_1.EventHandler.add(_this.imagePicker, 'change', _this.onImageChange, _this);
            };
            this.documentHelper = documentHelper;
        }
        PicContentControlDialog.prototype.getModuleName = function () {
            return 'PicContentControlDialog';
        };
        PicContentControlDialog.prototype.show = function () {
            var localValue = new ej2_base_1.L10n('documenteditor', this.documentHelper.owner.defaultLocale);
            localValue.setLocale(this.documentHelper.owner.locale);
            this.localeValue = localValue;
            this.documentHelper.dialog2.header = localValue.getConstant('Insert Pictures');
            this.documentHelper.dialog2.showCloseIcon = true;
            this.documentHelper.dialog2.allowDragging = true;
            this.documentHelper.dialog2.position = { X: 'center', Y: 'center' };
            this.documentHelper.dialog2.beforeOpen = this.documentHelper.updateFocus;
            this.documentHelper.dialog2.buttons = [{
                    click: this.onInsertPicClick,
                    buttonModel: { content: localValue.getConstant('Upload from computer'), iconCss: 'e-icons e-de-ctnr-upload', iconPosition: 'Left' }
                }];
            this.documentHelper.dialog2.dataBind();
            this.documentHelper.dialog2.show();
        };
        PicContentControlDialog.prototype.onImageChange = function () {
            var _this = this;
            var file = this.imagePicker.files[0];
            var fileReader = new FileReader();
            fileReader.onload = function () {
                _this.insertImage(fileReader.result);
            };
            fileReader.readAsDataURL(file);
        };
        PicContentControlDialog.prototype.insertImage = function (data) {
            this.image = document.createElement('img');
            var documentHelper = this.documentHelper;
            var container = this.container;
            this.image.addEventListener('load', function () {
                documentHelper.owner.editorModule.insertImageInternal(data, true, this.width, this.height, this.alt);
                if (!documentHelper.owner.selection.isImageSelected) {
                    documentHelper.owner.selection.handleShiftLeftKey();
                    documentHelper.owner.editor.insertContentControl('Picture');
                }
            });
            this.image.src = data;
        };
        PicContentControlDialog.prototype.destroy = function () {
            this.documentHelper = undefined;
            Iif (this.imagePicker) {
                this.imagePicker.remove();
                this.imagePicker = undefined;
            }
            Iif (this.image) {
                this.image.remove();
                this.image = undefined;
            }
        };
        return PicContentControlDialog;
    }());
    exports.PicContentControlDialog = PicContentControlDialog;
});