attach_clipboard_images_v2.patch

Marius BALTEANU, 2019-02-17 15:20

Download (1.39 KB)

View differences:

public/javascripts/attachments.js
201 201
      $(this).on({
202 202
          dragover: dragOverHandler,
203 203
          dragleave: dragOutHandler,
204
          drop: handleFileDropEvent
204
          drop: handleFileDropEvent,
205
          paste: copyImageFromClipboard
205 206
      }).addClass('filedroplistner');
206 207
    });
207 208
  }
......
250 251
  }
251 252
}
252 253

  
254
function copyImageFromClipboard(e) {
255
  if (!$(e.target).hasClass('wiki-edit')) { return; }
256
  var clipboardData = e.clipboardData || e.originalEvent.clipboardData
257
  if (!clipboardData) { return; }
258

  
259
  var items = clipboardData.items
260
  for (var i = 0 ; i < items.length ; i++) {
261
    var item = items[i];
262
    if (item.type.indexOf("image") != -1) {
263
      var blob = item.getAsFile();
264
      var date = new Date();
265
      var filename = 'clipboard-' + date.getTime() + '.' + blob.name.split('.').pop();
266
      var file = new File([blob], filename, {type: blob.type});
267
      var inputEl = $('input:file.filedrop').first()
268
      handleFileDropEvent.target = e.target;
269
      addFile(inputEl, file, true);
270
    }
271
  }
272
}
273

  
253 274
$(document).ready(setupFileDrop);
254 275
$(document).ready(function(){
255 276
  $("input.deleted_attachment").change(function(){