Permalink
Browse files

Removed external library. Added support for Themes and Plugin editors…

…. Updated readme files.
  • Loading branch information...
1 parent c1ba81c commit 177a6dd47f99c2e1dea9155de92704de48e18a4b @zupolgec committed Nov 4, 2011
Showing with 65 additions and 38 deletions.
  1. +18 −6 README.md
  2. +0 −9 jwerty.min.js
  3. +21 −7 readme.txt
  4. +26 −16 save_with_keyboard.php
View
@@ -1,21 +1,23 @@
# Save with keyboard
-This plugin lets you save your posts and pages in the most natural way: pressing Ctrl+s (or Cmd+s on Mac).
-
## Description
-I've coded this plugin because I was tired of pressing Cmd+s and then realize Chrome was trying to save the whole webpage :S
+This plugin lets you save your posts, pages, theme and plugin files in the most natural way: pressing Ctrl+S (or Cmd+S on Mac).
+
+I've coded this plugin because I was tired of pressing Cmd+S and then realize Chrome was trying to save the whole webpage :S
After coding this up, I've found in the plugin directory two plugins that did the same thing, but each one had some flaws
that convinced me to publish mine.
-My plugin loads the awesome [Jwerty library](http://keithcirkel.co.uk/jwerty/) only on post.php and post-new.php, reducing the
-page load on the other admin pages.
+This plugin loads only a few lines of javascript in the footer of the pages where it is needed.
+
It is also *so* smart that saves as draft unpublished posts/pages and updates the ones that are already public.
+Also adds a little tooltip on the buttons that can be "clicked" with Ctrl+S or Cmd+S.
+
## Installation
-1. Upload `save-with-keyboard.php` and `jwerty.min.js` to the `/wp-content/plugins/save-with-keyboard` directory
+1. Upload `save-with-keyboard.php` to the `/wp-content/plugins/` directory
2. Activate the plugin through the 'Plugins' menu in WordPress
## Frequently Asked Questions
@@ -24,11 +26,21 @@ It is also *so* smart that saves as draft unpublished posts/pages and updates th
You can bet it is.
+### Where the shortcut is enabled?
+
+In New Page and New Post pages (saving as draft), in Page and Post edit pages (updating published page/post) and in Themes and Plugins editor pages.
+
## Screenshots
Nothing to show you. It works behind the scenes.
## Changelog
+### 1.1
+Worked pretty well, but now it's awesome:
+- removed dependency from external libraries (except for jQuery which is anyway loaded by WP backend)
+- enabled shortcut in Themes and Plugins editor
+- added tooltip on shortcut-enabled buttons
+
### 1.0
First version. Should work already pretty well.
View

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.
View
@@ -1,26 +1,30 @@
=== Plugin Name ===
Contributors: zupolgec
-Tags: save, keyboard, shortcut, ctrl-s, cmd-s, ctrl+s, cmd+s
+Tags: save, update, publish, keyboard, shortcut, ctrl-s, cmd-s, ctrl+s, cmd+s, ctrl, cmd
Requires at least: 2.6
Tested up to: 3.2.1
-Stable tag: trunk
+Stable tag: 1.1
-This plugin lets you save your posts and pages in the most natural way: pressing Ctrl+s (or Cmd+s on Mac).
+This plugin lets you save your posts, pages, theme and plugin files in the most natural way: pressing Ctrl+S (or Cmd+S on Mac).
== Description ==
-I've coded this plugin because I was tired of pressing Cmd+s and then realize Chrome was trying to save the whole webpage :S
+This plugin lets you save your posts, pages, theme and plugin files in the most natural way: pressing Ctrl+S (or Cmd+S on Mac).
+
+I've coded this plugin because I was tired of pressing Cmd+S and then realize Chrome was trying to save the whole webpage :S
After coding this up, I've found in the plugin directory two plugins that did the same thing, but each one had some flaws
that convinced me to publish mine.
-My plugin loads the awesome [Jwerty library](http://keithcirkel.co.uk/jwerty/) only on post.php and post-new.php, reducing the
-page load on the other admin pages.
+This plugin loads only a few lines of javascript in the footer of the pages where it is needed.
+
It is also *so* smart that saves as draft unpublished posts/pages and updates the ones that are already public.
+Also adds a little tooltip on the buttons that can be "clicked" with Ctrl+S or Cmd+S.
+
== Installation ==
-1. Upload `save-with-keyboard.php` and `jwerty.min.js` to the `/wp-content/plugins/save-with-keyboard` directory
+1. Upload `save-with-keyboard.php` to the `/wp-content/plugins/` directory
2. Activate the plugin through the 'Plugins' menu in WordPress
== Frequently Asked Questions ==
@@ -29,11 +33,21 @@ It is also *so* smart that saves as draft unpublished posts/pages and updates th
You can bet it is.
+= Where the shortcut is enabled? =
+
+In New Page and New Post pages (saving as draft), in Page and Post edit pages (updating published page/post) and in Themes and Plugins editor pages.
+
== Screenshots ==
Nothing to show you. It works behind the scenes.
== Changelog ==
+= 1.1 =
+Worked pretty well, but now it's awesome:
+- removed dependency from external libraries (except for jQuery which is anyway loaded by WP backend)
+- enabled shortcut in Themes and Plugins editor
+- added tooltip on shortcut-enabled buttons
+
= 1.0 =
First version. Should work already pretty well.
View
@@ -2,31 +2,41 @@
/*
Plugin Name: Save with keyboard
Plugin URI: http://wordpress.org/extend/plugins/save-with-keyboard
-Description: This plugin lets you save your posts and pages in the most natural way: pressing Ctrl+s (or Cmd+s on Mac).
+Description: This plugin lets you save your posts, pages, theme and plugin files in the most natural way: pressing Ctrl+S (or Cmd+S on Mac).
Author: Mattia Trapani (zupolgec)
+Author URI: http://mtrapani.com
Version: 1.0
License: WTFPL (http://sam.zoy.org/wtfpl)
-Twitter: @zupolgec
*/
-/*
- * Detects Ctrl+s and Cmd+s then saves the page/post (as draft if unpublished).
- */
-
-function swk_enqueue_script($hook) {
- if( ! in_array($hook, array('post.php', 'post-new.php')) )
- return false;
+if( is_admin() ) {
+ // array of admin pages and buttons to "click" with Ctrl+S in those pages
+ $button_to_click = array(
+ 'post.php' => 'publish',
+ 'post-new.php' => 'save-post',
+ 'theme-editor.php' => 'submit',
+ 'plugin-editor.php' => 'submit'
+ );
- wp_enqueue_script( 'jwerty', plugins_url('/jwerty.min.js', __FILE__) );
- add_action( 'admin_head', 'swk_add_script' );
+ foreach($button_to_click as $page => $button_id) {
+ add_action( 'admin_footer-'.$page, 'swk_add_script' );
+ }
}
-add_action( 'admin_enqueue_scripts', 'swk_enqueue_script' );
-function swk_add_script() { ?>
+function swk_add_script() {
+ global $pagenow, $button_to_click;
+ ?>
<script>
- jwerty.key('ctrl+s/cmd+s', function() {
- ( jQuery('#save-post').length != 0 ) ? jQuery('#save-post').click() : jQuery('#publish').click();
- return false;
+ var button_id = "<?php echo $button_to_click[$pagenow]; ?>";
+
+ jQuery('#'+button_id).attr('title', 'Ctrl+S or Cmd+S to click');
+
+ jQuery(document).keydown( function(e) {
+ if( (e.keyCode || e.which) == 83 && (e.ctrlKey || e.metaKey) ) {
+ jQuery('#'+button_id).click();
+
+ return false;
+ }
});
</script>
<?php

0 comments on commit 177a6dd

Please sign in to comment.