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

59.09% Statements 13/22
0% Branches 0/2
33.33% Functions 3/9
59.09% Lines 13/22

    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
    401×
    1×
    95×
    94×

    94×
    94×
    94×

    1×
    96×

    1×

    1×

    1×

    1×
     import $ from 'jquery';
    export default class Placeholder {
      constructor(context) {
        this.context = context;

        this.$editingArea = context.layoutInfo.editingArea;
        this.options = context.options;
        this.events = {
          'summernote.init summernote.change': () => {
            this.update();
          },
          'summernote.codeview.toggled': () => {
            this.update();
          },
        };
      }

      shouldInitialize() {
        return !!this.options.placeholder;
      }

      initialize() {
        this.$placeholder = $('<div class="note-placeholder">');
        this.$placeholder.on('click', () => {
          this.context.invoke('focus');
        }).html(this.options.placeholder).prependTo(this.$editingArea);

        this.update();
      }

      destroy() {
        this.$placeholder.remove();
      }

      update() {
        const isShow = !this.context.invoke('codeview.isActivated') && this.context.invoke('editor.isEmpty');
        this.$placeholder.toggle(isShow);
      }
    }