generators/wysihat/templates/javascripts/wysihat_engine.js in wysihat-engine-0.1.6 vs generators/wysihat/templates/javascripts/wysihat_engine.js in wysihat-engine-0.1.7

- old
+ new

@@ -2,16 +2,16 @@ var WysihatHelper = { faceboxFile: function() { facebox.loading(); - new Effect.Appear($('facebox'), {duration: .3}); + new Effect.Appear($('facebox'), {duration: 0.3}); var fb = facebox; - var url = '/wysihat_files/?editor=' + this.id + var url = '/wysihat_files/?editor=' + this.id; - new Ajax.Request(url, { + new Ajax.Request(url, { method : 'get', onFailure : function(transport){ fb.reveal(transport.responseText, null); }, onSuccess : function(transport){ @@ -24,78 +24,56 @@ { if (this.linkSelected()) { this.unlinkSelection(); } else { facebox.loading(); - new Effect.Appear($('facebox'), {duration: .3}); - iframe = this + new Effect.Appear($('facebox'), {duration: 0.3}); + iframe = this; 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: .3}); - iframe = this + 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); Event.observe('html_editor', 'change', function(event) { iframe.contentWindow.document.body.innerHTML = $('html_editor').value; }); - }, -} + } +}; -WysiHat.Editor.include(WysihatHelper); - -Event.observe(window, 'load', function() { - $$('textarea.wysihat_editor').each(function(i){ - var editor = WysiHat.Editor.attach(i.id); - var toolbar = new WysiHat.Toolbar(editor); - toolbars[i.id] = toolbar; - - editor.inputFilter = function(text) { - return text.formatHTMLOutput().sanitize({ - tags: ['span', 'p', 'br', 'strong', 'em', 'a'], - attributes: ['id', 'href'] - }); - }; - - editor.observe("wysihat:paste", function(event) { - setTimeout(function() { - event.target.reload(); - }, 1); - }); - - $$('form').each(function(f){ - f.onsubmit = function(){ - editor.save(); - } - }); - }); -}); - -function addButtons(tag_id, buttons){ - Event.observe(window, 'load', function() { - buttons.each(function(button){ +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(); + }; + }); - switch(button.toLowerCase()){ - case 'image': - toolbars[tag_id].addButton({label : button.gsub('_','-').camelize().capitalize(), handler: function(editor) { return editor.faceboxFile(editor); }}); - break; - case 'link': - toolbars[tag_id].addButton({label : button.gsub('_','-').camelize().capitalize(), handler: function(editor) { return editor.faceboxLink(editor); }}); - break; - case 'html': - toolbars[tag_id].addButton({label : button.gsub('_','-').camelize().capitalize(), handler: function(editor) { return editor.faceboxHTML(editor); }}); - break; - case 'paste': - toolbars[tag_id].addButton({label : button.gsub('_','-').camelize().capitalize(), handler: function(editor) { return editor.faceboxPaste(editor); }}); - break; - default: - toolbars[tag_id].addButton({label : button.gsub('_','-').camelize().capitalize()}); - } - }) - }) -} \ No newline at end of file + 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()}); + } + }); +}