This repository has been archived by the owner. It is now read-only.
Permalink
Browse files

Complete changed how it works, we now hijack the form target and retu…

…rn it to it's original state after the submit
  • Loading branch information...
Glenn Murray
Glenn Murray committed Oct 24, 2008
1 parent 814b43c commit 8b5699720df8ea7a70a76b0c5aaa140385651b71
@@ -1,2 +1,2 @@
-%iframe{:id => 'page-preview', :src => 'about:blank', :frameborder => 0, :style => 'width:100%;height:40em;display:none;border:1px solid black;'}
- You don't support iframes. No preview for you.
+%iframe{:id => 'page-preview', :name => 'page-preview', :src => 'about:blank', :frameborder => 0, :style => 'width:100%;height:40em;display:none;border:1px solid black;'}
+ You don't support iframes. No preview for you.
@@ -1,4 +1,3 @@
= javascript_include_tag 'page_preview'
-%div
- %input{:type=>'button', :id => 'show-preview', :value => 'Preview', :class => 'button', :onclick => 'preview()'}
-#preview_container
+%p.buttons{:style => 'float: left; padding-right: 5px;' }
+ %input{:type=>'submit', :id => 'show-preview', :value => 'Preview', :class => 'button', :onclick => 'preview(this)'}
@@ -12,7 +12,8 @@ class PagePreviewExtension < Radiant::Extension
def activate
# admin.tabs.add "Page Preview", "/admin/page_preview", :after => "Layouts", :visibility => [:all]
- admin.page.edit.add :main, "/preview/show", :after => "edit_buttons"
+ admin.page.edit.add :form_bottom, "/preview/show", :before => 'edit_buttons'
+ admin.page.edit.add :form_bottom, "/preview/preview_iframe", :after => 'edit_buttons'
end
def deactivate
@@ -1,31 +1,16 @@
-function write_to_iframe(text) {
- // delete page-preview if it exists
- if ( $('page-preview') )
- $('page-preview').parentNode.removeChild($('page-preview'));
- var iframe = document.createElement('iframe');
- iframe.id = 'page-preview';
- iframe.setAttribute('frameborder','0');
- iframe.setAttribute('src','/blank-iframe.html');
- iframe.style.width = "100%";
- iframe.style.height = "40em";
- iframe.style.display = "none";
- iframe.style.border = "1px solid black";
- iframe.style.marginTop = '0.3em';
- $('preview_container').appendChild(iframe);
- var doc = $('page-preview').contentDocument;
- if (doc == undefined || doc == null)
- doc = $('page-preview').contentWindow.document;
- doc.open();
- doc.write(text);
- doc.close();
+function preview(button) {
+ form = button.form;
+ oldtarget = form.target;
+ oldaction = form.action;
+
$('page-preview').show();
-}
-function preview() {
- new Ajax.Request('/admin/preview', {
- method: 'post',
- parameters: Form.serialize(document.forms[0]),
- onSuccess: function(response) { write_to_iframe(response.responseText); }
- })
- write_to_iframe("Loading…");
- $('page-preview').style.display = 'block';
+
+ form.setAttribute('target', 'page-preview');
+ form.setAttribute('action', '/admin/preview');
+
+
+ window.setTimeout(function() {
+ form.target = oldtarget;
+ form.action = oldaction;
+ }, 1000);
}

0 comments on commit 8b56997

Please sign in to comment.