lib/wysihat-engine.rb in wysihat-engine-0.1.0 vs lib/wysihat-engine.rb in wysihat-engine-0.1.1

- old
+ new

@@ -27,97 +27,28 @@ end options['buttons'].each do |b| case b.to_s.downcase when "image" - buttons << "toolbar.addButton({label : \'Image\', handler: function(editor) { return editor.faceBoxFile(editor); } })\n" + buttons << "toolbars['#{tag_id}'].addButton({label : \'Image\', handler: function(editor) { return editor.faceBoxFile(editor); } })\n" when "link" - buttons << "toolbar.addButton({label : \'Link\', handler: function(editor) { return editor.faceboxLink(editor); } })\n" + buttons << "toolbars['#{tag_id}'].addButton({label : \'Link\', handler: function(editor) { return editor.faceboxLink(editor); } })\n" when "html" - buttons << "toolbar.addButton({label : \'HTML\', handler: function(editor) { return editor.faceboxHTML(editor); } })\n" + buttons << "toolbars['#{tag_id}'].addButton({label : \'HTML\', handler: function(editor) { return editor.faceboxHTML(editor); } })\n" when "paste" - buttons << "toolbar.addButton({label : \'Paste\', handler: function(editor) { return editor.faceboxPaste(editor); } })\n" + buttons << "toolbars['#{tag_id}'].addButton({label : \'Paste\', handler: function(editor) { return editor.faceboxPaste(editor); } })\n" else - buttons << "toolbar.addButton({label : \'#{b.to_s.split('_').map {|w| w.capitalize}.join}\'});\n" + buttons << "toolbars['#{tag_id}'].addButton({label : \'#{b.to_s.split('_').map {|w| w.capitalize}.join}\'});\n" end end options.delete('buttons'); content_tag( :script, - " - var WysihatHelper = { - faceBoxFile: function() - { - facebox.loading(); - new Effect.Appear($('facebox'), {duration: .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: .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 - 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; - }); - }, - - faceboxPaste: function() - { - facebox.loading(); - new Effect.Appear($('facebox'), {duration: .3}); - iframe = this - facebox.reveal('<textarea id=\"paste_editor\" style=\"width:100%; height:400px;\"></textarea>', null); - Event.observe('paste_editor', 'change', function(event) { - iframe.contentWindow.document.body.innerHTML = iframe.contentWindow.document.body.innerHTML + $('paste_editor').value.escapeHTML(); - }); - } - } - - WysiHat.Editor.include(WysihatHelper); - - Event.observe(window, 'load', function() { - var editor = WysiHat.Editor.attach('#{tag_id}'); - var toolbar = new WysiHat.Toolbar(editor); + "Event.observe(window, 'load', function() { #{buttons} - - $$('form').first().onsubmit = function(){ - editor.save(); - }; - - }); - ", + })", :type => 'text/javascript' ) << content_tag("textarea", html_escape(options.delete('value') || value_before_type_cast(object)), options.merge(:class => 'wysihat_editor')) end end \ No newline at end of file