Code coverage report for src/js/base/module/Dropzone.js

# all files / src/js/base/module/ Dropzone.js

51.52% Statements 34/66
5.56% Branches 1/18
47.06% Functions 8/17
50.77% Lines 33/65

    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
    1141×
    1×
    1×
    1×
    2×
    97×
    97×
    97×
    97×
    97×
    97×
    97×
    97×

    1×
    97×

    97×

    1×
    97×
    97×
    97×
    97×

    97×

    97×

    97×

    97×

    97×

    1×
    2×
    2×
    6×

    2×

    1×

    1×

     (function(global){global.wrappers['/Users/lqez/Dev/summernote/src/js/base/module/Dropzone.js']=[function(require,module,exports,__dirname,__filename){ "use strict";
    exports.__esModule = true;
    var jquery_1 = require("jquery");
    var Dropzone = /** @class */ (function () {
        function Dropzone(context) {
            this.context = context;
            this.$eventListener = jquery_1["default"](document);
            this.$editor = context.layoutInfo.editor;
            this.$editable = context.layoutInfo.editable;
            this.options = context.options;
            this.lang = this.options.langInfo;
            this.documentEventHandlers = {};
            this.$dropzone = jquery_1["default"]([
                '<div class="note-dropzone">',
                '  <div class="note-dropzone-message"/>',
                '</div>',
            ].join('')).prependTo(this.$editor);
        }
        /**
         * attach Drag and Drop Events
         */
        Dropzone.prototype.initialize = function () {
            Iif (this.options.disableDragAndDrop) {
                // prevent default drop event
                this.documentEventHandlers.onDrop = function (e) {
                    e.preventDefault();
                };
                // do not consider outside of dropzone
                this.$eventListener = this.$dropzone;
                this.$eventListener.on('drop', this.documentEventHandlers.onDrop);
            }
            else {
                this.attachDragAndDropEvent();
            }
        };
        /**
         * attach Drag and Drop Events
         */
        Dropzone.prototype.attachDragAndDropEvent = function () {
            var _this = this;
            var collection = jquery_1["default"]();
            var $dropzoneMessage = this.$dropzone.find('.note-dropzone-message');
            this.documentEventHandlers.onDragenter = function (e) {
                var isCodeview = _this.context.invoke('codeview.isActivated');
                var hasEditorSize = _this.$editor.width() > 0 && _this.$editor.height() > 0;
                if (!isCodeview && !collection.length && hasEditorSize) {
                    _this.$editor.addClass('dragover');
                    _this.$dropzone.width(_this.$editor.width());
                    _this.$dropzone.height(_this.$editor.height());
                    $dropzoneMessage.text(_this.lang.image.dragImageHere);
                }
                collection = collection.add(e.target);
            };
            this.documentEventHandlers.onDragleave = function (e) {
                collection = collection.not(e.target);
                if (!collection.length) {
                    _this.$editor.removeClass('dragover');
                }
            };
            this.documentEventHandlers.onDrop = function () {
                collection = jquery_1["default"]();
                _this.$editor.removeClass('dragover');
            };
            // show dropzone on dragenter when dragging a object to document
            // -but only if the editor is visible, i.e. has a positive width and height
            this.$eventListener.on('dragenter', this.documentEventHandlers.onDragenter)
                .on('dragleave', this.documentEventHandlers.onDragleave)
                .on('drop', this.documentEventHandlers.onDrop);
            // change dropzone's message on hover.
            this.$dropzone.on('dragenter', function () {
                _this.$dropzone.addClass('hover');
                $dropzoneMessage.text(_this.lang.image.dropImage);
            }).on('dragleave', function () {
                _this.$dropzone.removeClass('hover');
                $dropzoneMessage.text(_this.lang.image.dragImageHere);
            });
            // attach dropImage
            this.$dropzone.on('drop', function (event) {
                var dataTransfer = event.originalEvent.dataTransfer;
                // stop the browser from opening the dropped content
                event.preventDefault();
                if (dataTransfer && dataTransfer.files && dataTransfer.files.length) {
                    _this.$editable.focus();
                    _this.context.invoke('editor.insertImagesOrCallback', dataTransfer.files);
                }
                else {
                    jquery_1["default"].each(dataTransfer.types, function (idx, type) {
                        var content = dataTransfer.getData(type);
                        if (type.toLowerCase().indexOf('text') > -1) {
                            _this.context.invoke('editor.pasteHTML', content);
                        }
                        else {
                            jquery_1["default"](content).each(function (idx, item) {
                                _this.context.invoke('editor.insertNode', item);
                            });
                        }
                    });
                }
            }).on('dragover', false); // prevent default dragover event
        };
        Dropzone.prototype.destroy = function () {
            var _this = this;
            Object.keys(this.documentEventHandlers).forEach(function (key) {
                _this.$eventListener.off(key.substr(2).toLowerCase(), _this.documentEventHandlers[key]);
            });
            this.documentEventHandlers = {};
        };
        return Dropzone;
    }());
    exports["default"] = Dropzone;

    },'src/js/base/module/Dropzone.js',{"jquery":"/Users/lqez/Dev/summernote/node_modules/jquery/dist/jquery.js"}];})(this);
    //# sourceMappingURL=data:application/json;charset=utf-8;base64,[encoded data, 10576 characters]