github.com/Azareal/Gosora@v0.0.0-20210729070923-553e66b59003/pubnot/trumbowyg/plugins/pasteimage/trumbowyg.pasteimage.js (about)

     1  /* ===========================================================
     2   * trumbowyg.pasteimage.js v1.0
     3   * Basic base64 paste plugin for Trumbowyg
     4   * http://alex-d.github.com/Trumbowyg
     5   * ===========================================================
     6   * Author : Alexandre Demode (Alex-D)
     7   *          Twitter : @AlexandreDemode
     8   *          Website : alex-d.fr
     9   */
    10  
    11  (function ($) {
    12      'use strict';
    13  
    14      $.extend(true, $.trumbowyg, {
    15          plugins: {
    16              pasteImage: {
    17                  init: function (trumbowyg) {
    18                      trumbowyg.pasteHandlers.push(function (pasteEvent) {
    19                          try {
    20                              var items = (pasteEvent.originalEvent || pasteEvent).clipboardData.items,
    21                                  reader;
    22  
    23                              for (var i = items.length -1; i >= 0; i += 1) {
    24                                  if (items[i].type.match(/^image\//)) {
    25                                      reader = new FileReader();
    26                                      /* jshint -W083 */
    27                                      reader.onloadend = function (event) {
    28                                          trumbowyg.execCmd('insertImage', event.target.result, undefined, true);
    29                                      };
    30                                      /* jshint +W083 */
    31                                      reader.readAsDataURL(items[i].getAsFile());
    32                                  }
    33                              }
    34                          } catch (c) {
    35                          }
    36                      });
    37                  }
    38              }
    39          }
    40      });
    41  })(jQuery);