forked from xaviershay/enki
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement the use of Ctrl-E shortcut to preview posts/pages, instead …
…of live edit preview. (After some testing with live edit preview, found that it is not usable on smaller screen resolutions. Refreshing the preview on every key press is also rather irritating when the body contains external sources such as video, images, etc.)
- Loading branch information
1 parent
2c23e65
commit c49afe4
Showing
6 changed files
with
85 additions
and
88 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 => "<a href='http://hobix.com/textile/quick.html'>Textile enabled</a>" %> | ||
<%= form.input :body, :hint => "<a href='http://hobix.com/textile/quick.html'>Textile enabled</a>. Use Ctrl+E to switch between preview and edit mode." -%> | ||
<% end -%> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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('<div id="preview"><h3>Your entry will be formatted like this:</h3><p>Use Ctrl-E to return to edit mode.</p><div class="content"><p>Please wait...</p></div></div>'); | ||
|
||
jQuery.ajax({ | ||
type: 'POST', | ||
data: form.serialize().replace(/&*_method=\w+&*/, ''), | ||
url: dest, | ||
error: function() { | ||
$('#preview .content').html('<p>Failed to generate preview. Toggle back to edit mode and check that all required fields are filled in and valid.</p>'); | ||
}, | ||
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' | ||
}); | ||
} | ||
}); |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters