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