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 var current_tags = jQuery( '#tags-input' ).val().split(',');
22 jQuery( '#tagchecklist' ).empty();
24 // jQuery.merge( current_tags, current_tags ); // this doesn't work anymore, need something to array_unique
25 jQuery.each( current_tags, function( key, val ) {
26 val = val.replace( /^\s+/, '' ).replace( /\s+$/, '' ); // trim
27 if ( !val.match(/^\s+$/) && '' != val ) {
28 txt = '<span><a id="tag-check-' + key + '" class="ntdelbutton">X</a> ' + val + '</span> ';
29 jQuery( '#tagchecklist' ).append( txt );
30 jQuery( '#tag-check-' + key ).click( new_tag_remove_tag );
35 jQuery( '#tagchecklist' ).prepend( '<strong>'+postL10n.tagsUsed+'</strong><br />' );
38 function tag_flush_to_text() {
39 var newtags = jQuery('#tags-input').val() + ',' + jQuery('#newtag').val();
41 newtags = newtags.replace( /\s+,+\s*/g, ',' ).replace( /,+/g, ',' ).replace( /,+\s+,+/g, ',' ).replace( /,+\s*$/g, '' ).replace( /^\s*,+/g, '' );
42 jQuery('#tags-input').val( newtags );
43 tag_update_quickclicks();
44 jQuery('#newtag').val('');
45 jQuery('#newtag').focus();
49 function tag_save_on_publish() {
50 if ( jQuery('#newtag').val() != postL10n.addTag )
54 function tag_press_key( e ) {
55 if ( 13 == e.keyCode ) {
61 jQuery(document).ready( function() {
62 // close postboxes that should be closed
63 jQuery('.if-js-closed').removeClass('if-js-closed').addClass('closed');
65 // show things that should be visible, hide what should be hidden
66 jQuery('.hide-if-no-js').show();
67 jQuery('.hide-if-js').hide();
70 add_postbox_toggles('post');
73 make_slugedit_clickable();
75 // hide advanced slug field
76 jQuery('#slugdiv').hide();
78 jQuery('#tags-input').hide();
79 tag_update_quickclicks();
80 // add the quickadd form
81 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>');
82 jQuery('#tagadd').click( tag_flush_to_text );
83 jQuery('#newtag').focus(function() {
84 if ( this.value == postL10n.addTag )
85 jQuery(this).val( '' ).removeClass( 'form-input-tip' );
87 jQuery('#newtag').blur(function() {
88 if ( this.value == '' )
89 jQuery(this).val( postL10n.addTag ).addClass( 'form-input-tip' );
92 // auto-save tags on post save/publish
93 jQuery('#publish').click( tag_save_on_publish );
94 jQuery('#save-post').click( tag_save_on_publish );
96 jQuery('#title').blur( function() { if ( (jQuery("#post_ID").val() > 0) || (jQuery("#title").val().length == 0) ) return; autosave(); } );
99 jQuery('#newtag').suggest( 'admin-ajax.php?action=ajax-tag-search', { delay: 500, minchars: 2 } );
100 jQuery('#newtag').keypress( tag_press_key );
103 var categoryTabs =jQuery('#category-tabs').tabs();
106 var newCat = jQuery('#newcat').one( 'focus', function() { jQuery(this).val( '' ).removeClass( 'form-input-tip' ) } );
107 jQuery('#category-add-sumbit').click( function() { newCat.focus(); } );
108 var newCatParent = false;
109 var newCatParentOption = false;
110 var noSyncChecks = false; // prophylactic. necessary?
111 var syncChecks = function() {
115 var th = jQuery(this);
116 var c = th.is(':checked');
117 var id = th.val().toString();
118 jQuery('#in-category-' + id + ', #in-popular-category-' + id).attr( 'checked', c );
119 noSyncChecks = false;
121 var catAddBefore = function( s ) {
122 s.data += '&' + jQuery( '#categorychecklist :checked' ).serialize();
125 var catAddAfter = function( r, s ) {
126 if ( !newCatParent ) newCatParent = jQuery('#newcat_parent');
127 if ( !newCatParentOption ) newCatParentOption = newCatParent.find( 'option[value=-1]' );
128 jQuery(s.what + ' response_data', r).each( function() {
129 var t = jQuery(jQuery(this).text());
130 t.find( 'label' ).each( function() {
131 var th = jQuery(this);
132 var val = th.find('input').val();
133 var id = th.find('input')[0].id
134 jQuery('#' + id).change( syncChecks ).change();
135 if ( newCatParent.find( 'option[value=' + val + ']' ).size() )
137 var name = jQuery.trim( th.text() );
138 var o = jQuery( '<option value="' + parseInt( val, 10 ) + '"></option>' ).text( name );
139 newCatParent.prepend( o );
141 newCatParentOption.attr( 'selected', true );
144 jQuery('#categorychecklist').wpList( {
146 response: 'category-ajax-response',
147 addBefore: catAddBefore,
148 addAfter: catAddAfter
150 jQuery('#category-add-toggle').click( function() {
151 jQuery(this).parents('div:first').toggleClass( 'wp-hidden-children' );
152 categoryTabs.tabsClick( 1 );
153 jQuery('#newcat').focus();
156 jQuery('.categorychecklist .popular-category :checkbox').change( syncChecks ).filter( ':checked' ).change();
158 jQuery('.edit-timestamp').click(function () {
159 if (jQuery('#timestampdiv').is(":hidden")) {
160 jQuery('#timestampdiv').slideDown("normal");
161 jQuery('.edit-timestamp').text(postL10n.cancel);
163 jQuery('#timestampdiv').hide();
164 jQuery('#mm').val(jQuery('#hidden_mm').val());
165 jQuery('#jj').val(jQuery('#hidden_jj').val());
166 jQuery('#aa').val(jQuery('#hidden_aa').val());
167 jQuery('#hh').val(jQuery('#hidden_hh').val());
168 jQuery('#mn').val(jQuery('#hidden_mn').val());
169 jQuery('.edit-timestamp').text(postL10n.edit);
176 jQuery('#the-list').wpList( { addAfter: function( xml, s ) {
177 if ( jQuery.isFunction( autosave_update_post_ID ) ) {
178 autosave_update_post_ID(s.parsed.responses[0].supplemental.postid);