1 // this file contains all the scripts used in the post/edit page
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];
9 jQuery.each( current_tags, function( key, val ) {
10 if ( val && !val.match(/^\s+$/) && '' != val ) {
11 new_tags = new_tags.concat( val );
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();
20 function tag_update_quickclicks() {
21 if ( jQuery( '#tags-input' ).length == 0 )
23 var current_tags = jQuery( '#tags-input' ).val().split(',');
24 jQuery( '#tagchecklist' ).empty();
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 );
37 jQuery( '#tagchecklist' ).prepend( '<strong>'+postL10n.tagsUsed+'</strong><br />' );
40 function tag_flush_to_text() {
41 var newtags = jQuery('#tags-input').val() + ',' + jQuery('#newtag').val();
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();
51 function tag_save_on_publish() {
52 if ( jQuery('#newtag').val() != postL10n.addTag )
56 function tag_press_key( e ) {
57 if ( 13 == e.keyCode ) {
63 jQuery(document).ready( function() {
64 // close postboxes that should be closed
65 jQuery('.if-js-closed').removeClass('if-js-closed').addClass('closed');
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();
72 add_postbox_toggles('post');
75 make_slugedit_clickable();
77 // hide advanced slug field
78 jQuery('#slugdiv').hide();
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' );
89 jQuery('#newtag').blur(function() {
90 if ( this.value == '' )
91 jQuery(this).val( postL10n.addTag ).addClass( 'form-input-tip' );
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 );
98 jQuery('#title').blur( function() { if ( (jQuery("#post_ID").val() > 0) || (jQuery("#title").val().length == 0) ) return; autosave(); } );
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 );
105 var categoryTabs =jQuery('#category-tabs').tabs();
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() {
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;
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();
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() )
140 var name = jQuery.trim( th.text() );
141 var o = jQuery( '<option value="' + parseInt( val, 10 ) + '"></option>' ).text( name );
142 newCatParent.prepend( o );
144 newCatParentOption.attr( 'selected', true );
147 jQuery('#categorychecklist').wpList( {
149 response: 'category-ajax-response',
150 addBefore: catAddBefore,
151 addAfter: catAddAfter
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();
160 jQuery('.categorychecklist .popular-category :checkbox').change( syncChecks ).filter( ':checked' ).change();
162 jQuery('.edit-timestamp').click(function () {
163 if (jQuery('#timestampdiv').is(":hidden")) {
164 jQuery('#timestampdiv').slideDown("normal");
165 jQuery('.edit-timestamp').text(postL10n.cancel);
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);
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);
184 }, addBefore: function( s ) {
185 s.data += '&post_id=' + jQuery('#post_ID').val();