Comments (4)
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.
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.
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.
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)
- wysihtml is not defined HOT 12
- Html is cleaned up after inserting an image or link when the composer is empty
- Update Value Of Existing Editors HOT 1
- Wyishtml crashes on IE 11 when formatting block with p HOT 1
- wysihtml.com home page textArea
- parser: whitelist `data-foo` attribute HOT 1
- Page scrolls down after document load on Firefox HOT 12
- Anchor Tag Isn't Applying href Attribute HOT 1
- loose the focus
- inserting a link are confusing control.
- Is there a way to get editor instance from the element
- Insert link with additional data
- cannot create link with href attr
- "Change" event is not triggered once a link is added/removed
- Type for parserRules
- Inserting element at start/end of line
- [QUESTION] Where I can find the CI service?
- ctrl+right/left arrow support
- Trying to get in touch regarding a security issue
- insertUnorderedList seems like it could be rolled into outdentList and indentList
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from wysihtml.