Skip to content

Commit

Permalink
make multiple instances of wysiwyg editor work
Browse files Browse the repository at this point in the history
  • Loading branch information
weilu committed Mar 4, 2014
1 parent 71c4809 commit 46b90be
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 12 deletions.
22 changes: 12 additions & 10 deletions app/views/admin/documents/_form.html.slim
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,18 @@ javascript:
container: "body"
});
$(".editor").wysiwyg({
hotKeys: {
"ctrl+b meta+b": "bold",
"ctrl+i meta+i": "italic",
"ctrl+u meta+u": "underline",
"ctrl+z meta+z": "undo",
"ctrl+y meta+y meta+shift+z": "redo"
},
dragAndDropImages: false
});
$(".editor").each(function(){
$(this).wysiwyg({
hotKeys: {
"ctrl+b meta+b": "bold",
"ctrl+i meta+i": "italic",
"ctrl+u meta+u": "underline",
"ctrl+z meta+z": "undo",
"ctrl+y meta+y meta+shift+z": "redo"
},
dragAndDropImages: false
});
})
$('input[type=submit]').on('click', function(event) {
$('.editor').each(function(i, el){
Expand Down
6 changes: 4 additions & 2 deletions vendor/assets/javascripts/bootstrap-wysiwyg.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/* http://github.com/mindmup/bootstrap-wysiwyg */
/* modified: https://github.com/mindmup/bootstrap-wysiwyg/pull/103 */
/*global jQuery, $, FileReader*/
/*jslint browser:true*/
(function ($) {
Expand All @@ -20,12 +21,13 @@
};
$.fn.wysiwyg = function (userOptions) {
var editor = this,
wrapper = $(editor).parent(),
selectedRange,
options,
toolbarBtnSelector,
updateToolbar = function () {
if (options.activeToolbarClass) {
$(options.toolbarSelector).find(toolbarBtnSelector).each(function () {
$(options.toolbarSelector, wrapper).find(toolbarBtnSelector).each(function () {
var command = $(this).data(options.commandRole);
if (document.queryCommandState(command)) {
$(this).addClass(options.activeToolbarClass);
Expand Down Expand Up @@ -103,7 +105,7 @@
input.data(options.selectionMarker, color);
},
bindToolbar = function (toolbar, options) {
toolbar.find(toolbarBtnSelector).click(function () {
toolbar.find(toolbarBtnSelector, wrapper).click(function () {
restoreSelection();
editor.focus();
execCommand($(this).data(options.commandRole));
Expand Down

0 comments on commit 46b90be

Please sign in to comment.