Fix permalink editor for pages, hide "View Post" button while editing permalink, fixes #9040

git-svn-id: http://svn.automattic.com/wordpress/trunk@10525 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
azaozz 2009-02-08 13:38:02 +00:00
parent dad4caa7e5
commit ccd5cea290
5 changed files with 20 additions and 15 deletions

View File

@ -943,16 +943,13 @@ function get_sample_permalink($id, $title=null, $name = null) {
* @param unknown_type $new_slug
* @return unknown
*/
function get_sample_permalink_html($id, $new_title=null, $new_slug=null) {
function get_sample_permalink_html( $id, $new_title = null, $new_slug = null ) {
$post = &get_post($id);
list($permalink, $post_name) = get_sample_permalink($post->ID, $new_title, $new_slug);
if ( 'publish' == $post->post_status )
$view_post = 'post' == $post->post_type ? __('View Post') : __('View Page');
if ( false === strpos($permalink, '%postname%') && false === strpos($permalink, '%pagename%') ) {
if ( 'page' == $post->post_type )
return '';
$return = '<strong>' . __('Permalink:') . "</strong>\n" . '<span id="sample-permalink">' . $permalink . "</span>\n";
$return .= '<span id="change-permalinks"><a href="options-permalink.php" class="button" target="_blank">' . __('Change Permalinks') . "</a></span>\n";
if ( isset($view_post) )

View File

@ -1,7 +1,8 @@
function edit_permalink(post_id) {
var i, c = 0, e = jQuery('#editable-post-name'), revert_e = e.html(), real_slug = jQuery('#post_name'), revert_slug = real_slug.html(), b = jQuery('#edit-slug-buttons'), revert_b = b.html(), full = jQuery('#editable-post-name-full').html();
b.html('<a href="" class="save button">'+slugL10n.save+'</a> <a class="cancel" href="">'+slugL10n.cancel+'</a>');
jQuery('#view-post-btn').hide();
b.html('<a href="#" class="save button">'+slugL10n.save+'</a> <a class="cancel" href="#">'+slugL10n.cancel+'</a>');
b.children('.save').click(function() {
var new_slug = e.children('input').val();
jQuery.post(slugL10n.requestFile, {
@ -14,10 +15,12 @@ function edit_permalink(post_id) {
b.html(revert_b);
real_slug.attr('value', new_slug);
make_slugedit_clickable();
jQuery('#view-post-btn').show();
});
return false;
});
jQuery('#edit-slug-buttons .cancel').click(function() {
jQuery('#view-post-btn').show();
e.html(revert_e);
b.html(revert_b);
real_slug.attr('value', revert_slug);

View File

@ -1 +1 @@
function edit_permalink(a){var d,h=0,g=jQuery("#editable-post-name"),j=g.html(),m=jQuery("#post_name"),n=m.html(),k=jQuery("#edit-slug-buttons"),l=k.html(),f=jQuery("#editable-post-name-full").html();k.html('<a href="" class="save button">'+slugL10n.save+'</a> <a class="cancel" href="">'+slugL10n.cancel+"</a>");k.children(".save").click(function(){var b=g.children("input").val();jQuery.post(slugL10n.requestFile,{action:"sample-permalink",post_id:a,new_slug:b,new_title:jQuery("#title").val(),samplepermalinknonce:jQuery("#samplepermalinknonce").val()},function(c){jQuery("#edit-slug-box").html(c);k.html(l);m.attr("value",b);make_slugedit_clickable()});return false});jQuery("#edit-slug-buttons .cancel").click(function(){g.html(j);k.html(l);m.attr("value",n);return false});for(d=0;d<f.length;++d){if("%"==f.charAt(d)){h++}}slug_value=(h>f.length/4)?"":f;g.html('<input type="text" id="new-post-slug" value="'+slug_value+'" />').children("input").keypress(function(c){var b=c.charCode?c.charCode:c.keyCode?c.keyCode:0;if(13==b){k.children(".save").click();return false}if(27==b){k.children(".cancel").click();return false}m.attr("value",this.value)}).focus()}function make_slugedit_clickable(){jQuery("#editable-post-name").click(function(){jQuery("#edit-slug-buttons").children(".edit-slug").click()})};
function edit_permalink(a){var d,h=0,g=jQuery("#editable-post-name"),j=g.html(),m=jQuery("#post_name"),n=m.html(),k=jQuery("#edit-slug-buttons"),l=k.html(),f=jQuery("#editable-post-name-full").html();jQuery("#view-post-btn").hide();k.html('<a href="#" class="save button">'+slugL10n.save+'</a> <a class="cancel" href="#">'+slugL10n.cancel+"</a>");k.children(".save").click(function(){var b=g.children("input").val();jQuery.post(slugL10n.requestFile,{action:"sample-permalink",post_id:a,new_slug:b,new_title:jQuery("#title").val(),samplepermalinknonce:jQuery("#samplepermalinknonce").val()},function(c){jQuery("#edit-slug-box").html(c);k.html(l);m.attr("value",b);make_slugedit_clickable();jQuery("#view-post-btn").show()});return false});jQuery("#edit-slug-buttons .cancel").click(function(){jQuery("#view-post-btn").show();g.html(j);k.html(l);m.attr("value",n);return false});for(d=0;d<f.length;++d){if("%"==f.charAt(d)){h++}}slug_value=(h>f.length/4)?"":f;g.html('<input type="text" id="new-post-slug" value="'+slug_value+'" />').children("input").keypress(function(c){var b=c.charCode?c.charCode:c.keyCode?c.keyCode:0;if(13==b){k.children(".save").click();return false}if(27==b){k.children(".cancel").click();return false}m.attr("value",this.value)}).focus()}function make_slugedit_clickable(){jQuery("#editable-post-name").click(function(){jQuery("#edit-slug-buttons").children(".edit-slug").click()})};

View File

@ -92,15 +92,18 @@ function get_permalink($id = 0, $leavename = false) {
$leavename? '' : '%pagename%',
);
if ( is_object($id) && isset($id->filter) && 'sample' == $id->filter )
if ( is_object($id) && isset($id->filter) && 'sample' == $id->filter ) {
$post = $id;
else
$sample = true;
} else {
$post = &get_post($id);
$sample = false;
}
if ( empty($post->ID) ) return false;
if ( $post->post_type == 'page' )
return get_page_link($post->ID, $leavename);
return get_page_link($post->ID, $leavename, $sample);
elseif ($post->post_type == 'attachment')
return get_attachment_link($post->ID);
@ -177,10 +180,11 @@ function post_permalink($post_id = 0, $deprecated = '') {
* @since 1.5.0
*
* @param int $id Optional. Post ID.
* @param bool $leavename Optional, defaults to false. Whether to keep post name or page name.
* @param bool $leavename Optional, defaults to false. Whether to keep page name.
* @param bool $sample Optional, defaults to false. Is it a sample permalink.
* @return string
*/
function get_page_link($id = false, $leavename = false) {
function get_page_link( $id = false, $leavename = false, $sample = false ) {
global $post;
$id = (int) $id;
@ -190,7 +194,7 @@ function get_page_link($id = false, $leavename = false) {
if ( 'page' == get_option('show_on_front') && $id == get_option('page_on_front') )
$link = get_option('home');
else
$link = _get_page_link( $id , $leavename );
$link = _get_page_link( $id , $leavename, $sample );
return apply_filters('page_link', $link, $id);
}
@ -205,9 +209,10 @@ function get_page_link($id = false, $leavename = false) {
*
* @param int $id Optional. Post ID.
* @param bool $leavename Optional. Leave name.
* @param bool $sample Optional. Sample permalink.
* @return string
*/
function _get_page_link( $id = false, $leavename = false ) {
function _get_page_link( $id = false, $leavename = false, $sample = false ) {
global $post, $wp_rewrite;
if ( !$id )
@ -217,7 +222,7 @@ function _get_page_link( $id = false, $leavename = false ) {
$pagestruct = $wp_rewrite->get_page_permastruct();
if ( '' != $pagestruct && isset($post->post_status) && 'draft' != $post->post_status ) {
if ( '' != $pagestruct && ( ( isset($post->post_status) && 'draft' != $post->post_status ) || $sample ) ) {
$link = get_page_uri($id);
$link = ( $leavename ) ? $pagestruct : str_replace('%pagename%', $link, $pagestruct);
$link = get_option('home') . "/$link";

View File

@ -240,7 +240,7 @@ function wp_default_scripts( &$scripts ) {
'requestFile' => admin_url('admin-ajax.php')
) );
$scripts->add( 'slug', "/wp-admin/js/slug$suffix.js", array('jquery'), '20090102' );
$scripts->add( 'slug', "/wp-admin/js/slug$suffix.js", array('jquery'), '20090207' );
$scripts->add_data( 'slug', 'group', 1 );
$scripts->localize( 'slug', 'slugL10n', array(
'requestFile' => admin_url('admin-ajax.php'),