Code Monkey home page Code Monkey logo

Comments (4)

anthonyjb avatar anthonyjb commented on September 28, 2024 1

Hi @tuhlmann - yes there is an event/notification for the editable content it is documented here under the ContentEdit API.

For your question specifically if you wanted to know whenever the content of the document was changed you could use the following code:

ContentEdit.Root.get().bind('taint', function (element) {
    console.log(element, 'just got changed');
});

Hope that helps and thanks for your interest in CT.

from contenttools.

tuhlmann avatar tuhlmann commented on September 28, 2024

Thanks for the quick reply- I look into it.

from contenttools.

tuhlmann avatar tuhlmann commented on September 28, 2024

@anthonyjb I got a simple integration with our app working and see the fired taint event.
From what I see the event carries all the contents of the region as a "Character" array. Is there also a way to see only the changes or would I need to diff it myself?

from contenttools.

anthonyjb avatar anthonyjb commented on September 28, 2024

You'd need to perform the diff yourself I'm afraid. The array of characters is a HTMLString instance, you can out put either the HTML or text version of the content to perform a diff using:

var htmlVersion = element.content.html();
var textVersion = element.content.text();

You could look to capture focus events, store a snapshot of the elements content and then capture blur events to compare the contents to see if it's changed, as a simplified example you could approach this like so:

var snapshot = null;
ContentEdit.Root.get().bind('focus', function (element) {

    // We only care about elements that support content
    if (element.content === undefined) {
        snapshot = null;
        return;
    }

    // Take a snapshot
    snapshot = element.content.text()
});

ContentEdit.Root.get().bind('blur', function (element) {

    // Check we have a snapshot to compare
    if (snapshot === null) {
        return;
    }

    // Compare the snapshots
    someDiffFunc(snapshot, element.content.text());

    // Clear the snapshot
    snapshot = null;
});

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.