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

60% Statements 9/15
0% Branches 0/9
75% Functions 3/4
60% Lines 9/15

    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
    291×

    1×
    1×
    91×
    91×

    1×
    91×

    1×

    1×
     import lists from '../core/lists';

    export default class Clipboard {
      constructor(context) {
        this.context = context;
        this.$editable = context.layoutInfo.editable;
      }

      initialize() {
        this.$editable.on('paste', this.pasteByEvent.bind(this));
      }

      /**
       * paste by clipboard event
       *
       * @param {Event} event
       */
      pasteByEvent(event) {
        const clipboardData = event.originalEvent.clipboardData;
        if (clipboardData && clipboardData.items && clipboardData.items.length) {
          const item = lists.head(clipboardData.items);
          if (item.kind === 'file' && item.type.indexOf('image/') !== -1) {
            this.context.invoke('editor.insertImagesOrCallback', [item.getAsFile()]);
          }
          this.context.invoke('editor.afterCommand');
        }
      }
    }