Slug edit for pages. Hide advanced slug field if JS enabled. Trigger first autosave after 15 chars. Set autosave interval to 60s. Props filosofo. see #5749

git-svn-id: http://svn.automattic.com/wordpress/trunk@6955 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
ryan 2008-02-21 20:19:34 +00:00
parent f5afc1fd4f
commit ed09992863
8 changed files with 31 additions and 10 deletions

View File

@ -85,8 +85,8 @@ endif; ?>
<?php the_editor($post->post_content); ?>
<?php wp_nonce_field( 'autosave', 'autosavenonce', false ); ?>
<?php wp_nonce_field( 'closedpostboxes', 'closedpostboxesnonce', false ); ?>
<?php wp_nonce_field( 'samplepermalink', 'samplepermalinknonce', false ); ?>
<?php wp_nonce_field( 'getpermalink', 'getpermalinknonce', false ); ?>
<?php wp_nonce_field( 'samplepermalink', 'samplepermalinknonce', false ); ?>
</div>
<?php echo $form_pingback ?>

View File

@ -51,6 +51,12 @@ addLoadEvent(focusit);
<h3><?php _e('Title') ?></h3>
<div class="inside">
<input type="text" name="post_title" size="30" tabindex="1" value="<?php echo attribute_escape( $post->post_title ); ?>" id="title" />
<?php $sample_permalink_html = get_sample_permalink_html($post->ID); ?>
<div id="edit-slug-box">
<?php if ( ! empty($post->ID) && ! empty($sample_permalink_html) ) :
echo $sample_permalink_html;
endif; ?>
</div>
</div>
</div>
@ -60,6 +66,7 @@ addLoadEvent(focusit);
<?php wp_nonce_field( 'autosave', 'autosavenonce', false ); ?>
<?php wp_nonce_field( 'closedpostboxes', 'closedpostboxesnonce', false ); ?>
<?php wp_nonce_field( 'getpermalink', 'getpermalinknonce', false ); ?>
<?php wp_nonce_field( 'samplepermalink', 'samplepermalinknonce', false ); ?>
</div>
<div class="submitbox" id="submitpage">

View File

