Please wait...
diff --git a/app/views/admin/pages/_form.html.erb b/app/views/admin/pages/_form.html.erb index 1c63a6e1d..dab6d32ec 100644 --- a/app/views/admin/pages/_form.html.erb +++ b/app/views/admin/pages/_form.html.erb @@ -1,5 +1,9 @@ +<% content_for(:head) do -%> + <%= javascript_include_tag 'admin/edit-preview' %> +<% end -%> + <% form.input_field_set do -%> <%= form.input :title %> <%= form.input :slug, :hint => "leave blank for an auto-generated slug based on the title" %> - <%= form.input :body, :hint => "Textile enabled" %> + <%= form.input :body, :hint => "Textile enabled. Use Ctrl+E to switch between preview and edit mode." -%> <% end -%> diff --git a/app/views/admin/posts/_form.html.erb b/app/views/admin/posts/_form.html.erb index 4bc23ab14..1541d45f2 100644 --- a/app/views/admin/posts/_form.html.erb +++ b/app/views/admin/posts/_form.html.erb @@ -1,6 +1,10 @@ +<% content_for(:head) do -%> + <%= javascript_include_tag 'admin/edit-preview' %> +<% end -%> + <% form.input_field_set do -%> <%= form.input :title -%> - <%= form.input :body, :hint => "Textile enabled" -%> + <%= form.input :body, :hint => "Textile enabled. Use Ctrl+E to switch between preview and edit mode." -%> <%= form.input :tag_list, :as => 'string', :required => false, :hint => 'comma separated: ruby, rails' -%> <% end -%> <% form.input_field_set do -%> diff --git a/app/views/layouts/admin.html.erb b/app/views/layouts/admin.html.erb index a53c78660..07ba0d942 100644 --- a/app/views/layouts/admin.html.erb +++ b/app/views/layouts/admin.html.erb @@ -14,10 +14,8 @@ <%= javascript_include_tag 'jquery.form.js' %> <%= javascript_include_tag 'jquery.easing.1.3.js' %> <%= javascript_include_tag 'humanmsg' %> - <%= javascript_include_tag 'common' %> <%= javascript_include_tag 'admin/shortcut' %> <%= javascript_include_tag 'admin/common' %> - <%= javascript_include_tag 'admin/live-edit-preview' %> <%= stylesheet_link_tag 'formtastic' %> <%= stylesheet_link_tag 'humanmsg' %> diff --git a/public/javascripts/admin/edit-preview.js b/public/javascripts/admin/edit-preview.js new file mode 100644 index 000000000..a61bc0cec --- /dev/null +++ b/public/javascripts/admin/edit-preview.js @@ -0,0 +1,46 @@ +$(document).ready(function() { + var form = $('form.new_post, form.edit_post, form.new_page, form.edit_page'); + + if (form.length > 0) { + var dest = window.location.href; + if (!dest.match(/\/new$/)) { + dest = dest.replace(/\/\d$/, ''); + dest = dest + '/new'; + } + dest = dest + '/preview' + + var toggle_preview = function() { + if ($('#preview').length == 0) { + form.hide(); + form.after('
Use Ctrl-E to return to edit mode.
Please wait...
Failed to generate preview. Toggle back to edit mode and check that all required fields are filled in and valid.
'); + }, + success: function(r) { + $('#preview .content').html(r); + } + }); + } + else { + $('#preview').remove(); + form.show(); + } + } + + var ctrl_down = false; + $(document).keydown(function(e) { + if (e.which == 224 || e.which == 17) { ctrl_down = true; console.log('ctrl down'); } // Cmd || Ctrl + }); + $(document).keyup(function(e) { + if (e.which == 224 || e.which == 17) { ctrl_down = false; console.log('ctrl up'); } + }); + $(document).keypress(function(e) { + if (ctrl_down && e.which == 101) { toggle_preview(); } // 'E' + }); + } +}); diff --git a/public/javascripts/admin/live-edit-preview.js b/public/javascripts/admin/live-edit-preview.js deleted file mode 100644 index 7c4053909..000000000 --- a/public/javascripts/admin/live-edit-preview.js +++ /dev/null @@ -1,57 +0,0 @@ -$(document).ready(function() { - var form = $('.new_post, .edit_post, .new_page, .edit_page'); - var input_elements = form.find(':text, textarea'); - var textarea = $('#post_body, #page_body'); - var fetch_preview = function() { - var dest = window.location.href; - - if (!dest.endsWith('new')) { - dest = dest.replace(/\/\d$/, ''); - dest = dest + '/new'; - } - dest = dest + '/preview' - - jQuery.ajax({ - type: 'POST', - data: form.serialize().replace(/&*_method=\w+&*/, ''), - url: dest, - timeout: 2000, - error: function() { - console.log("Failed to submit"); - }, - success: function(r) { - if ($('#preview').length == 0) { - form.after('pause live preview