From 4c6d9571f9f239d8155c72876952e1735b87b6b5 Mon Sep 17 00:00:00 2001 From: Ryan Boren Date: Fri, 8 Feb 2008 19:57:50 +0000 Subject: [PATCH] Postbox save updates and admin js refactoring from nbachiyski. fixes #5799 git-svn-id: https://develop.svn.wordpress.org/trunk@6761 602fd350-edb4-49c9-b593-d223f7449a82 --- wp-admin/admin-ajax.php | 11 +++++--- wp-admin/edit-form-advanced.php | 21 ++++++++------- wp-admin/edit-link-form.php | 11 ++++---- wp-admin/edit-page-form.php | 17 ++++++------ wp-admin/includes/post.php | 4 +-- wp-admin/js/link.js | 4 +-- wp-admin/js/page.js | 6 +++++ wp-admin/js/post.js | 48 +-------------------------------- wp-admin/js/postbox.js | 12 +++++---- wp-admin/js/slug.js | 46 +++++++++++++++++++++++++++++++ wp-admin/page-new.php | 2 +- wp-admin/page.php | 2 +- wp-includes/script-loader.php | 12 ++++++--- 13 files changed, 108 insertions(+), 88 deletions(-) create mode 100644 wp-admin/js/page.js create mode 100644 wp-admin/js/slug.js diff --git a/wp-admin/admin-ajax.php b/wp-admin/admin-ajax.php index 12800d2d89..61979a461c 100644 --- a/wp-admin/admin-ajax.php +++ b/wp-admin/admin-ajax.php @@ -513,11 +513,16 @@ case 'autosave-generate-nonces' : die('0'); break; case 'closed-postboxes' : - check_ajax_referer( $action ); - $closed = explode(',', $_POST['closed']); + check_ajax_referer( 'closedpostboxes', 'closedpostboxesnonce' ); + $closed = isset( $_POST['closed'] )? $_POST['closed'] : ''; + $closed = explode( ',', $_POST['closed'] ); + $page = isset( $_POST['page'] )? $_POST['page'] : ''; + if ( !preg_match( '/^[a-z-]+$/', $page ) ) { + die(-1); + } if (!is_array($closed)) break; $current_user = wp_get_current_user(); - update_usermeta($current_user->ID, 'closedpostboxes', $closed); + update_usermeta($current_user->ID, 'closedpostboxes_'.$page, $closed); break; case 'sample-permalink': check_ajax_referer( $action ); diff --git a/wp-admin/edit-form-advanced.php b/wp-admin/edit-form-advanced.php index 5aca0a960b..6994be4260 100644 --- a/wp-admin/edit-form-advanced.php +++ b/wp-admin/edit-form-advanced.php @@ -89,6 +89,7 @@ addLoadEvent(focusit);

post_content); ?> + @@ -175,7 +176,7 @@ else echo clean_url(stripslashes(wp_get_referer())); ?>" />

-
+

@@ -183,7 +184,7 @@ else
-
+