@ -593,7 +593,7 @@ function get_sample_permalink($id, $name = null) {
function get_sample_permalink_html($id, $new_slug=null) {
$post = &get_post($id);
list($permalink, $post_name) = get_sample_permalink($post->ID, $new_slug);
if (false === strpos($permalink, '%postname%')) {
if (false === strpos($permalink, '%postname%') && false === strpos($permalink, '%pagename%')) {
return '';
}
$title = __('Click to edit this part of the permalink');
@ -603,7 +603,7 @@ function get_sample_permalink_html($id, $new_slug=null) {
$post_name_abridged = $post_name;
}
$post_name_html = '<span id="editable-post-name" title="'.$title.'">'.$post_name_abridged.'</span><span id="editable-post-name-full">'.$post_name.'</span>';
$display_link = str_replace('%postname%', $post_name_html, $permalink);
$display_link = str_replace(array('%pagename%','%postname%'), $post_name_html, $permalink);
$return = '<strong>' . __('Permalink:') . "</strong>\n" . '<span id="sample-permalink">' . $display_link . "</span>\n";
$return .= '<span id="edit-slug-buttons"><a href="#post_name" class="edit-slug" onclick="edit_permalink(' . $id . '); return false;">' . __('Edit') . "</a></span>\n";
return $return;

View File

@ -2,6 +2,9 @@ addLoadEvent( function() {
add_postbox_toggles('page');
make_slugedit_clickable();
// hide advanced slug field
jQuery('#pageslugdiv').hide();
jQuery('#timestamp').css('display', 'none');
jQuery('.edit-timestamp').click(function () {
if (jQuery('#timestamp').is(":hidden")) {

View File

@ -68,6 +68,9 @@ addLoadEvent( function() {
// Editable slugs
make_slugedit_clickable();
// hide advanced slug field
jQuery('#slugdiv').hide();
jQuery('#tags-input').hide();
tag_update_quickclicks();

View File

@ -12,6 +12,12 @@ function autosave_start_timer() {
jQuery("#post #submit").click(function() { jQuery.cancel(autosavePeriodical); });
jQuery("#post #publish").click(function() { jQuery.cancel(autosavePeriodical); });
jQuery("#post #deletepost").click(function() { jQuery.cancel(autosavePeriodical); });
// Autosave early on for a new post
jQuery("#content").keypress(function() {
if ( 1 === ( jQuery(this).val().length % 15 ) && 1 > parseInt(jQuery("#post_ID").val(),10) )
setTimeout(autosave, 5000);
});
}
addLoadEvent(autosave_start_timer)
@ -132,6 +138,8 @@ function autosave() {
}
post_data["content"] = jQuery("#content").val();
if ( jQuery('#post_name').val() )
post_data["post_name"] = jQuery('#post_name').val();
if(post_data["post_title"].length==0 || post_data["content"].length==0 || post_data["post_title"] + post_data["content"] == autosaveLast) {
return;

View File

@ -63,7 +63,7 @@ function get_permalink($id = 0, $leavename=false) {
if ( empty($post->ID) ) return FALSE;
if ( $post->post_type == 'page' )
return get_page_link($post->ID);
return get_page_link($post->ID, $leavename);
elseif ($post->post_type == 'attachment')
return get_attachment_link($post->ID);
@ -118,7 +118,7 @@ function post_permalink($post_id = 0, $deprecated = '') {
}
// Respects page_on_front. Use this one.
function get_page_link($id = false) {
function get_page_link($id = false, $leavename = false) {
global $post;
$id = (int) $id;
@ -128,13 +128,13 @@ function get_page_link($id = false) {
if ( 'page' == get_option('show_on_front') && $id == get_option('page_on_front') )
$link = get_option('home');
else
$link = _get_page_link( $id );
$link = _get_page_link( $id , $leavename );
return apply_filters('page_link', $link, $id);
}
// Ignores page_on_front. Internal use only.
function _get_page_link( $id = false ) {
function _get_page_link( $id = false, $leavename = false ) {
global $post, $wp_rewrite;
if ( !$id )
@ -146,7 +146,7 @@ function _get_page_link( $id = false ) {
if ( '' != $pagestruct && isset($post->post_status) && 'draft' != $post->post_status ) {
$link = get_page_uri($id);
$link = str_replace('%pagename%', $link, $pagestruct);
$link = ( $leavename ) ? $pagestruct : str_replace('%pagename%', $link, $pagestruct);
$link = get_option('home') . "/$link";
$link = user_trailingslashit($link, 'page');
} else {

View File

@ -44,7 +44,7 @@ class WP_Scripts {
$this->add( 'autosave', '/wp-includes/js/autosave.js', array('jquery', 'schedule'), '20080221');
$this->localize( 'autosave', 'autosaveL10n', array(
'autosaveInterval' => apply_filters('autosave_interval', '120'),
'autosaveInterval' => apply_filters('autosave_interval', '60'),
'errorText' => __('Error: %response%'),
'failText' => __('Error: Autosave Failed.'),
'previewPageText' => __('Preview this Page'),
@ -148,7 +148,7 @@ class WP_Scripts {
'save' => __('Save'),
'cancel' => __('Cancel'),
) );
$this->add( 'post', '/wp-admin/js/post.js', array('suggest', 'jquery-ui-tabs', 'wp-lists', 'postbox', 'slug'), '20080128' );
$this->add( 'post', '/wp-admin/js/post.js', array('suggest', 'jquery-ui-tabs', 'wp-lists', 'postbox', 'slug'), '20080221' );
$this->localize( 'post', 'postL10n', array(
'tagsUsed' => __('Tags used on this post:'),
'add' => attribute_escape(__('Add')),