2008-02-08 14:57:50 -05:00
|
|
|
function edit_permalink(post_id) {
|
|
|
|
var i, c = 0;
|
|
|
|
var e = jQuery('#editable-post-name');
|
2008-03-02 15:17:30 -05:00
|
|
|
var revert_e = e.html();
|
2008-02-08 14:57:50 -05:00
|
|
|
var real_slug = jQuery('#post_name');
|
2008-02-11 18:19:09 -05:00
|
|
|
var revert_slug = real_slug.html();
|
2008-02-08 14:57:50 -05:00
|
|
|
var b = jQuery('#edit-slug-buttons');
|
|
|
|
var revert_b = b.html();
|
2008-02-11 18:19:09 -05:00
|
|
|
var full = jQuery('#editable-post-name-full').html();
|
2008-02-08 14:57:50 -05:00
|
|
|
|
2008-11-11 04:39:42 -05:00
|
|
|
b.html('<a href="" class="save button">'+slugL10n.save+'</a> <a class="cancel" href="">'+slugL10n.cancel+'</a>');
|
2008-02-08 14:57:50 -05:00
|
|
|
b.children('.save').click(function() {
|
2008-03-03 16:02:53 -05:00
|
|
|
var new_slug = e.children('input').val();
|
2008-02-08 14:57:50 -05:00
|
|
|
jQuery.post(slugL10n.requestFile, {
|
|
|
|
action: 'sample-permalink',
|
|
|
|
post_id: post_id,
|
|
|
|
new_slug: new_slug,
|
2008-03-03 16:02:53 -05:00
|
|
|
new_title: jQuery('#title').val(),
|
2008-02-11 12:40:16 -05:00
|
|
|
samplepermalinknonce: jQuery('#samplepermalinknonce').val()}, function(data) {
|
2008-02-21 12:08:06 -05:00
|
|
|
jQuery('#edit-slug-box').html(data);
|
2008-02-08 14:57:50 -05:00
|
|
|
b.html(revert_b);
|
2008-03-02 15:17:30 -05:00
|
|
|
real_slug.attr('value', new_slug);
|
2008-02-08 14:57:50 -05:00
|
|
|
make_slugedit_clickable();
|
|
|
|
});
|
|
|
|
return false;
|
|
|
|
});
|
|
|
|
jQuery('#edit-slug-buttons .cancel').click(function() {
|
|
|
|
e.html(revert_e);
|
|
|
|
b.html(revert_b);
|
2008-02-11 18:19:09 -05:00
|
|
|
real_slug.attr('value', revert_slug);
|
2008-02-08 14:57:50 -05:00
|
|
|
return false;
|
|
|
|
});
|
2008-02-11 18:19:09 -05:00
|
|
|
for(i=0; i < full.length; ++i) {
|
|
|
|
if ('%' == full.charAt(i)) c++;
|
2008-02-08 14:57:50 -05:00
|
|
|
}
|
2008-02-11 18:19:09 -05:00
|
|
|
slug_value = (c > full.length/4)? '' : full;
|
2008-02-08 14:57:50 -05:00
|
|
|
e.html('<input type="text" id="new-post-slug" value="'+slug_value+'" />').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()});
|
|
|
|
}
|
|
|
|
|