mp-wp_genesis 1 // this file contains all the scripts used in the post/edit page
mp-wp_genesis 2
mp-wp_genesis 3 function new_tag_remove_tag() {
mp-wp_genesis 4 var id = jQuery( this ).attr( 'id' );
mp-wp_genesis 5 var num = id.substr( 10 );
mp-wp_genesis 6 var current_tags = jQuery( '#tags-input' ).val().split(',');
mp-wp_genesis 7 delete current_tags[num];
mp-wp_genesis 8 var new_tags = [];
mp-wp_genesis 9 jQuery.each( current_tags, function( key, val ) {
mp-wp_genesis 10 if ( val && !val.match(/^\s+$/) && '' != val ) {
mp-wp_genesis 11 new_tags = new_tags.concat( val );
mp-wp_genesis 12 }
mp-wp_genesis 13 });
mp-wp_genesis 14 jQuery( '#tags-input' ).val( new_tags.join( ',' ).replace( /\s*,+\s*/, ',' ).replace( /,+/, ',' ).replace( /,+\s+,+/, ',' ).replace( /,+\s*$/, '' ).replace( /^\s*,+/, '' ) );
mp-wp_genesis 15 tag_update_quickclicks();
mp-wp_genesis 16 jQuery('#newtag').focus();
mp-wp_genesis 17 return false;
mp-wp_genesis 18 }
mp-wp_genesis 19
mp-wp_genesis 20 function tag_update_quickclicks() {
mp-wp_genesis 21 if ( jQuery( '#tags-input' ).length == 0 )
mp-wp_genesis 22 return;
mp-wp_genesis 23 var current_tags = jQuery( '#tags-input' ).val().split(',');
mp-wp_genesis 24 jQuery( '#tagchecklist' ).empty();
mp-wp_genesis 25 shown = false;
mp-wp_genesis 26 // jQuery.merge( current_tags, current_tags ); // this doesn't work anymore, need something to array_unique
mp-wp_genesis 27 jQuery.each( current_tags, function( key, val ) {
mp-wp_genesis 28 val = val.replace( /^\s+/, '' ).replace( /\s+$/, '' ); // trim
mp-wp_genesis 29 if ( !val.match(/^\s+$/) && '' != val ) {
mp-wp_genesis 30 txt = '<span><a id="tag-check-' + key + '" class="ntdelbutton">X</a> ' + val + '</span> ';
mp-wp_genesis 31 jQuery( '#tagchecklist' ).append( txt );
mp-wp_genesis 32 jQuery( '#tag-check-' + key ).click( new_tag_remove_tag );
mp-wp_genesis 33 shown = true;
mp-wp_genesis 34 }
mp-wp_genesis 35 });
mp-wp_genesis 36 if ( shown )
mp-wp_genesis 37 jQuery( '#tagchecklist' ).prepend( '<strong>'+postL10n.tagsUsed+'</strong><br />' );
mp-wp_genesis 38 }
mp-wp_genesis 39
mp-wp_genesis 40 function tag_flush_to_text(e,a) {
mp-wp_genesis 41 a = a || false;
mp-wp_genesis 42 var text = a ? jQuery(a).text() : jQuery('#newtag').val();
mp-wp_genesis 43 var newtags = jQuery('#tags-input').val();
mp-wp_genesis 44
mp-wp_genesis 45 var t = text.replace( /\s*([^,]+).*/, '$1,' );
mp-wp_genesis 46 newtags += ','
mp-wp_genesis 47
mp-wp_genesis 48 if ( newtags.indexOf(t) != -1 )
mp-wp_genesis 49 return false;
mp-wp_genesis 50
mp-wp_genesis 51 newtags += text;
mp-wp_genesis 52
mp-wp_genesis 53 // massage
mp-wp_genesis 54 newtags = newtags.replace( /\s+,+\s*/g, ',' ).replace( /,+/g, ',' ).replace( /,+\s+,+/g, ',' ).replace( /,+\s*$/g, '' ).replace( /^\s*,+/g, '' );
mp-wp_genesis 55 jQuery('#tags-input').val( newtags );
mp-wp_genesis 56 tag_update_quickclicks();
mp-wp_genesis 57 if ( ! a ) {
mp-wp_genesis 58 jQuery('#newtag').val('');
mp-wp_genesis 59 jQuery('#newtag').focus();
mp-wp_genesis 60 }
mp-wp_genesis 61 return false;
mp-wp_genesis 62 }
mp-wp_genesis 63
mp-wp_genesis 64 function tag_save_on_publish() {
mp-wp_genesis 65 if ( jQuery('#newtag').val() != postL10n.addTag )
mp-wp_genesis 66 tag_flush_to_text();
mp-wp_genesis 67 }
mp-wp_genesis 68
mp-wp_genesis 69 function tag_press_key( e ) {
mp-wp_genesis 70 if ( 13 == e.keyCode ) {
mp-wp_genesis 71 tag_flush_to_text();
mp-wp_genesis 72 return false;
mp-wp_genesis 73 }
mp-wp_genesis 74 };
mp-wp_genesis 75
mp-wp_genesis 76 (function($){
mp-wp_genesis 77 tagCloud = {
mp-wp_genesis 78 init : function() {
mp-wp_genesis 79 $('#tagcloud-link').click(function(){tagCloud.get(); $(this).unbind().click(function(){return false;}); return false;});
mp-wp_genesis 80 },
mp-wp_genesis 81
mp-wp_genesis 82 get : function() {
mp-wp_genesis 83 $.post('admin-ajax.php', {'action':'get-tagcloud'}, function(r, stat) {
mp-wp_genesis 84 if ( 0 == r || 'success' != stat )
mp-wp_genesis 85 r = wpAjax.broken;
mp-wp_genesis 86
mp-wp_genesis 87 r = '<p id="the-tagcloud">'+r+'</p>';
mp-wp_genesis 88 $('#tagcloud-link').after($(r));
mp-wp_genesis 89 $('#the-tagcloud a').click(function(){
mp-wp_genesis 90 tag_flush_to_text(0,this);
mp-wp_genesis 91 return false;
mp-wp_genesis 92 });
mp-wp_genesis 93 });
mp-wp_genesis 94 }
mp-wp_genesis 95 }
mp-wp_genesis 96 })(jQuery);
mp-wp_genesis 97
mp-wp_genesis 98 jQuery(document).ready( function($) {
mp-wp_genesis 99 tagCloud.init();
mp-wp_genesis 100
mp-wp_genesis 101 // close postboxes that should be closed
mp-wp_genesis 102 jQuery('.if-js-closed').removeClass('if-js-closed').addClass('closed');
mp-wp_genesis 103
mp-wp_genesis 104 // postboxes
mp-wp_genesis 105 postboxes.add_postbox_toggles('post');
mp-wp_genesis 106
mp-wp_genesis 107 // Editable slugs
mp-wp_genesis 108 make_slugedit_clickable();
mp-wp_genesis 109
mp-wp_genesis 110 jQuery('#tags-input').hide();
mp-wp_genesis 111 tag_update_quickclicks();
mp-wp_genesis 112 // add the quickadd form
mp-wp_genesis 113 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>');
mp-wp_genesis 114 jQuery('#tagadd').click( tag_flush_to_text );
mp-wp_genesis 115 jQuery('#newtag').focus(function() {
mp-wp_genesis 116 if ( this.value == postL10n.addTag )
mp-wp_genesis 117 jQuery(this).val( '' ).removeClass( 'form-input-tip' );
mp-wp_genesis 118 });
mp-wp_genesis 119 jQuery('#newtag').blur(function() {
mp-wp_genesis 120 if ( this.value == '' )
mp-wp_genesis 121 jQuery(this).val( postL10n.addTag ).addClass( 'form-input-tip' );
mp-wp_genesis 122 });
mp-wp_genesis 123
mp-wp_genesis 124 // auto-save tags on post save/publish
mp-wp_genesis 125 jQuery('#publish').click( tag_save_on_publish );
mp-wp_genesis 126 jQuery('#save-post').click( tag_save_on_publish );
mp-wp_genesis 127
mp-wp_genesis 128 jQuery('#title').blur( function() { if ( (jQuery("#post_ID").val() > 0) || (jQuery("#title").val().length == 0) ) return; autosave(); } );
mp-wp_genesis 129
mp-wp_genesis 130 // auto-suggest stuff
mp-wp_genesis 131 jQuery('#newtag').suggest( 'admin-ajax.php?action=ajax-tag-search', { delay: 500, minchars: 2, multiple: true, multipleSep: ", " } );
mp-wp_genesis 132 jQuery('#newtag').keypress( tag_press_key );
mp-wp_genesis 133
mp-wp_genesis 134 // category tabs
mp-wp_genesis 135 var categoryTabs =jQuery('#category-tabs').tabs();
mp-wp_genesis 136
mp-wp_genesis 137 // Ajax Cat
mp-wp_genesis 138 var newCat = jQuery('#newcat').one( 'focus', function() { jQuery(this).val( '' ).removeClass( 'form-input-tip' ) } );
mp-wp_genesis 139 jQuery('#category-add-sumbit').click( function() { newCat.focus(); } );
mp-wp_genesis 140 var newCatParent = false;
mp-wp_genesis 141 var newCatParentOption = false;
mp-wp_genesis 142 var noSyncChecks = false; // prophylactic. necessary?
mp-wp_genesis 143 var syncChecks = function() {
mp-wp_genesis 144 if ( noSyncChecks )
mp-wp_genesis 145 return;
mp-wp_genesis 146 noSyncChecks = true;
mp-wp_genesis 147 var th = jQuery(this);
mp-wp_genesis 148 var c = th.is(':checked');
mp-wp_genesis 149 var id = th.val().toString();
mp-wp_genesis 150 jQuery('#in-category-' + id + ', #in-popular-category-' + id).attr( 'checked', c );
mp-wp_genesis 151 noSyncChecks = false;
mp-wp_genesis 152 };
mp-wp_genesis 153 var popularCats = jQuery('#categorychecklist-pop :checkbox').map( function() { return parseInt(jQuery(this).val(), 10); } ).get().join(',');
mp-wp_genesis 154 var catAddBefore = function( s ) {
mp-wp_genesis 155 s.data += '&popular_ids=' + popularCats + '&' + jQuery( '#categorychecklist :checked' ).serialize();
mp-wp_genesis 156 return s;
mp-wp_genesis 157 };
mp-wp_genesis 158 var catAddAfter = function( r, s ) {
mp-wp_genesis 159 if ( !newCatParent ) newCatParent = jQuery('#newcat_parent');
mp-wp_genesis 160 if ( !newCatParentOption ) newCatParentOption = newCatParent.find( 'option[value=-1]' );
mp-wp_genesis 161 jQuery(s.what + ' response_data', r).each( function() {
mp-wp_genesis 162 var t = jQuery(jQuery(this).text());
mp-wp_genesis 163 t.find( 'label' ).each( function() {
mp-wp_genesis 164 var th = jQuery(this);
mp-wp_genesis 165 var val = th.find('input').val();
mp-wp_genesis 166 var id = th.find('input')[0].id
mp-wp_genesis 167 jQuery('#' + id).change( syncChecks ).change();
mp-wp_genesis 168 if ( newCatParent.find( 'option[value=' + val + ']' ).size() )
mp-wp_genesis 169 return;
mp-wp_genesis 170 var name = jQuery.trim( th.text() );
mp-wp_genesis 171 var o = jQuery( '<option value="' + parseInt( val, 10 ) + '"></option>' ).text( name );
mp-wp_genesis 172 newCatParent.prepend( o );
mp-wp_genesis 173 } );
mp-wp_genesis 174 newCatParentOption.attr( 'selected', true );
mp-wp_genesis 175 } );
mp-wp_genesis 176 };
mp-wp_genesis 177 jQuery('#categorychecklist').wpList( {
mp-wp_genesis 178 alt: '',
mp-wp_genesis 179 response: 'category-ajax-response',
mp-wp_genesis 180 addBefore: catAddBefore,
mp-wp_genesis 181 addAfter: catAddAfter
mp-wp_genesis 182 } );
mp-wp_genesis 183 jQuery('#category-add-toggle').click( function() {
mp-wp_genesis 184 jQuery(this).parents('div:first').toggleClass( 'wp-hidden-children' );
mp-wp_genesis 185 // categoryTabs.tabs( 'select', '#categories-all' ); // this is broken (in the UI beta?)
mp-wp_genesis 186 categoryTabs.find( 'a[href="#categories-all"]' ).click();
mp-wp_genesis 187 jQuery('#newcat').focus();
mp-wp_genesis 188 return false;
mp-wp_genesis 189 } );
mp-wp_genesis 190
mp-wp_genesis 191 $('a[href="#categories-all"]').click(function(){deleteUserSetting('cats');});
mp-wp_genesis 192 $('a[href="#categories-pop"]').click(function(){setUserSetting('cats','pop');});
mp-wp_genesis 193 if ( 'pop' == getUserSetting('cats') )
mp-wp_genesis 194 $('a[href="#categories-pop"]').click();
mp-wp_genesis 195
mp-wp_genesis 196 jQuery('.categorychecklist .popular-category :checkbox').change( syncChecks ).filter( ':checked' ).change();
mp-wp_genesis 197 var stamp = $('#timestamp').html();
mp-wp_genesis 198 var visibility = $('#post-visibility-display').html();
mp-wp_genesis 199 var sticky = '';
mp-wp_genesis 200
mp-wp_genesis 201 function updateVisibility() {
mp-wp_genesis 202 if ( $('#post-visibility-select input:radio:checked').val() != 'public' ) {
mp-wp_genesis 203 $('#sticky').attr('checked', false);
mp-wp_genesis 204 $('#sticky-span').hide();
mp-wp_genesis 205 } else {
mp-wp_genesis 206 $('#sticky-span').show();
mp-wp_genesis 207 }
mp-wp_genesis 208 if ( $('#post-visibility-select input:radio:checked').val() != 'password' ) {
mp-wp_genesis 209 $('#password-span').hide();
mp-wp_genesis 210 } else {
mp-wp_genesis 211 $('#password-span').show();
mp-wp_genesis 212 }
mp-wp_genesis 213 }
mp-wp_genesis 214
mp-wp_genesis 215 function updateText() {
mp-wp_genesis 216 var attemptedDate = new Date( $('#aa').val(), $('#mm').val() -1, $('#jj').val(), $('#hh').val(), $('#mn').val());
mp-wp_genesis 217 var originalDate = new Date( $('#hidden_aa').val(), $('#hidden_mm').val() -1, $('#hidden_jj').val(), $('#hidden_hh').val(), $('#hidden_mn').val());
mp-wp_genesis 218 var currentDate = new Date( $('#cur_aa').val(), $('#cur_mm').val() -1, $('#cur_jj').val(), $('#cur_hh').val(), $('#cur_mn').val());
mp-wp_genesis 219 if ( attemptedDate > currentDate && $('#original_post_status').val() != 'future' ) {
mp-wp_genesis 220 var publishOn = postL10n.publishOnFuture;
mp-wp_genesis 221 $('#publish').val( postL10n.schedule );
mp-wp_genesis 222 } else if ( attemptedDate <= currentDate && $('#original_post_status').val() != 'publish' ) {
mp-wp_genesis 223 var publishOn = postL10n.publishOn;
mp-wp_genesis 224 $('#publish').val( postL10n.publish );
mp-wp_genesis 225 } else {
mp-wp_genesis 226 var publishOn = postL10n.publishOnPast;
mp-wp_genesis 227 $('#publish').val( postL10n.update );
mp-wp_genesis 228 }
mp-wp_genesis 229 if ( originalDate.toUTCString() == attemptedDate.toUTCString() ) { //hack
mp-wp_genesis 230 $('#timestamp').html(stamp);
mp-wp_genesis 231 } else {
mp-wp_genesis 232 $('#timestamp').html(
mp-wp_genesis 233 publishOn + ' <b>' +
mp-wp_genesis 234 $( '#mm option[value=' + $('#mm').val() + ']' ).text() + ' ' +
mp-wp_genesis 235 $('#jj').val() + ', ' +
mp-wp_genesis 236 $('#aa').val() + ' @ ' +
mp-wp_genesis 237 $('#hh').val() + ':' +
mp-wp_genesis 238 $('#mn').val() + '</b> '
mp-wp_genesis 239 );
mp-wp_genesis 240 }
mp-wp_genesis 241
mp-wp_genesis 242 if ( $('#post-visibility-select input:radio:checked').val() == 'private' ) {
mp-wp_genesis 243 $('#publish').val( postL10n.update );
mp-wp_genesis 244 if ( $('#post_status option[value=publish]').length == 0 ) {
mp-wp_genesis 245 $('#post_status').append('<option value="publish">' + postL10n.privatelyPublished + '</option>');
mp-wp_genesis 246 }
mp-wp_genesis 247 $('#post_status option[value=publish]').html( postL10n.privatelyPublished );
mp-wp_genesis 248 $('#post_status option[value=publish]').attr('selected', true);
mp-wp_genesis 249 $('.edit-post-status').hide();
mp-wp_genesis 250 } else {
mp-wp_genesis 251 if ( $('#original_post_status').val() == 'future' || $('#original_post_status').val() == 'draft' ) {
mp-wp_genesis 252 if ( $('#post_status option[value=publish]').length != 0 ) {
mp-wp_genesis 253 $('#post_status option[value=publish]').remove();
mp-wp_genesis 254 $('#post_status').val($('#hidden_post_status').val());
mp-wp_genesis 255 }
mp-wp_genesis 256 } else {
mp-wp_genesis 257 $('#post_status option[value=publish]').html( postL10n.published );
mp-wp_genesis 258 }
mp-wp_genesis 259 $('.edit-post-status').show();
mp-wp_genesis 260 }
mp-wp_genesis 261 $('#post-status-display').html($('#post_status :selected').text());
mp-wp_genesis 262 if ( $('#post_status :selected').val() == 'private' || $('#post_status :selected').val() == 'publish' ) {
mp-wp_genesis 263 $('#save-post').hide();
mp-wp_genesis 264 } else {
mp-wp_genesis 265 $('#save-post').show();
mp-wp_genesis 266 if ( $('#post_status :selected').val() == 'pending' ) {
mp-wp_genesis 267 $('#save-post').show().val( postL10n.savePending );
mp-wp_genesis 268 } else {
mp-wp_genesis 269 $('#save-post').show().val( postL10n.saveDraft );
mp-wp_genesis 270 }
mp-wp_genesis 271 }
mp-wp_genesis 272 }
mp-wp_genesis 273
mp-wp_genesis 274 $('.edit-visibility').click(function () {
mp-wp_genesis 275 if ($('#post-visibility-select').is(":hidden")) {
mp-wp_genesis 276 updateVisibility();
mp-wp_genesis 277 $('#post-visibility-select').slideDown("normal");
mp-wp_genesis 278 $('.edit-visibility').hide();
mp-wp_genesis 279 }
mp-wp_genesis 280 return false;
mp-wp_genesis 281 });
mp-wp_genesis 282
mp-wp_genesis 283 $('.cancel-post-visibility').click(function () {
mp-wp_genesis 284 $('#post-visibility-select').slideUp("normal");
mp-wp_genesis 285 $('#visibility-radio-' + $('#hidden-post-visibility').val()).attr('checked', true);
mp-wp_genesis 286 $('#post_password').val($('#hidden_post_password').val());
mp-wp_genesis 287 $('#sticky').attr('checked', $('#hidden-post-sticky').attr('checked'));
mp-wp_genesis 288 $('#post-visibility-display').html(visibility);
mp-wp_genesis 289 $('.edit-visibility').show();
mp-wp_genesis 290 updateText();
mp-wp_genesis 291 return false;
mp-wp_genesis 292 });
mp-wp_genesis 293
mp-wp_genesis 294 $('.save-post-visibility').click(function () { // crazyhorse - multiple ok cancels
mp-wp_genesis 295 $('#post-visibility-select').slideUp("normal");
mp-wp_genesis 296 $('.edit-visibility').show();
mp-wp_genesis 297 updateText();
mp-wp_genesis 298 if ( $('#post-visibility-select input:radio:checked').val() != 'public' ) {
mp-wp_genesis 299 $('#sticky').attr('checked', false);
mp-wp_genesis 300 }
mp-wp_genesis 301
mp-wp_genesis 302 if ( true == $('#sticky').attr('checked') ) {
mp-wp_genesis 303 sticky = 'Sticky';
mp-wp_genesis 304 } else {
mp-wp_genesis 305 sticky = '';
mp-wp_genesis 306 }
mp-wp_genesis 307
mp-wp_genesis 308 $('#post-visibility-display').html(
mp-wp_genesis 309 postL10n[$('#post-visibility-select input:radio:checked').val() + sticky]
mp-wp_genesis 310 );
mp-wp_genesis 311
mp-wp_genesis 312 return false;
mp-wp_genesis 313 });
mp-wp_genesis 314
mp-wp_genesis 315 $('#post-visibility-select input:radio').change(function() {
mp-wp_genesis 316 updateVisibility();
mp-wp_genesis 317 });
mp-wp_genesis 318
mp-wp_genesis 319 $('.edit-timestamp').click(function () {
mp-wp_genesis 320 if ($('#timestampdiv').is(":hidden")) {
mp-wp_genesis 321 $('#timestampdiv').slideDown("normal");
mp-wp_genesis 322 $('.edit-timestamp').hide();
mp-wp_genesis 323 }
mp-wp_genesis 324
mp-wp_genesis 325 return false;
mp-wp_genesis 326 });
mp-wp_genesis 327
mp-wp_genesis 328 $('.cancel-timestamp').click(function() {
mp-wp_genesis 329 $('#timestampdiv').slideUp("normal");
mp-wp_genesis 330 $('#mm').val($('#hidden_mm').val());
mp-wp_genesis 331 $('#jj').val($('#hidden_jj').val());
mp-wp_genesis 332 $('#aa').val($('#hidden_aa').val());
mp-wp_genesis 333 $('#hh').val($('#hidden_hh').val());
mp-wp_genesis 334 $('#mn').val($('#hidden_mn').val());
mp-wp_genesis 335 $('.edit-timestamp').show();
mp-wp_genesis 336 updateText();
mp-wp_genesis 337 return false;
mp-wp_genesis 338 });
mp-wp_genesis 339
mp-wp_genesis 340 $('.save-timestamp').click(function () { // crazyhorse - multiple ok cancels
mp-wp_genesis 341 $('#timestampdiv').slideUp("normal");
mp-wp_genesis 342 $('.edit-timestamp').show();
mp-wp_genesis 343 updateText();
mp-wp_genesis 344
mp-wp_genesis 345 return false;
mp-wp_genesis 346 });
mp-wp_genesis 347
mp-wp_genesis 348 $('.edit-post-status').click(function() {
mp-wp_genesis 349 if ($('#post-status-select').is(":hidden")) {
mp-wp_genesis 350 $('#post-status-select').slideDown("normal");
mp-wp_genesis 351 $(this).hide();
mp-wp_genesis 352 }
mp-wp_genesis 353
mp-wp_genesis 354 return false;
mp-wp_genesis 355 });
mp-wp_genesis 356
mp-wp_genesis 357 $('.save-post-status').click(function() {
mp-wp_genesis 358 $('#post-status-select').slideUp("normal");
mp-wp_genesis 359 $('.edit-post-status').show();
mp-wp_genesis 360 updateText();
mp-wp_genesis 361 return false;
mp-wp_genesis 362 });
mp-wp_genesis 363
mp-wp_genesis 364 $('.cancel-post-status').click(function() {
mp-wp_genesis 365 $('#post-status-select').slideUp("normal");
mp-wp_genesis 366 $('#post_status').val($('#hidden_post_status').val());
mp-wp_genesis 367 $('.edit-post-status').show();
mp-wp_genesis 368 updateText();
mp-wp_genesis 369 return false;
mp-wp_genesis 370 });
mp-wp_genesis 371
mp-wp_genesis 372 // Custom Fields
mp-wp_genesis 373 jQuery('#the-list').wpList( { addAfter: function( xml, s ) {
mp-wp_genesis 374 $('table#list-table').show();
mp-wp_genesis 375 if ( jQuery.isFunction( autosave_update_post_ID ) ) {
mp-wp_genesis 376 autosave_update_post_ID(s.parsed.responses[0].supplemental.postid);
mp-wp_genesis 377 }
mp-wp_genesis 378 }, addBefore: function( s ) {
mp-wp_genesis 379 s.data += '&post_id=' + jQuery('#post_ID').val();
mp-wp_genesis 380 return s;
mp-wp_genesis 381 }
mp-wp_genesis 382 });
mp-wp_genesis 383
mp-wp_genesis 384 // preview
mp-wp_genesis 385 $('#post-preview').click(function(e){
mp-wp_genesis 386 if ( 1 > $('#post_ID').val() && autosaveFirst ) {
mp-wp_genesis 387 autosaveDelayPreview = true;
mp-wp_genesis 388 autosave();
mp-wp_genesis 389 return false;
mp-wp_genesis 390 }
mp-wp_genesis 391
mp-wp_genesis 392 $('input#wp-preview').val('dopreview');
mp-wp_genesis 393 $('form#post').attr('target', 'wp-preview').submit().attr('target', '');
mp-wp_genesis 394 $('input#wp-preview').val('');
mp-wp_genesis 395 return false;
mp-wp_genesis 396 });
mp-wp_genesis 397
mp-wp_genesis 398 });
mp-wp_genesis 399
mp-wp_genesis 400 (function($){
mp-wp_genesis 401 commentsBox = {
mp-wp_genesis 402 st : 0,
mp-wp_genesis 403
mp-wp_genesis 404 get : function(total, num) {
mp-wp_genesis 405 var st = this.st;
mp-wp_genesis 406 if ( ! num )
mp-wp_genesis 407 num = 20;
mp-wp_genesis 408
mp-wp_genesis 409 this.st += num;
mp-wp_genesis 410 this.total = total;
mp-wp_genesis 411 $('.waiting').show();
mp-wp_genesis 412
mp-wp_genesis 413 var data = {
mp-wp_genesis 414 'action' : 'get-comments',
mp-wp_genesis 415 'mode' : 'single',
mp-wp_genesis 416 '_ajax_nonce' : $('#add_comment_nonce').val(),
mp-wp_genesis 417 'post_ID' : $('#post_ID').val(),
mp-wp_genesis 418 'start' : st,
mp-wp_genesis 419 'num' : num
mp-wp_genesis 420 };
mp-wp_genesis 421
mp-wp_genesis 422 $.post('admin-ajax.php', data,
mp-wp_genesis 423 function(r) {
mp-wp_genesis 424 var r = wpAjax.parseAjaxResponse(r);
mp-wp_genesis 425 $('#commentstatusdiv .widefat').show();
mp-wp_genesis 426 $('.waiting').hide();
mp-wp_genesis 427
mp-wp_genesis 428 if ( 'object' == typeof r && r.responses[0] ) {
mp-wp_genesis 429 $('#the-comment-list').append( r.responses[0].data );
mp-wp_genesis 430 $('#the-comment-list .hide-if-no-js').removeClass('hide-if-no-js');
mp-wp_genesis 431
mp-wp_genesis 432 theList = theExtraList = null;
mp-wp_genesis 433 $("a[className*=':']").unbind();
mp-wp_genesis 434 setCommentsList();
mp-wp_genesis 435
mp-wp_genesis 436 if ( commentsBox.st > commentsBox.total )
mp-wp_genesis 437 $('#show-comments').hide();
mp-wp_genesis 438 else
mp-wp_genesis 439 $('#show-comments').html(postL10n.showcomm);
mp-wp_genesis 440 return;
mp-wp_genesis 441 } else if ( 1 == r ) {
mp-wp_genesis 442 $('#show-comments').parent().html(postL10n.endcomm);
mp-wp_genesis 443 return;
mp-wp_genesis 444 }
mp-wp_genesis 445
mp-wp_genesis 446 $('#the-comment-list').append('<tr><td colspan="5">'+wpAjax.broken+'</td></tr>');
mp-wp_genesis 447 }
mp-wp_genesis 448 );
mp-wp_genesis 449
mp-wp_genesis 450 return false;
mp-wp_genesis 451 }
mp-wp_genesis 452 };
mp-wp_genesis 453
mp-wp_genesis 454 })(jQuery);
mp-wp_genesis 455