home *** CD-ROM | disk | FTP | other *** search
/ Cricao de Sites - 650 Layouts Prontos / WebMasters.iso / Blogs / wordpress2.6.exe / wordpress2.6 / wp-admin / js / post.js < prev    next >
Encoding:
JavaScript  |  2008-06-30  |  6.9 KB  |  190 lines

  1. // this file contains all the scripts used in the post/edit page
  2.  
  3. function new_tag_remove_tag() {
  4.     var id = jQuery( this ).attr( 'id' );
  5.     var num = id.substr( 10 );
  6.     var current_tags = jQuery( '#tags-input' ).val().split(',');
  7.     delete current_tags[num];
  8.     var new_tags = [];
  9.     jQuery.each( current_tags, function( key, val ) {
  10.         if ( val && !val.match(/^\s+$/) && '' != val ) {
  11.             new_tags = new_tags.concat( val );
  12.         }
  13.     });
  14.     jQuery( '#tags-input' ).val( new_tags.join( ',' ).replace( /\s*,+\s*/, ',' ).replace( /,+/, ',' ).replace( /,+\s+,+/, ',' ).replace( /,+\s*$/, '' ).replace( /^\s*,+/, '' ) );
  15.     tag_update_quickclicks();
  16.     jQuery('#newtag').focus();
  17.     return false;
  18. }
  19.  
  20. function tag_update_quickclicks() {
  21.     if ( jQuery( '#tags-input' ).length == 0 )
  22.         return;
  23.     var current_tags = jQuery( '#tags-input' ).val().split(',');
  24.     jQuery( '#tagchecklist' ).empty();
  25.     shown = false;
  26. //    jQuery.merge( current_tags, current_tags ); // this doesn't work anymore, need something to array_unique
  27.     jQuery.each( current_tags, function( key, val ) {
  28.         val = val.replace( /^\s+/, '' ).replace( /\s+$/, '' ); // trim
  29.         if ( !val.match(/^\s+$/) && '' != val ) {
  30.             txt = '<span><a id="tag-check-' + key + '" class="ntdelbutton">X</a> ' + val + '</span> ';
  31.             jQuery( '#tagchecklist' ).append( txt );
  32.             jQuery( '#tag-check-' + key ).click( new_tag_remove_tag );
  33.             shown = true;
  34.         }
  35.     });
  36.     if ( shown )
  37.         jQuery( '#tagchecklist' ).prepend( '<strong>'+postL10n.tagsUsed+'</strong><br />' );
  38. }
  39.  
  40. function tag_flush_to_text() {
  41.     var newtags = jQuery('#tags-input').val() + ',' + jQuery('#newtag').val();
  42.     // massage
  43.     newtags = newtags.replace( /\s+,+\s*/g, ',' ).replace( /,+/g, ',' ).replace( /,+\s+,+/g, ',' ).replace( /,+\s*$/g, '' ).replace( /^\s*,+/g, '' );
  44.     jQuery('#tags-input').val( newtags );
  45.     tag_update_quickclicks();
  46.     jQuery('#newtag').val('');
  47.     jQuery('#newtag').focus();
  48.     return false;
  49. }
  50.  
  51. function tag_save_on_publish() {
  52.     if ( jQuery('#newtag').val() != postL10n.addTag )
  53.         tag_flush_to_text();
  54. }
  55.  
  56. function tag_press_key( e ) {
  57.     if ( 13 == e.keyCode ) {
  58.         tag_flush_to_text();
  59.         return false;
  60.     }
  61. }
  62.  
  63. jQuery(document).ready( function() {
  64.     // close postboxes that should be closed
  65.     jQuery('.if-js-closed').removeClass('if-js-closed').addClass('closed');
  66.  
  67.     // show things that should be visible, hide what should be hidden
  68.     jQuery('.hide-if-no-js').show();
  69.     jQuery('.hide-if-js').hide();
  70.  
  71.     // postboxes
  72.     add_postbox_toggles('post');
  73.  
  74.     // Editable slugs
  75.     make_slugedit_clickable();
  76.  
  77.     // hide advanced slug field
  78.     jQuery('#slugdiv').hide();
  79.  
  80.     jQuery('#tags-input').hide();
  81.     tag_update_quickclicks();
  82.     // add the quickadd form
  83.     jQuery('#jaxtag').prepend('<span id="ajaxtag"><input type="text" name="newtag" id="newtag" class="form-input-tip" size="16" autocomplete="off" value="'+postL10n.addTag+'" /><input type="button" class="button" id="tagadd" value="' + postL10n.add + '" tabindex="3" /><input type="hidden"/><input type="hidden"/><span class="howto">'+postL10n.separate+'</span></span>');
  84.     jQuery('#tagadd').click( tag_flush_to_text );
  85.     jQuery('#newtag').focus(function() {
  86.         if ( this.value == postL10n.addTag )
  87.             jQuery(this).val( '' ).removeClass( 'form-input-tip' );
  88.     });
  89.     jQuery('#newtag').blur(function() {
  90.         if ( this.value == '' )
  91.             jQuery(this).val( postL10n.addTag ).addClass( 'form-input-tip' );
  92.     });
  93.  
  94.     // auto-save tags on post save/publish
  95.     jQuery('#publish').click( tag_save_on_publish );
  96.     jQuery('#save-post').click( tag_save_on_publish );
  97.  
  98.     jQuery('#title').blur( function() { if ( (jQuery("#post_ID").val() > 0) || (jQuery("#title").val().length == 0) ) return; autosave(); } );
  99.  
  100.     // auto-suggest stuff
  101.     jQuery('#newtag').suggest( 'admin-ajax.php?action=ajax-tag-search', { delay: 500, minchars: 2, multiple: true, multipleSep: ", " } );
  102.     jQuery('#newtag').keypress( tag_press_key );
  103.  
  104.     // category tabs
  105.     var categoryTabs =jQuery('#category-tabs').tabs();
  106.  
  107.     // Ajax Cat
  108.     var newCat = jQuery('#newcat').one( 'focus', function() { jQuery(this).val( '' ).removeClass( 'form-input-tip' ) } );
  109.     jQuery('#category-add-sumbit').click( function() { newCat.focus(); } );
  110.     var newCatParent = false;
  111.     var newCatParentOption = false;
  112.     var noSyncChecks = false; // prophylactic. necessary?
  113.     var syncChecks = function() {
  114.         if ( noSyncChecks )
  115.             return;
  116.         noSyncChecks = true;
  117.         var th = jQuery(this);
  118.         var c = th.is(':checked');
  119.         var id = th.val().toString();
  120.         jQuery('#in-category-' + id + ', #in-popular-category-' + id).attr( 'checked', c );
  121.         noSyncChecks = false;
  122.     };
  123.     var popularCats = jQuery('#categorychecklist-pop :checkbox').map( function() { return parseInt(jQuery(this).val(), 10); } ).get().join(',');
  124.     var catAddBefore = function( s ) {
  125.         s.data += '&popular_ids=' + popularCats + '&' + jQuery( '#categorychecklist :checked' ).serialize();
  126.         return s;
  127.     };
  128.     var catAddAfter = function( r, s ) {
  129.         if ( !newCatParent ) newCatParent = jQuery('#newcat_parent');
  130.         if ( !newCatParentOption ) newCatParentOption = newCatParent.find( 'option[value=-1]' );
  131.         jQuery(s.what + ' response_data', r).each( function() {
  132.             var t = jQuery(jQuery(this).text());
  133.             t.find( 'label' ).each( function() {
  134.                 var th = jQuery(this);
  135.                 var val = th.find('input').val();
  136.                 var id = th.find('input')[0].id
  137.                 jQuery('#' + id).change( syncChecks ).change();
  138.                 if ( newCatParent.find( 'option[value=' + val + ']' ).size() )
  139.                     return;
  140.                 var name = jQuery.trim( th.text() );
  141.                 var o = jQuery( '<option value="' +  parseInt( val, 10 ) + '"></option>' ).text( name );
  142.                 newCatParent.prepend( o );
  143.             } );
  144.             newCatParentOption.attr( 'selected', true );
  145.         } );
  146.     };
  147.     jQuery('#categorychecklist').wpList( {
  148.         alt: '',
  149.         response: 'category-ajax-response',
  150.         addBefore: catAddBefore,
  151.         addAfter: catAddAfter
  152.     } );
  153.     jQuery('#category-add-toggle').click( function() {
  154.         jQuery(this).parents('div:first').toggleClass( 'wp-hidden-children' );
  155.         // categoryTabs.tabs( 'select', '#categories-all' ); // this is broken (in the UI beta?)
  156.         categoryTabs.find( 'a[href="#categories-all"]' ).click();
  157.         jQuery('#newcat').focus();
  158.         return false;
  159.     } );
  160.     jQuery('.categorychecklist .popular-category :checkbox').change( syncChecks ).filter( ':checked' ).change();
  161.  
  162.     jQuery('.edit-timestamp').click(function () {
  163.         if (jQuery('#timestampdiv').is(":hidden")) {
  164.             jQuery('#timestampdiv').slideDown("normal");
  165.             jQuery('.edit-timestamp').text(postL10n.cancel);
  166.         } else {
  167.             jQuery('#timestampdiv').hide();
  168.             jQuery('#mm').val(jQuery('#hidden_mm').val());
  169.             jQuery('#jj').val(jQuery('#hidden_jj').val());
  170.             jQuery('#aa').val(jQuery('#hidden_aa').val());
  171.             jQuery('#hh').val(jQuery('#hidden_hh').val());
  172.             jQuery('#mn').val(jQuery('#hidden_mn').val());
  173.             jQuery('.edit-timestamp').text(postL10n.edit);
  174.         }
  175.         return false;
  176.  
  177.     });
  178.  
  179.     // Custom Fields
  180.     jQuery('#the-list').wpList( { addAfter: function( xml, s ) {
  181.         if ( jQuery.isFunction( autosave_update_post_ID ) ) {
  182.             autosave_update_post_ID(s.parsed.responses[0].supplemental.postid);
  183.         }
  184.     }, addBefore: function( s ) {
  185.         s.data += '&post_id=' + jQuery('#post_ID').val();
  186.         return s;
  187.     }
  188.     });
  189. });
  190.