var toolbars = []; var WysihatHelper = { faceboxFile: function() { facebox.loading(); new Effect.Appear($('facebox'), {duration: 0.3}); var fb = facebox; var url = '/wysihat_files/?editor=' + this.id; new Ajax.Request(url, { method : 'get', onFailure : function(transport){ fb.reveal(transport.responseText, null); }, 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('', 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('', 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(); }; }); buttons.each(function(button){ switch(button.toLowerCase()){ case 'image': 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); }}); break; case 'html': 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); }}); break; default: toolbar.addButton({label : button.gsub('_','-').camelize().capitalize()}); } }); }