Giter Site home page Giter Site logo

Comments (4)

kasoban avatar kasoban commented on July 29, 2024

I guess you figured this out yourself since you closed the ticket, but let's explain this for anyone stumbling upon this through a search:

The event handlers on the textbox will not get called due to wysihtml creating a contenteditable iframe copied from the textbox attributes and hiding the actual textbox, so there won't be actual user input to the textbox.

from wysihtml.

jengel3 avatar jengel3 commented on July 29, 2024

I actually ended up submitting this to the wrong version of wysi, but they are fairly similar, and I'd be willing to use any version that I can get to work properly. How would I go about tracking user input instead of the way I'm doing it now?

from wysihtml.

kasoban avatar kasoban commented on July 29, 2024

Well, you submitted it to Waxolunist/bootstrap3-wysihtml5-bower which is effectively based on this fork.
Anyway, to access the editor you can do the following:

After you initialized the editor on an element by calling element.wysihtml5(), the initialized editor is stored as a data field for that element. So you can get a hold of it through element.data('wysihtml5').editor for example, if you have jQuery available. From there on you could apply a listener like element.data('wysihtml5').editor.on('change', function() {doSomething;}) or the like.

Here is a list of events exposed by the editor:
https://github.com/xing/wysihtml5/wiki/Events
At the very bottom there is an example for a keydown listener.

from wysihtml.

priithaamer avatar priithaamer commented on July 29, 2024

The event system in wysihtml5x needs an overhaul as the change event does not work properly. Until then we're using a combination of change event listeners and mutation observers to get proper events about changes in editable element. Please note that the following works when using contentEditable version of wysihtml. I have not tested it with iframes:

var el = document.getElementById('editor'),
  editor = new wysihtml5.Editor(el, {});

var handleContentMutation = function(mutations) {
  var mutation = _.some(mutations, function(mutation) {
    return !(mutation.type == 'attributes' && mutation.target == el);
  });

  if (mutation) {
    // It is advised to defer the invocation of this method here, i.e. by
    // using _.defer() from Underscore
    handleContentChange();
  }
}

var handleContentChange = function() {
  // Well, content has been changed now...
};

el.addEventListener('input', handleContentChange);

// Listen for change events on editor in case MutationObserver is not present.
editor.addEventListener('change', handleContentChange);

if (window.MutationObserver) {
  var observer = new MutationObserver(handleContentMutation);
  observer.observe(el, {attributes: true, childList: true, characterData: true});
}

from wysihtml.

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.