home *** CD-ROM | disk | FTP | other *** search
/ Cricao de Sites - 650 Layouts Prontos / WebMasters.iso / Blogs / wordpress2.6.exe / wordpress2.6 / wp-admin / js / slug.js < prev    next >
Encoding:
JavaScript  |  2008-03-04  |  1.7 KB  |  49 lines

  1. function edit_permalink(post_id) {
  2.     var i, c = 0;
  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();
  10.  
  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',
  16.             post_id: post_id,
  17.             new_slug: new_slug,
  18.             new_title: jQuery('#title').val(),
  19.             samplepermalinknonce: jQuery('#samplepermalinknonce').val()}, function(data) {
  20.                 jQuery('#edit-slug-box').html(data);
  21.                 b.html(revert_b);
  22.                 real_slug.attr('value', new_slug);
  23.                 make_slugedit_clickable();
  24.             });
  25.         return false;
  26.     });
  27.     jQuery('#edit-slug-buttons .cancel').click(function() {
  28.         e.html(revert_e);
  29.         b.html(revert_b);
  30.         real_slug.attr('value', revert_slug);
  31.         return false;
  32.     });
  33.     for(i=0; i < full.length; ++i) {
  34.         if ('%' == full.charAt(i)) c++;
  35.     }
  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();
  43. }
  44.  
  45. function make_slugedit_clickable() {
  46.     jQuery('#editable-post-name').click(function() {jQuery('#edit-slug-buttons').children('.edit-slug').click()});
  47. }
  48.  
  49.