Created
September 3, 2012 19:59
-
-
Save patik/3612901 to your computer and use it in GitHub Desktop.
wysihtml5 mulitiple editors issue
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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")); | |
}); | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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