layerssss / paste.js

read image/text data from clipboard (cross-browser)
http://layerssss.github.io/paste.js/
MIT License
463 stars 94 forks source link

Rewritten the whole library using a more classic approach. #4

Closed EugenMayer closed 9 years ago

EugenMayer commented 9 years ago

now we should be able to handle browser specific implementation easier. Added a lot case-documentation

layerssss commented 9 years ago

I'll make a few adjustments on this tomorrow. To support contenteditable without affecting the focus behavior is a good start.

Also try to fix #3 . We don't need to create a hidden div if:

  1. we already have a contenteditable (from WSIWYG editor, maybe)
  2. or we are in chrome / IE11
EugenMayer commented 9 years ago

firefox and chrome are working now, IE11 not tested

EugenMayer commented 9 years ago

Now working version for IE11, Firefox and Chrome - safari is not working and will not work, see this browser bug http://jsfiddle.net/0psu172n/13/

layerssss commented 9 years ago

Hi, @EugenMayer , I'm going to close this pull-request, and instead, I've implemented the interface for contenteditable in #5 . I have two reasons for this:

  1. 5 didn't introduce browser-specific usage, hacking is inside the lib, not visible to users

  2. 5 didn't introduce a callback. I think configuring a callback is not very user-friendly, so I managed to use the "mark and sweep" way to detect which is the new image pasted under firefox. I did it in https://github.com/layerssss/paste.js/pull/5/files#diff-7ac007ae909854c3175f2730e5accce2R120 . It's quite clean.

I also took your idea to make three modes of invoking the library:

  1. non-inputable element, like my first user-case
  2. textarea, like the github comment box
  3. visible contenteditable, this is surely a very important one.

I finally abstract them into three shorthand methods, to be used the way like other popular jquery plugins. E.g. when you have a contenteditable, and you want to handle the image uploading by js. you can call:

$ '#mycontenteditable'
  .pastableContenteditable()
  .on 'pasteImage', (data)->
    # now images are already removed from contenteditable by paste.js
    uploadImageByDataURL data.dataURL, (url_on_cdn)->
      # uploaded, insert the image into contenteditable
      $(document.createElement 'img').attr('src', url_on_cdn).appendTo('#mycontenteditable')

I hope this can solve your problem, and many thanks to the help.

by the way, here's some information I found when I firstly made this lib. There might be useful if you continue working on this lib

EugenMayer commented 9 years ago

so you basically just dumped the merge. Whatever - then i guess our joint effort stops here.