generators/wysihat/templates/javascripts/wysihat_engine.js in wysihat-engine-0.1.8 vs generators/wysihat/templates/javascripts/wysihat_engine.js in wysihat-engine-0.1.9
- old
+ new
@@ -1,6 +1,6 @@
-var toolbars = [];
+var editors = [];
var WysihatHelper = {
faceboxFile: function()
{
facebox.loading();
@@ -17,63 +17,67 @@
onSuccess : function(transport){
fb.reveal(transport.responseText, null);
}
});
},
-
+
faceboxLink: function()
{
if (this.linkSelected()) {
this.unlinkSelection();
} else {
facebox.loading();
new Effect.Appear($('facebox'), {duration: 0.3});
iframe = this;
- facebox.reveal('<input type=\"text\" id=\"link_field\" style=\"width:100%;\"/>', null);
+ facebox.reveal('<input type=\"text\" id=\"link_field\" style=\"width:100%;\"/>', null);
Event.observe('link_field', 'change', function(event) {
iframe.linkSelection($('link_field').value);
});
}
},
-
+
faceboxHTML: function()
{
facebox.loading();
new Effect.Appear($('facebox'), {duration: 0.3});
iframe = this;
- facebox.reveal('<textarea id=\"html_editor\" style=\"width:100%; height:400px;\">' + iframe.contentWindow.document.body.innerHTML + '</textarea>', null);
+ facebox.reveal('<textarea id=\"html_editor\" style=\"width:100%; height:400px;\">' + iframe.contentWindow.document.body.innerHTML + '</textarea>', null);
Event.observe('html_editor', 'change', function(event) {
iframe.contentWindow.document.body.innerHTML = $('html_editor').value;
});
}
};
function wysiHatify(tag_id, buttons){
WysiHat.Editor.include(WysihatHelper);
var editor = WysiHat.Editor.attach(tag_id);
var toolbar = new WysiHat.Toolbar(editor);
-
- $$('form').each(function(i){
- i.onsubmit = function(){
- editor.save();
+
+ editors.push(editor);
+
+ $$('form').each(function(f){
+ f.onsubmit = function(){
+ editors.each(function(e){
+ e.save();
+ });
};
});
-
- buttons.each(function(button){
+
+ buttons.each(function(button){
switch(button.toLowerCase()){
case 'image':
- toolbar.addButton({label : button.gsub('_','-').camelize().capitalize(), handler: function(editor) { return editor.faceboxFile(editor); }});
+ toolbar.addButton({label : button.gsub('_','-').camelize().capitalize(), handler: function(editor) { return editor.faceboxFile(editor); }});
break;
case 'link':
- toolbar.addButton({label : button.gsub('_','-').camelize().capitalize(), handler: function(editor) { return editor.faceboxLink(editor); }});
+ toolbar.addButton({label : button.gsub('_','-').camelize().capitalize(), handler: function(editor) { return editor.faceboxLink(editor); }});
break;
case 'html':
- toolbar.addButton({label : button.gsub('_','-').camelize().capitalize(), handler: function(editor) { return editor.faceboxHTML(editor); }});
+ toolbar.addButton({label : button.gsub('_','-').camelize().capitalize(), handler: function(editor) { return editor.faceboxHTML(editor); }});
break;
case 'paste':
- toolbar.addButton({label : button.gsub('_','-').camelize().capitalize(), handler: function(editor) { return editor.faceboxPaste(editor); }});
+ toolbar.addButton({label : button.gsub('_','-').camelize().capitalize(), handler: function(editor) { return editor.faceboxPaste(editor); }});
break;
default:
toolbar.addButton({label : button.gsub('_','-').camelize().capitalize()});
}
- });
+ });
}