Skip to content

Instantly share code, notes, and snippets.

@patik
Created September 3, 2012 19:59
Show Gist options
  • Save patik/3612901 to your computer and use it in GitHub Desktop.
Save patik/3612901 to your computer and use it in GitHub Desktop.
wysihtml5 mulitiple editors issue
<div id="alpha-toolbar"><!-- Toolbar commands here --></div>
<textarea id="alpha"></textarea>
<div id="bravo-toolbar"><!-- Toolbar commands here --></div>
<textarea id="bravo"></textarea>
<div id="charlie-toolbar"><!-- Toolbar commands here --></div>
<textarea id="charlie"></textarea>
var editor,
editors = [], // Will hold all wysihtml5.Editor objects
textareas = ['alpha', 'bravo', 'charlie']; // List of IDs of the <textarea>s
textareas.forEach(function (textarea, index)) {
// Create editor for this <textarea>
editor = new wysihtml5.Editor(textarea, {
toolbar: textarea + "-toolbar",
stylesheets: ["reset.css", "editor.css"],
parserRules: wysihtml5ParserRules
});
// Add editor to list for later reference
editors[index] = editor;
// Add event listeners
editors[index].on("load", function() {
// How can references to EDITOR in this function be changed to reference the object on which the event fired?
// i.e., editors[1] or editors[4]
var composer = EDITOR.composer;
composer.selection.selectNode(EDITOR.composer.element.querySelector("h1"));
});
});
var editors = {}, // Will hold all wysihtml5.Editor objects
textareas = ['alpha', 'bravo', 'charlie']; // List of IDs of the <textarea>s
textareas.forEach(function (textarea) {
// Create editor for this <textarea>
// Add editor to list for later reference
editors[textarea] = new wysihtml5.Editor(textarea, {
toolbar: textarea + "-toolbar",
stylesheets: ["css/reset-min.css", "css/editor.css"],
parserRules: wysihtml5ParserRules
});
// Add event listeners
editors[textarea].on("load", function() {
// Reference to the editor object: this
// Reference to the <textarea> element: this.textareaElement
var editor = editors[this.textareaElement.id],
composer = editor.composer;
composer.selection.selectNode(editor.composer.element.querySelector("h1"));
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment