Project

General

Profile

Feature #3816 » attach_clipboard_image_short_file_name.patch

Takenori TAKAKI, 2019-02-16 02:05

View differences:

public/javascripts/attachments.js
255 255
  $("input.deleted_attachment").change(function(){
256 256
    $(this).parents('.existing-attachment').toggleClass('deleted', $(this).is(":checked"));
257 257
  }).change();
258
  $(".filedroplistner .wiki-edit").on('paste', function(e){
259
    var items = e.originalEvent.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-'
266
            + date.getFullYear() + ('0'+(date.getMonth()+1)).slice(-2) + ('0'+date.getDate()).slice(-2)
267
            + ('0'+date.getHours()).slice(-2) + ('0'+date.getMinutes()).slice(-2) + ('0'+date.getSeconds()).slice(-2)
268
            + '-' + randomKey(7).toLocaleLowerCase() + '.' + blob.name.split('.').pop();
269
        var file = new File([blob], filename, {type: blob.type});
270
        var inputEl = $('input[name="attachments[dummy][file]"]');
271
        handleFileDropEvent.target = e.target;
272
        addFile(inputEl, file, true);
273
      }
274
    }
275
  });
258 276
});
(22-22/24)