Code coverage report for src/js/summernote.js

# all files / src/js/ summernote.js

19.23% Statements 5/26
0% Branches 0/12
0% Functions 0/2
19.23% Lines 5/26

    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
    471×
    1×
    1×
    1×

    1×

     import $ from 'jquery';
    import env from './base/core/env';
    import lists from './base/core/lists';
    import Context from './base/Context';

    $.fn.extend({
      /**
       * Summernote API
       *
       * @param {Object|String}
       * @return {this}
       */
      summernote: function() {
        const type = $.type(lists.head(arguments));
        const isExternalAPICalled = type === 'string';
        const hasInitOptions = type === 'object';

        const options = $.extend({}, $.summernote.options, hasInitOptions ? lists.head(arguments) : {});

        // Update options
        options.langInfo = $.extend(true, {}, $.summernote.lang['en-US'], $.summernote.lang[options.lang]);
        options.icons = $.extend(true, {}, $.summernote.options.icons, options.icons);
        options.tooltip = options.tooltip === 'auto' ? !env.isSupportTouch : options.tooltip;

        this.each((idx, note) => {
          const $note = $(note);
          if (!$note.data('summernote')) {
            const context = new Context($note, options);
            $note.data('summernote', context);
            $note.data('summernote').triggerEvent('init', context.layoutInfo);
          }
        });

        const $note = this.first();
        if ($note.length) {
          const context = $note.data('summernote');
          if (isExternalAPICalled) {
            return context.invoke.apply(context, lists.from(arguments));
          } else if (options.focus) {
            context.invoke('editor.focus');
          }
        }

        return this;
      },
    });