Code Monkey home page Code Monkey logo

Comments (4)

anthonyjb avatar anthonyjb commented on August 18, 2024

Yes absolutely, the editor has a paste method which can be monkey patched for example:

# Monkey patch editors paste method
editorCls = ContentTools.EditorApp.getCls()
editorCls.paste = (element, clipboardData) ->
    ... add you custom handler here ...

element is the element being pasted into, and clipboardData is the content pasted by the user (https://developer.mozilla.org/en-US/docs/Web/API/ClipboardEvent/clipboardData).

You will need to use the develop branch as I modified the source to ensure the clipboardData is sent to the paste event, previously only a plain text version of the content was sent.

from contenttools.

mlshvdv avatar mlshvdv commented on August 18, 2024

@anthonyjb I tried to patch 'develop' version with following code, but console.log('Paste', arguments); doesn't shows pasted data:

  window.onload = function() {
    var editor, req;
    editor = new ContentTools.EditorApp.get();
    editor.paste = function(element, clipboardData){

      console.log('Paste', arguments); // What's wrong?

    };
    editor.init('.editable', 'data-name');
    editor.bind('save', function(regions, autoSave) {
      var saved;
      editor.busy(true);
      saved = (function(_this) {
        return function() {
          editor.busy(false);
          return new ContentTools.FlashUI('ok');
        };
      })(this);
      return setTimeout(saved, 2000);
    });
    req = new XMLHttpRequest();
    req.overrideMimeType('application/json');
    req.open('GET', 'https://raw.githubusercontent.com/GetmeUK/ContentTools/master/translations/lp.json', true);
    return req.onreadystatechange = function(ev) {
      var translations;
      if (ev.target.readyState === 4) {
        translations = JSON.parse(ev.target.responseText);
        ContentEdit.addTranslations('lp', translations);
        return ContentEdit.LANGUAGE = 'lp';
      }
    };
  };

from contenttools.

anthonyjb avatar anthonyjb commented on August 18, 2024

So if I patch the editor as you have done and console.log the clipboardData value I get a DataTransfer object which I can use to query for pasted data (https://developer.mozilla.org/en-US/docs/Web/API/ClipboardEvent).

This allows me to query the pasted data, for example: clipboardData.getData('text/plain'), what is the value of clipboardData for you?

editor.paste = function (element, clipboardData) {
    console.log(clipboardData.getData('text/plain'));
}

from contenttools.

mlshvdv avatar mlshvdv commented on August 18, 2024

Works great! Thank you!

from contenttools.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.