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