1 function edit_permalink(post_id) {
3 var e = jQuery('#editable-post-name');
4 var revert_e = e.html();
5 var real_slug = jQuery('#post_name');
6 var revert_slug = real_slug.html();
7 var b = jQuery('#edit-slug-buttons');
8 var revert_b = b.html();
9 var full = jQuery('#editable-post-name-full').html();
11 b.html('<a href="" class="save">'+slugL10n.save+'</a> <a class="cancel" href="">'+slugL10n.cancel+'</a>');
12 b.children('.save').click(function() {
13 var new_slug = e.children('input').val();
14 jQuery.post(slugL10n.requestFile, {
15 action: 'sample-permalink',
18 new_title: jQuery('#title').val(),
19 samplepermalinknonce: jQuery('#samplepermalinknonce').val()}, function(data) {
20 jQuery('#edit-slug-box').html(data);
22 real_slug.attr('value', new_slug);
23 make_slugedit_clickable();
27 jQuery('#edit-slug-buttons .cancel').click(function() {
30 real_slug.attr('value', revert_slug);
33 for(i=0; i < full.length; ++i) {
34 if ('%' == full.charAt(i)) c++;
36 slug_value = (c > full.length/4)? '' : full;
37 e.html('<input type="text" id="new-post-slug" value="'+slug_value+'" />').children('input').keypress(function(e){
38 var key = e.charCode ? e.charCode : e.keyCode ? e.keyCode : 0;
39 // on enter, just save the new slug, don't save the post
40 if (13 == key) {b.children('.save').click();return false;}
41 if (27 == key) {b.children('.cancel').click();return false;}
42 real_slug.attr('value', this.value)}).focus();
45 function make_slugedit_clickable() {
46 jQuery('#editable-post-name').click(function() {jQuery('#edit-slug-buttons').children('.edit-slug').click()});