Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions src/views/sourceview.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
if (!this.textarea) {
this.textarea = this.composer.doc.createElement('textarea');
this.textarea.className = "wysihtml5-source-view";
this._observeTextArea();
}
this.textarea.style.width = width + 'px';
this.textarea.style.height = height + 'px';
Expand Down Expand Up @@ -48,6 +49,37 @@
this.switchToTextarea(true);
}
}.bind(this));
},

// Adds event listeners to the textarea
_observeTextArea: function() {
self = this

// Insert listener for key up
this.textarea.addEventListener("keyup", function(event) {
self.editor.fire(event.type, event).fire(event.type + ":texarea", event);
}, false);

// Insert listener for focus
this.textarea.addEventListener("focus", function(event) {
self.editor.fire(event.type, event).fire(event.type + ":texarea", event);

// Save current focus state
setTimeout((function() {
self.focusState = event.target.value;
}).bind(this), 0);
}, false);

// Insert listener for change
this.textarea.addEventListener("blur", function(event) {
self.editor.fire(event.type, event).fire(event.type + ":texarea", event);

// Check if the state has changed
if (self.focusState != event.target.value) {
self.editor.fire("change", event).fire("change:texarea", event);
}

}, false);
}

});
Expand Down