@@ -234,12 +235,12 @@ if (current_user_can('upload_files') && false) {

-
+

-
+

() @@ -250,7 +251,7 @@ if ( ! empty($pings) )
-
+

@@ -271,7 +272,7 @@ list_meta($metadata); -
+

@@ -282,14 +283,14 @@ list_meta($metadata);
-
+

-
+

@@ -297,7 +298,7 @@ list_meta($metadata);
-
+

@@ -309,7 +310,7 @@ if ( $post->post_author && !in_array($post->post_author, $authors) ) $authors[] = $post->post_author; if ( $authors && count( $authors ) > 1 ) : ?> -
+

$authors, 'name' => 'post_author_override', 'selected' => empty($post_ID) ? $user_ID : $post->post_author) ); ?> diff --git a/wp-admin/edit-link-form.php b/wp-admin/edit-link-form.php index 39bb566035..844144b933 100644 --- a/wp-admin/edit-link-form.php +++ b/wp-admin/edit-link-form.php @@ -32,6 +32,7 @@ function xfn_check($class, $value = '', $deprecated = '') { +
@@ -64,7 +65,7 @@ function xfn_check($class, $value = '', $deprecated = '') {

-
+

@@ -100,7 +101,7 @@ function xfn_check($class, $value = '', $deprecated = '') {

-
+

-
+

-
+

@@ -240,7 +241,7 @@ function xfn_check($class, $value = '', $deprecated = '') { -
+

diff --git a/wp-admin/edit-page-form.php b/wp-admin/edit-page-form.php index a41dd0d262..6cde174981 100644 --- a/wp-admin/edit-page-form.php +++ b/wp-admin/edit-page-form.php @@ -57,6 +57,7 @@ addLoadEvent(focusit);

post_content); ?> +
@@ -136,7 +137,7 @@ if ( ('edit' == $action) && current_user_can('delete_page', $post_ID) )

-
+

@@ -155,7 +156,7 @@ list_meta($metadata);
-
+

@@ -166,21 +167,21 @@ list_meta($metadata);
-
+

-
+

-
+

@@ -202,7 +203,7 @@ list_meta($metadata);
-
+

@@ -215,7 +216,7 @@ if ( $post->post_author && !in_array($post->post_author, $authors) ) $authors[] = $post->post_author; if ( $authors && count( $authors ) > 1 ) : ?> -
+

$authors, 'name' => 'post_author_override', 'selected' => empty($post_ID) ? $user_ID : $post->post_author) ); ?> diff --git a/wp-admin/includes/post.php b/wp-admin/includes/post.php index 13e4ee5207..ec9a831432 100644 --- a/wp-admin/includes/post.php +++ b/wp-admin/includes/post.php @@ -517,9 +517,9 @@ function wp_edit_posts_query( $q = false ) { return array($post_stati, $avail_post_stati); } -function postbox_classes( $id ) { +function postbox_classes( $id, $page ) { $current_user = wp_get_current_user(); - if ( $closed = get_usermeta( $current_user->ID, 'closedpostboxes' ) ) { + if ( $closed = get_usermeta( $current_user->ID, 'closedpostboxes_'.$page ) ) { if ( !is_array( $closed ) ) return ''; return in_array( $id, $closed )? 'closed' : ''; } else { diff --git a/wp-admin/js/link.js b/wp-admin/js/link.js index ec6d1d1776..40c7fb9572 100644 --- a/wp-admin/js/link.js +++ b/wp-admin/js/link.js @@ -1,6 +1,6 @@ addLoadEvent( function() { // postboxes - add_postbox_toggles(); + add_postbox_toggles('link'); // category tabs var categoryTabs = jQuery('#category-tabs').tabs(); @@ -43,4 +43,4 @@ addLoadEvent( function() { return false; } ); jQuery('.categorychecklist :checkbox').change( syncChecks ).filter( ':checked' ).change(); -}); \ No newline at end of file +}); diff --git a/wp-admin/js/page.js b/wp-admin/js/page.js new file mode 100644 index 0000000000..7a294488e0 --- /dev/null +++ b/wp-admin/js/page.js @@ -0,0 +1,6 @@ +addLoadEvent( function() { + add_postbox_toggles('page'); + make_slugedit_clickable(); +}); + + diff --git a/wp-admin/js/post.js b/wp-admin/js/post.js index c40ad1730b..81d4ff221f 100644 --- a/wp-admin/js/post.js +++ b/wp-admin/js/post.js @@ -52,55 +52,9 @@ function tag_press_key( e ) { } } -function edit_permalink(post_id) { - var i, c = 0; - var e = jQuery('#editable-post-name'); - var revert_e = e.html(); - var real_slug = jQuery('#post_name'); - var b = jQuery('#edit-slug-buttons'); - var revert_b = b.html(); - var old_slug = e.children('span').html(); - - b.html(''+postL10n.save+' '+postL10n.cancel+''); - b.children('.save').click(function() { - var new_slug = e.children('input').attr('value'); - jQuery.post(postL10n.requestFile, { - action: 'sample-permalink', - post_id: post_id, - new_slug: new_slug, - cookie: document.cookie}, function(data) { - jQuery('#sample-permalink').html(data); - b.html(revert_b); - real_slug.attr('value', new_slug); - make_slugedit_clickable(); - }); - return false; - }); - jQuery('#edit-slug-buttons .cancel').click(function() { - e.html(revert_e); - b.html(revert_b); - real_slug.attr('value', revert_e); - return false; - }); - for(i=0; i < revert_e.length; ++i) { - if ('%' == revert_e.charAt(i)) c++; - } - slug_value = (c > revert_e.length/4)? '' : revert_e; - e.html('').children('input').keypress(function(e){ - var key = e.charCode ? e.charCode : e.keyCode ? e.keyCode : 0; - // on enter, just save the new slug, don't save the post - if (13 == key) {b.children('.save').click();return false;} - if (27 == key) {b.children('.cancel').click();return false;} - real_slug.attr('value', this.value)}).focus(); -} - -function make_slugedit_clickable() { - jQuery('#editable-post-name').click(function() {jQuery('#edit-slug-buttons').children('.edit-slug').click()}); -} - addLoadEvent( function() { // postboxes - add_postbox_toggles(); + add_postbox_toggles('post'); // If no tags on the page, skip the tag and category stuff. if ( !jQuery('#tags-input').size() ) { diff --git a/wp-admin/js/postbox.js b/wp-admin/js/postbox.js index 7b05458db7..22ac62dfee 100644 --- a/wp-admin/js/postbox.js +++ b/wp-admin/js/postbox.js @@ -1,12 +1,14 @@ -function add_postbox_toggles() { +function add_postbox_toggles(page) { jQuery('.postbox h3').prepend('+ '); - jQuery('.togbox').click( function() { jQuery(jQuery(this).parent().parent().get(0)).toggleClass('closed'); save_postboxes_state(); } ); + jQuery('.togbox').click( function() { jQuery(jQuery(this).parent().parent().get(0)).toggleClass('closed'); save_postboxes_state(page); } ); } -function save_postboxes_state() { +function save_postboxes_state(page) { var closed = jQuery('.postbox').filter('.closed').map(function() { return this.id; }).get().join(','); jQuery.post(postboxL10n.requestFile, { action: 'closed-postboxes', closed: closed, - cookie: document.cookie}); -} \ No newline at end of file + closedpostboxesnonce: jQuery('#closedpostboxesnonce').val(), + page: page + }); +} diff --git a/wp-admin/js/slug.js b/wp-admin/js/slug.js new file mode 100644 index 0000000000..a0a81af0f4 --- /dev/null +++ b/wp-admin/js/slug.js @@ -0,0 +1,46 @@ +function edit_permalink(post_id) { + var i, c = 0; + var e = jQuery('#editable-post-name'); + var revert_e = e.html(); + var real_slug = jQuery('#post_name'); + var b = jQuery('#edit-slug-buttons'); + var revert_b = b.html(); + var old_slug = e.children('span').html(); + + b.html(''+slugL10n.save+' '+slugL10n.cancel+''); + b.children('.save').click(function() { + var new_slug = e.children('input').attr('value'); + jQuery.post(slugL10n.requestFile, { + action: 'sample-permalink', + post_id: post_id, + new_slug: new_slug, + cookie: document.cookie}, function(data) { + jQuery('#sample-permalink').html(data); + b.html(revert_b); + real_slug.attr('value', new_slug); + make_slugedit_clickable(); + }); + return false; + }); + jQuery('#edit-slug-buttons .cancel').click(function() { + e.html(revert_e); + b.html(revert_b); + real_slug.attr('value', revert_e); + return false; + }); + for(i=0; i < revert_e.length; ++i) { + if ('%' == revert_e.charAt(i)) c++; + } + slug_value = (c > revert_e.length/4)? '' : revert_e; + e.html('').children('input').keypress(function(e){ + var key = e.charCode ? e.charCode : e.keyCode ? e.keyCode : 0; + // on enter, just save the new slug, don't save the post + if (13 == key) {b.children('.save').click();return false;} + if (27 == key) {b.children('.cancel').click();return false;} + real_slug.attr('value', this.value)}).focus(); +} + +function make_slugedit_clickable() { + jQuery('#editable-post-name').click(function() {jQuery('#edit-slug-buttons').children('.edit-slug').click()}); +} + diff --git a/wp-admin/page-new.php b/wp-admin/page-new.php index e181cdc152..cb14c5a6bc 100644 --- a/wp-admin/page-new.php +++ b/wp-admin/page-new.php @@ -4,7 +4,7 @@ $title = __('New Page'); $parent_file = 'post-new.php'; $editing = true; wp_enqueue_script('autosave'); -wp_enqueue_script('post'); +wp_enqueue_script('page'); wp_enqueue_script('thickbox'); wp_enqueue_script('media-upload'); diff --git a/wp-admin/page.php b/wp-admin/page.php index 8f2d9820ad..0cd6979708 100644 --- a/wp-admin/page.php +++ b/wp-admin/page.php @@ -52,7 +52,7 @@ case 'edit': exit(); } - wp_enqueue_script('post'); + wp_enqueue_script('page'); wp_enqueue_script('thickbox'); wp_enqueue_script('media-upload'); diff --git a/wp-includes/script-loader.php b/wp-includes/script-loader.php index 0ad8e25110..b226059159 100644 --- a/wp-includes/script-loader.php +++ b/wp-includes/script-loader.php @@ -135,16 +135,20 @@ class WP_Scripts { $this->localize( 'postbox', 'postboxL10n', array( 'requestFile' => get_option( 'siteurl' ) . '/wp-admin/admin-ajax.php', ) ); - $this->add( 'post', '/wp-admin/js/post.js', array('suggest', 'jquery-ui-tabs', 'wp-lists', 'postbox'), '20080128' ); + $this->add( 'slug', '/wp-admin/js/slug.js', array('jquery'), '20080208' ); + $this->localize( 'slug', 'slugL10n', array( + 'requestFile' => get_option( 'siteurl' ) . '/wp-admin/admin-ajax.php', + 'save' => __('Save'), + 'cancel' => __('Cancel'), + ) ); + $this->add( 'post', '/wp-admin/js/post.js', array('suggest', 'jquery-ui-tabs', 'wp-lists', 'postbox', 'slug'), '20080128' ); $this->localize( 'post', 'postL10n', array( 'tagsUsed' => __('Tags used on this post:'), 'add' => attribute_escape(__('Add')), 'addTag' => attribute_escape(__('Add new tag')), 'separate' => __('Separate tags with commas'), - 'save' => __('Save'), - 'cancel' => __('Cancel'), - 'requestFile' => get_option( 'siteurl' ) . '/wp-admin/admin-ajax.php', ) ); + $this->add( 'page', '/wp-admin/js/page.js', array('jquery', 'slug', 'postbox'), '20080208' ); $this->add( 'link', '/wp-admin/js/link.js', array('jquery-ui-tabs', 'wp-lists', 'postbox'), '20080131' ); $this->add( 'media-upload', '/wp-admin/js/media-upload.js', false, '20080109' ); $this->localize( 'upload', 'uploadL10n', array(