-
+ 50EC9D3C1E91659D2AE1F9E78C70E46B077D0A047F58847995321BDD86D67858922A30A1A983CB1FFB19E7C8C95B1B8FBAA089C1FE9EDD60E80A04A5FDB8A995
mp-wp/wp-admin/js/post.js
(0 . 0)(1 . 455)
50835 // this file contains all the scripts used in the post/edit page
50836
50837 function new_tag_remove_tag() {
50838 var id = jQuery( this ).attr( 'id' );
50839 var num = id.substr( 10 );
50840 var current_tags = jQuery( '#tags-input' ).val().split(',');
50841 delete current_tags[num];
50842 var new_tags = [];
50843 jQuery.each( current_tags, function( key, val ) {
50844 if ( val && !val.match(/^\s+$/) && '' != val ) {
50845 new_tags = new_tags.concat( val );
50846 }
50847 });
50848 jQuery( '#tags-input' ).val( new_tags.join( ',' ).replace( /\s*,+\s*/, ',' ).replace( /,+/, ',' ).replace( /,+\s+,+/, ',' ).replace( /,+\s*$/, '' ).replace( /^\s*,+/, '' ) );
50849 tag_update_quickclicks();
50850 jQuery('#newtag').focus();
50851 return false;
50852 }
50853
50854 function tag_update_quickclicks() {
50855 if ( jQuery( '#tags-input' ).length == 0 )
50856 return;
50857 var current_tags = jQuery( '#tags-input' ).val().split(',');
50858 jQuery( '#tagchecklist' ).empty();
50859 shown = false;
50860 // jQuery.merge( current_tags, current_tags ); // this doesn't work anymore, need something to array_unique
50861 jQuery.each( current_tags, function( key, val ) {
50862 val = val.replace( /^\s+/, '' ).replace( /\s+$/, '' ); // trim
50863 if ( !val.match(/^\s+$/) && '' != val ) {
50864 txt = '<span><a id="tag-check-' + key + '" class="ntdelbutton">X</a> ' + val + '</span> ';
50865 jQuery( '#tagchecklist' ).append( txt );
50866 jQuery( '#tag-check-' + key ).click( new_tag_remove_tag );
50867 shown = true;
50868 }
50869 });
50870 if ( shown )
50871 jQuery( '#tagchecklist' ).prepend( '<strong>'+postL10n.tagsUsed+'</strong><br />' );
50872 }
50873
50874 function tag_flush_to_text(e,a) {
50875 a = a || false;
50876 var text = a ? jQuery(a).text() : jQuery('#newtag').val();
50877 var newtags = jQuery('#tags-input').val();
50878
50879 var t = text.replace( /\s*([^,]+).*/, '$1,' );
50880 newtags += ','
50881
50882 if ( newtags.indexOf(t) != -1 )
50883 return false;
50884
50885 newtags += text;
50886
50887 // massage
50888 newtags = newtags.replace( /\s+,+\s*/g, ',' ).replace( /,+/g, ',' ).replace( /,+\s+,+/g, ',' ).replace( /,+\s*$/g, '' ).replace( /^\s*,+/g, '' );
50889 jQuery('#tags-input').val( newtags );
50890 tag_update_quickclicks();
50891 if ( ! a ) {
50892 jQuery('#newtag').val('');
50893 jQuery('#newtag').focus();
50894 }
50895 return false;
50896 }
50897
50898 function tag_save_on_publish() {
50899 if ( jQuery('#newtag').val() != postL10n.addTag )
50900 tag_flush_to_text();
50901 }
50902
50903 function tag_press_key( e ) {
50904 if ( 13 == e.keyCode ) {
50905 tag_flush_to_text();
50906 return false;
50907 }
50908 };
50909
50910 (function($){
50911 tagCloud = {
50912 init : function() {
50913 $('#tagcloud-link').click(function(){tagCloud.get(); $(this).unbind().click(function(){return false;}); return false;});
50914 },
50915
50916 get : function() {
50917 $.post('admin-ajax.php', {'action':'get-tagcloud'}, function(r, stat) {
50918 if ( 0 == r || 'success' != stat )
50919 r = wpAjax.broken;
50920
50921 r = '<p id="the-tagcloud">'+r+'</p>';
50922 $('#tagcloud-link').after($(r));
50923 $('#the-tagcloud a').click(function(){
50924 tag_flush_to_text(0,this);
50925 return false;
50926 });
50927 });
50928 }
50929 }
50930 })(jQuery);
50931
50932 jQuery(document).ready( function($) {
50933 tagCloud.init();
50934
50935 // close postboxes that should be closed
50936 jQuery('.if-js-closed').removeClass('if-js-closed').addClass('closed');
50937
50938 // postboxes
50939 postboxes.add_postbox_toggles('post');
50940
50941 // Editable slugs
50942 make_slugedit_clickable();
50943
50944 jQuery('#tags-input').hide();
50945 tag_update_quickclicks();
50946 // add the quickadd form
50947 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>');
50948 jQuery('#tagadd').click( tag_flush_to_text );
50949 jQuery('#newtag').focus(function() {
50950 if ( this.value == postL10n.addTag )
50951 jQuery(this).val( '' ).removeClass( 'form-input-tip' );
50952 });
50953 jQuery('#newtag').blur(function() {
50954 if ( this.value == '' )
50955 jQuery(this).val( postL10n.addTag ).addClass( 'form-input-tip' );
50956 });
50957
50958 // auto-save tags on post save/publish
50959 jQuery('#publish').click( tag_save_on_publish );
50960 jQuery('#save-post').click( tag_save_on_publish );
50961
50962 jQuery('#title').blur( function() { if ( (jQuery("#post_ID").val() > 0) || (jQuery("#title").val().length == 0) ) return; autosave(); } );
50963
50964 // auto-suggest stuff
50965 jQuery('#newtag').suggest( 'admin-ajax.php?action=ajax-tag-search', { delay: 500, minchars: 2, multiple: true, multipleSep: ", " } );
50966 jQuery('#newtag').keypress( tag_press_key );
50967
50968 // category tabs
50969 var categoryTabs =jQuery('#category-tabs').tabs();
50970
50971 // Ajax Cat
50972 var newCat = jQuery('#newcat').one( 'focus', function() { jQuery(this).val( '' ).removeClass( 'form-input-tip' ) } );
50973 jQuery('#category-add-sumbit').click( function() { newCat.focus(); } );
50974 var newCatParent = false;
50975 var newCatParentOption = false;
50976 var noSyncChecks = false; // prophylactic. necessary?
50977 var syncChecks = function() {
50978 if ( noSyncChecks )
50979 return;
50980 noSyncChecks = true;
50981 var th = jQuery(this);
50982 var c = th.is(':checked');
50983 var id = th.val().toString();
50984 jQuery('#in-category-' + id + ', #in-popular-category-' + id).attr( 'checked', c );
50985 noSyncChecks = false;
50986 };
50987 var popularCats = jQuery('#categorychecklist-pop :checkbox').map( function() { return parseInt(jQuery(this).val(), 10); } ).get().join(',');
50988 var catAddBefore = function( s ) {
50989 s.data += '&popular_ids=' + popularCats + '&' + jQuery( '#categorychecklist :checked' ).serialize();
50990 return s;
50991 };
50992 var catAddAfter = function( r, s ) {
50993 if ( !newCatParent ) newCatParent = jQuery('#newcat_parent');
50994 if ( !newCatParentOption ) newCatParentOption = newCatParent.find( 'option[value=-1]' );
50995 jQuery(s.what + ' response_data', r).each( function() {
50996 var t = jQuery(jQuery(this).text());
50997 t.find( 'label' ).each( function() {
50998 var th = jQuery(this);
50999 var val = th.find('input').val();
51000 var id = th.find('input')[0].id
51001 jQuery('#' + id).change( syncChecks ).change();
51002 if ( newCatParent.find( 'option[value=' + val + ']' ).size() )
51003 return;
51004 var name = jQuery.trim( th.text() );
51005 var o = jQuery( '<option value="' + parseInt( val, 10 ) + '"></option>' ).text( name );
51006 newCatParent.prepend( o );
51007 } );
51008 newCatParentOption.attr( 'selected', true );
51009 } );
51010 };
51011 jQuery('#categorychecklist').wpList( {
51012 alt: '',
51013 response: 'category-ajax-response',
51014 addBefore: catAddBefore,
51015 addAfter: catAddAfter
51016 } );
51017 jQuery('#category-add-toggle').click( function() {
51018 jQuery(this).parents('div:first').toggleClass( 'wp-hidden-children' );
51019 // categoryTabs.tabs( 'select', '#categories-all' ); // this is broken (in the UI beta?)
51020 categoryTabs.find( 'a[href="#categories-all"]' ).click();
51021 jQuery('#newcat').focus();
51022 return false;
51023 } );
51024
51025 $('a[href="#categories-all"]').click(function(){deleteUserSetting('cats');});
51026 $('a[href="#categories-pop"]').click(function(){setUserSetting('cats','pop');});
51027 if ( 'pop' == getUserSetting('cats') )
51028 $('a[href="#categories-pop"]').click();
51029
51030 jQuery('.categorychecklist .popular-category :checkbox').change( syncChecks ).filter( ':checked' ).change();
51031 var stamp = $('#timestamp').html();
51032 var visibility = $('#post-visibility-display').html();
51033 var sticky = '';
51034
51035 function updateVisibility() {
51036 if ( $('#post-visibility-select input:radio:checked').val() != 'public' ) {
51037 $('#sticky').attr('checked', false);
51038 $('#sticky-span').hide();
51039 } else {
51040 $('#sticky-span').show();
51041 }
51042 if ( $('#post-visibility-select input:radio:checked').val() != 'password' ) {
51043 $('#password-span').hide();
51044 } else {
51045 $('#password-span').show();
51046 }
51047 }
51048
51049 function updateText() {
51050 var attemptedDate = new Date( $('#aa').val(), $('#mm').val() -1, $('#jj').val(), $('#hh').val(), $('#mn').val());
51051 var originalDate = new Date( $('#hidden_aa').val(), $('#hidden_mm').val() -1, $('#hidden_jj').val(), $('#hidden_hh').val(), $('#hidden_mn').val());
51052 var currentDate = new Date( $('#cur_aa').val(), $('#cur_mm').val() -1, $('#cur_jj').val(), $('#cur_hh').val(), $('#cur_mn').val());
51053 if ( attemptedDate > currentDate && $('#original_post_status').val() != 'future' ) {
51054 var publishOn = postL10n.publishOnFuture;
51055 $('#publish').val( postL10n.schedule );
51056 } else if ( attemptedDate <= currentDate && $('#original_post_status').val() != 'publish' ) {
51057 var publishOn = postL10n.publishOn;
51058 $('#publish').val( postL10n.publish );
51059 } else {
51060 var publishOn = postL10n.publishOnPast;
51061 $('#publish').val( postL10n.update );
51062 }
51063 if ( originalDate.toUTCString() == attemptedDate.toUTCString() ) { //hack
51064 $('#timestamp').html(stamp);
51065 } else {
51066 $('#timestamp').html(
51067 publishOn + ' <b>' +
51068 $( '#mm option[value=' + $('#mm').val() + ']' ).text() + ' ' +
51069 $('#jj').val() + ', ' +
51070 $('#aa').val() + ' @ ' +
51071 $('#hh').val() + ':' +
51072 $('#mn').val() + '</b> '
51073 );
51074 }
51075
51076 if ( $('#post-visibility-select input:radio:checked').val() == 'private' ) {
51077 $('#publish').val( postL10n.update );
51078 if ( $('#post_status option[value=publish]').length == 0 ) {
51079 $('#post_status').append('<option value="publish">' + postL10n.privatelyPublished + '</option>');
51080 }
51081 $('#post_status option[value=publish]').html( postL10n.privatelyPublished );
51082 $('#post_status option[value=publish]').attr('selected', true);
51083 $('.edit-post-status').hide();
51084 } else {
51085 if ( $('#original_post_status').val() == 'future' || $('#original_post_status').val() == 'draft' ) {
51086 if ( $('#post_status option[value=publish]').length != 0 ) {
51087 $('#post_status option[value=publish]').remove();
51088 $('#post_status').val($('#hidden_post_status').val());
51089 }
51090 } else {
51091 $('#post_status option[value=publish]').html( postL10n.published );
51092 }
51093 $('.edit-post-status').show();
51094 }
51095 $('#post-status-display').html($('#post_status :selected').text());
51096 if ( $('#post_status :selected').val() == 'private' || $('#post_status :selected').val() == 'publish' ) {
51097 $('#save-post').hide();
51098 } else {
51099 $('#save-post').show();
51100 if ( $('#post_status :selected').val() == 'pending' ) {
51101 $('#save-post').show().val( postL10n.savePending );
51102 } else {
51103 $('#save-post').show().val( postL10n.saveDraft );
51104 }
51105 }
51106 }
51107
51108 $('.edit-visibility').click(function () {
51109 if ($('#post-visibility-select').is(":hidden")) {
51110 updateVisibility();
51111 $('#post-visibility-select').slideDown("normal");
51112 $('.edit-visibility').hide();
51113 }
51114 return false;
51115 });
51116
51117 $('.cancel-post-visibility').click(function () {
51118 $('#post-visibility-select').slideUp("normal");
51119 $('#visibility-radio-' + $('#hidden-post-visibility').val()).attr('checked', true);
51120 $('#post_password').val($('#hidden_post_password').val());
51121 $('#sticky').attr('checked', $('#hidden-post-sticky').attr('checked'));
51122 $('#post-visibility-display').html(visibility);
51123 $('.edit-visibility').show();
51124 updateText();
51125 return false;
51126 });
51127
51128 $('.save-post-visibility').click(function () { // crazyhorse - multiple ok cancels
51129 $('#post-visibility-select').slideUp("normal");
51130 $('.edit-visibility').show();
51131 updateText();
51132 if ( $('#post-visibility-select input:radio:checked').val() != 'public' ) {
51133 $('#sticky').attr('checked', false);
51134 }
51135
51136 if ( true == $('#sticky').attr('checked') ) {
51137 sticky = 'Sticky';
51138 } else {
51139 sticky = '';
51140 }
51141
51142 $('#post-visibility-display').html(
51143 postL10n[$('#post-visibility-select input:radio:checked').val() + sticky]
51144 );
51145
51146 return false;
51147 });
51148
51149 $('#post-visibility-select input:radio').change(function() {
51150 updateVisibility();
51151 });
51152
51153 $('.edit-timestamp').click(function () {
51154 if ($('#timestampdiv').is(":hidden")) {
51155 $('#timestampdiv').slideDown("normal");
51156 $('.edit-timestamp').hide();
51157 }
51158
51159 return false;
51160 });
51161
51162 $('.cancel-timestamp').click(function() {
51163 $('#timestampdiv').slideUp("normal");
51164 $('#mm').val($('#hidden_mm').val());
51165 $('#jj').val($('#hidden_jj').val());
51166 $('#aa').val($('#hidden_aa').val());
51167 $('#hh').val($('#hidden_hh').val());
51168 $('#mn').val($('#hidden_mn').val());
51169 $('.edit-timestamp').show();
51170 updateText();
51171 return false;
51172 });
51173
51174 $('.save-timestamp').click(function () { // crazyhorse - multiple ok cancels
51175 $('#timestampdiv').slideUp("normal");
51176 $('.edit-timestamp').show();
51177 updateText();
51178
51179 return false;
51180 });
51181
51182 $('.edit-post-status').click(function() {
51183 if ($('#post-status-select').is(":hidden")) {
51184 $('#post-status-select').slideDown("normal");
51185 $(this).hide();
51186 }
51187
51188 return false;
51189 });
51190
51191 $('.save-post-status').click(function() {
51192 $('#post-status-select').slideUp("normal");
51193 $('.edit-post-status').show();
51194 updateText();
51195 return false;
51196 });
51197
51198 $('.cancel-post-status').click(function() {
51199 $('#post-status-select').slideUp("normal");
51200 $('#post_status').val($('#hidden_post_status').val());
51201 $('.edit-post-status').show();
51202 updateText();
51203 return false;
51204 });
51205
51206 // Custom Fields
51207 jQuery('#the-list').wpList( { addAfter: function( xml, s ) {
51208 $('table#list-table').show();
51209 if ( jQuery.isFunction( autosave_update_post_ID ) ) {
51210 autosave_update_post_ID(s.parsed.responses[0].supplemental.postid);
51211 }
51212 }, addBefore: function( s ) {
51213 s.data += '&post_id=' + jQuery('#post_ID').val();
51214 return s;
51215 }
51216 });
51217
51218 // preview
51219 $('#post-preview').click(function(e){
51220 if ( 1 > $('#post_ID').val() && autosaveFirst ) {
51221 autosaveDelayPreview = true;
51222 autosave();
51223 return false;
51224 }
51225
51226 $('input#wp-preview').val('dopreview');
51227 $('form#post').attr('target', 'wp-preview').submit().attr('target', '');
51228 $('input#wp-preview').val('');
51229 return false;
51230 });
51231
51232 });
51233
51234 (function($){
51235 commentsBox = {
51236 st : 0,
51237
51238 get : function(total, num) {
51239 var st = this.st;
51240 if ( ! num )
51241 num = 20;
51242
51243 this.st += num;
51244 this.total = total;
51245 $('.waiting').show();
51246
51247 var data = {
51248 'action' : 'get-comments',
51249 'mode' : 'single',
51250 '_ajax_nonce' : $('#add_comment_nonce').val(),
51251 'post_ID' : $('#post_ID').val(),
51252 'start' : st,
51253 'num' : num
51254 };
51255
51256 $.post('admin-ajax.php', data,
51257 function(r) {
51258 var r = wpAjax.parseAjaxResponse(r);
51259 $('#commentstatusdiv .widefat').show();
51260 $('.waiting').hide();
51261
51262 if ( 'object' == typeof r && r.responses[0] ) {
51263 $('#the-comment-list').append( r.responses[0].data );
51264 $('#the-comment-list .hide-if-no-js').removeClass('hide-if-no-js');
51265
51266 theList = theExtraList = null;
51267 $("a[className*=':']").unbind();
51268 setCommentsList();
51269
51270 if ( commentsBox.st > commentsBox.total )
51271 $('#show-comments').hide();
51272 else
51273 $('#show-comments').html(postL10n.showcomm);
51274 return;
51275 } else if ( 1 == r ) {
51276 $('#show-comments').parent().html(postL10n.endcomm);
51277 return;
51278 }
51279
51280 $('#the-comment-list').append('<tr><td colspan="5">'+wpAjax.broken+'</td></tr>');
51281 }
51282 );
51283
51284 return false;
51285 }
51286 };
51287
51288 })(jQuery);
51289