1 /* global postL10n, ajaxurl, wpAjax, setPostThumbnailL10n, postboxes, pagenow, tinymce, alert, deleteUserSetting */
2 /* global theList:true, theExtraList:true, getUserSetting, setUserSetting */
4 var tagBox, commentsBox, WPSetThumbnailHTML, WPSetThumbnailID, WPRemoveThumbnail, wptitlehint, makeSlugeditClickable, editPermalink;
5 // Back-compat: prevent fatal errors
6 makeSlugeditClickable = editPermalink = function(){};
8 window.wp = window.wp || {};
10 // return an array with any duplicate, whitespace or values removed
11 function array_unique_noempty(a) {
13 jQuery.each( a, function(key, val) {
14 val = jQuery.trim(val);
15 if ( val && jQuery.inArray(val, out) == -1 )
22 var titleHasFocus = false;
25 clean : function(tags) {
26 var comma = postL10n.comma;
28 tags = tags.replace(new RegExp(comma, 'g'), ',');
29 tags = tags.replace(/\s*,\s*/g, ',').replace(/,+/g, ',').replace(/[,\s]+$/, '').replace(/^[,\s]+/, '');
31 tags = tags.replace(/,/g, comma);
35 parseTags : function(el) {
36 var id = el.id, num = id.split('-check-num-')[1], taxbox = $(el).closest('.tagsdiv'),
37 thetags = taxbox.find('.the-tags'), comma = postL10n.comma,
38 current_tags = thetags.val().split(comma), new_tags = [];
39 delete current_tags[num];
41 $.each( current_tags, function(key, val) {
48 thetags.val( this.clean( new_tags.join(comma) ) );
50 this.quickClicks(taxbox);
54 quickClicks : function(el) {
55 var thetags = $('.the-tags', el),
56 tagchecklist = $('.tagchecklist', el),
57 id = $(el).attr('id'),
58 current_tags, disabled;
60 if ( !thetags.length )
63 disabled = thetags.prop('disabled');
65 current_tags = thetags.val().split(postL10n.comma);
68 $.each( current_tags, function( key, val ) {
76 // Create a new span, and ensure the text is properly escaped.
77 span = $('<span />').text( val );
79 // If tags editing isn't disabled, create the X button.
81 xbutton = $( '<a id="' + id + '-check-num-' + key + '" class="ntdelbutton">X</a>' );
82 xbutton.click( function(){ tagBox.parseTags(this); });
83 span.prepend(' ').prepend( xbutton );
86 // Append the span to the tag list.
87 tagchecklist.append( span );
91 flushTags : function(el, a, f) {
92 var tagsval, newtags, text,
93 tags = $('.the-tags', el),
94 newtag = $('input.newtag', el),
95 comma = postL10n.comma;
98 text = a ? $(a).text() : newtag.val();
100 newtags = tagsval ? tagsval + comma + text : text;
102 newtags = this.clean( newtags );
103 newtags = array_unique_noempty( newtags.split(comma) ).join(comma);
105 this.quickClicks(el);
109 if ( 'undefined' == typeof(f) )
116 var tax = id.substr(id.indexOf('-')+1);
118 $.post(ajaxurl, {'action':'get-tagcloud', 'tax':tax}, function(r, stat) {
119 if ( 0 === r || 'success' != stat )
122 r = $('<p id="tagcloud-'+tax+'" class="the-tagcloud">'+r+'</p>');
123 $('a', r).click(function(){
124 tagBox.flushTags( $(this).closest('.inside').children('.tagsdiv'), this);
133 var t = this, ajaxtag = $('div.ajaxtag');
135 $('.tagsdiv').each( function() {
136 tagBox.quickClicks(this);
139 $('input.tagadd', ajaxtag).click(function(){
140 t.flushTags( $(this).closest('.tagsdiv') );
143 $('div.taghint', ajaxtag).click(function(){
144 $(this).css('visibility', 'hidden').parent().siblings('.newtag').focus();
147 $('input.newtag', ajaxtag).blur(function() {
148 if ( '' === this.value )
149 $(this).parent().siblings('.taghint').css('visibility', '');
151 $(this).parent().siblings('.taghint').css('visibility', 'hidden');
152 }).keyup(function(e){
153 if ( 13 == e.which ) {
154 tagBox.flushTags( $(this).closest('.tagsdiv') );
157 }).keypress(function(e){
158 if ( 13 == e.which ) {
163 var tax = $(this).closest('div.tagsdiv').attr('id');
164 $(this).suggest( ajaxurl + '?action=ajax-tag-search&tax=' + tax, { delay: 500, minchars: 2, multiple: true, multipleSep: postL10n.comma + ' ' } );
167 // save tags on post save/publish
168 $('#post').submit(function(){
169 $('div.tagsdiv').each( function() {
170 tagBox.flushTags(this, false, 1);
175 $('a.tagcloud-link').click(function(){
176 tagBox.get( $(this).attr('id') );
177 $(this).unbind().click(function(){
178 $(this).siblings('.the-tagcloud').toggle();
189 get : function(total, num) {
190 var st = this.st, data;
196 $('#commentsdiv .spinner').show();
199 'action' : 'get-comments',
201 '_ajax_nonce' : $('#add_comment_nonce').val(),
202 'p' : $('#post_ID').val(),
207 $.post(ajaxurl, data,
209 r = wpAjax.parseAjaxResponse(r);
210 $('#commentsdiv .widefat').show();
211 $('#commentsdiv .spinner').hide();
213 if ( 'object' == typeof r && r.responses[0] ) {
214 $('#the-comment-list').append( r.responses[0].data );
216 theList = theExtraList = null;
217 $( 'a[className*=\':\']' ).unbind();
219 if ( commentsBox.st > commentsBox.total )
220 $('#show-comments').hide();
222 $('#show-comments').show().children('a').html(postL10n.showcomm);
225 } else if ( 1 == r ) {
226 $('#show-comments').html(postL10n.endcomm);
230 $('#the-comment-list').append('<tr><td colspan="2">'+wpAjax.broken+'</td></tr>');
238 WPSetThumbnailHTML = function(html){
239 $('.inside', '#postimagediv').html(html);
242 WPSetThumbnailID = function(id){
243 var field = $('input[value="_thumbnail_id"]', '#list-table');
244 if ( field.size() > 0 ) {
245 $('#meta\\[' + field.attr('id').match(/[0-9]+/) + '\\]\\[value\\]').text(id);
249 WPRemoveThumbnail = function(nonce){
251 action: 'set-post-thumbnail', post_id: $( '#post_ID' ).val(), thumbnail_id: -1, _ajax_nonce: nonce, cookie: encodeURIComponent( document.cookie )
254 alert( setPostThumbnailL10n.error );
256 WPSetThumbnailHTML(str);
262 $(document).on( 'heartbeat-send.refresh-lock', function( e, data ) {
263 var lock = $('#active_post_lock').val(),
264 post_id = $('#post_ID').val(),
267 if ( ! post_id || ! $('#post-lock-dialog').length )
270 send.post_id = post_id;
275 data['wp-refresh-post-lock'] = send;
277 }).on( 'heartbeat-tick.refresh-lock', function( e, data ) {
278 // Post locks: update the lock string or show the dialog if somebody has taken over editing
279 var received, wrap, avatar;
281 if ( data['wp-refresh-post-lock'] ) {
282 received = data['wp-refresh-post-lock'];
284 if ( received.lock_error ) {
285 // show "editing taken over" message
286 wrap = $('#post-lock-dialog');
288 if ( wrap.length && ! wrap.is(':visible') ) {
290 // Save the latest changes and disable
291 $(document).one( 'heartbeat-tick', function() {
292 wp.autosave.server.suspend();
293 wrap.removeClass('saving').addClass('saved');
294 $(window).off( 'beforeunload.edit-post' );
297 wrap.addClass('saving');
298 wp.autosave.server.triggerSave();
301 if ( received.lock_error.avatar_src ) {
302 avatar = $('<img class="avatar avatar-64 photo" width="64" height="64" />').attr( 'src', received.lock_error.avatar_src.replace(/&/g, '&') );
303 wrap.find('div.post-locked-avatar').empty().append( avatar );
306 wrap.show().find('.currently-editing').text( received.lock_error.text );
307 wrap.find('.wp-tab-first').focus();
309 } else if ( received.new_lock ) {
310 $('#active_post_lock').val( received.new_lock );
313 }).on( 'before-autosave.update-post-slug', function() {
314 titleHasFocus = document.activeElement && document.activeElement.id === 'title';
315 }).on( 'after-autosave.update-post-slug', function() {
316 // Create slug area only if not already there
317 // and the title field was not focused (user was not typing a title) when autosave ran
318 if ( ! $('#edit-slug-box > *').length && ! titleHasFocus ) {
320 action: 'sample-permalink',
321 post_id: $('#post_ID').val(),
322 new_title: $('#title').val(),
323 samplepermalinknonce: $('#samplepermalinknonce').val()
326 if ( data != '-1' ) {
327 $('#edit-slug-box').html(data);
339 function schedule() {
341 window.clearTimeout( timeout );
342 timeout = window.setTimeout( function(){ check = true; }, 300000 );
345 $(document).on( 'heartbeat-send.wp-refresh-nonces', function( e, data ) {
349 if ( ( post_id = $('#post_ID').val() ) && ( nonce = $('#_wpnonce').val() ) ) {
350 data['wp-refresh-post-nonces'] = {
356 }).on( 'heartbeat-tick.wp-refresh-nonces', function( e, data ) {
357 var nonces = data['wp-refresh-post-nonces'];
362 if ( nonces.replace ) {
363 $.each( nonces.replace, function( selector, value ) {
364 $( '#' + selector ).val( value );
368 if ( nonces.heartbeatNonce )
369 window.heartbeatSettings.nonce = nonces.heartbeatNonce;
371 }).ready( function() {
376 jQuery(document).ready( function($) {
377 var stamp, visibility, $submitButtons, updateVisibility, updateText,
381 $document = $(document),
382 $editSlugWrap = $('#edit-slug-box'),
383 postId = $('#post_ID').val() || 0,
384 $submitpost = $('#submitpost'),
386 $postVisibilitySelect = $('#post-visibility-select'),
387 $timestampdiv = $('#timestampdiv'),
388 $postStatusSelect = $('#post-status-select');
390 postboxes.add_postbox_toggles(pagenow);
392 // Clear the window name. Otherwise if this is a former preview window where the user navigated to edit another post,
393 // and the first post is still being edited, clicking Preview there will use this window to show the preview.
396 // Post locks: contain focus inside the dialog. If the dialog is shown, focus the first item.
397 $('#post-lock-dialog .notification-dialog').on( 'keydown', function(e) {
401 var target = $(e.target);
403 if ( target.hasClass('wp-tab-first') && e.shiftKey ) {
404 $(this).find('.wp-tab-last').focus();
406 } else if ( target.hasClass('wp-tab-last') && ! e.shiftKey ) {
407 $(this).find('.wp-tab-first').focus();
410 }).filter(':visible').find('.wp-tab-first').focus();
412 // Set the heartbeat interval to 15 sec. if post lock dialogs are enabled
413 if ( wp.heartbeat && $('#post-lock-dialog').length ) {
414 wp.heartbeat.interval( 15 );
417 // The form is being submitted by the user
418 $submitButtons = $submitpost.find( ':submit, a.submitdelete, #post-preview' ).on( 'click.edit-post', function( event ) {
419 var $button = $(this);
421 if ( $button.hasClass('disabled') ) {
422 event.preventDefault();
426 if ( $button.hasClass('submitdelete') || $button.is( '#post-preview' ) ) {
430 // The form submission can be blocked from JS or by using HTML 5.0 validation on some fields.
431 // Run this only on an actual 'submit'.
432 $('form#post').off( 'submit.edit-post' ).on( 'submit.edit-post', function( event ) {
433 if ( event.isDefaultPrevented() ) {
439 wp.autosave.server.suspend();
443 $(window).off( 'beforeunload.edit-post' );
445 $submitButtons.addClass( 'disabled' );
447 if ( $button.attr('id') === 'publish' ) {
448 $submitpost.find('#major-publishing-actions .spinner').show();
450 $submitpost.find('#minor-publishing .spinner').show();
455 // Submit the form saving a draft or an autosave, and show a preview in a new tab
456 $('#post-preview').on( 'click.post-preview', function( event ) {
458 $form = $('form#post'),
459 $previewField = $('input#wp-preview'),
460 target = $this.attr('target') || 'wp-preview',
461 ua = navigator.userAgent.toLowerCase();
463 event.preventDefault();
465 if ( $this.hasClass('disabled') ) {
470 wp.autosave.server.tempBlockSave();
473 $previewField.val('dopreview');
474 $form.attr( 'target', target ).submit().attr( 'target', '' );
476 // Workaround for WebKit bug preventing a form submitting twice to the same action.
477 // https://bugs.webkit.org/show_bug.cgi?id=28633
478 if ( ua.indexOf('safari') !== -1 && ua.indexOf('chrome') === -1 ) {
479 $form.attr( 'action', function( index, value ) {
480 return value + '?t=' + ( new Date() ).getTime();
484 $previewField.val('');
487 // This code is meant to allow tabbing from Title to Post content.
488 $('#title').on( 'keydown.editor-focus', function( event ) {
489 var editor, $textarea;
491 if ( event.keyCode === 9 && ! event.ctrlKey && ! event.altKey && ! event.shiftKey ) {
492 editor = typeof tinymce != 'undefined' && tinymce.get('content');
493 $textarea = $('#content');
495 if ( editor && ! editor.isHidden() ) {
497 } else if ( $textarea.length ) {
503 event.preventDefault();
507 // Autosave new posts after a title is typed
508 if ( $( '#auto_draft' ).val() ) {
509 $( '#title' ).blur( function() {
512 if ( ! this.value || $('#edit-slug-box > *').length ) {
516 // Cancel the autosave when the blur was triggered by the user submitting the form
517 $('form#post').one( 'submit', function() {
521 window.setTimeout( function() {
522 if ( ! cancel && wp.autosave ) {
523 wp.autosave.server.triggerSave();
529 $document.on( 'autosave-disable-buttons.edit-post', function() {
530 $submitButtons.addClass( 'disabled' );
531 }).on( 'autosave-enable-buttons.edit-post', function() {
532 if ( ! wp.heartbeat || ! wp.heartbeat.hasConnectionError() ) {
533 $submitButtons.removeClass( 'disabled' );
535 }).on( 'before-autosave.edit-post', function() {
536 $( '.autosave-message' ).text( postL10n.savingText );
537 }).on( 'after-autosave.edit-post', function( event, data ) {
538 $( '.autosave-message' ).text( data.message );
541 $(window).on( 'beforeunload.edit-post', function() {
542 var editor = typeof tinymce !== 'undefined' && tinymce.get('content');
544 if ( ( editor && ! editor.isHidden() && editor.isDirty() ) ||
545 ( wp.autosave && wp.autosave.server.postChanged() ) ) {
547 return postL10n.saveAlert;
549 }).on( 'unload.edit-post', function( event ) {
550 if ( ! releaseLock ) {
554 // Unload is triggered (by hand) on removing the Thickbox iframe.
555 // Make sure we process only the main document unload.
556 if ( event.target && event.target.nodeName != '#document' ) {
565 action: 'wp-remove-post-lock',
566 _wpnonce: $('#_wpnonce').val(),
567 post_ID: $('#post_ID').val(),
568 active_post_lock: $('#active_post_lock').val()
574 if ( $('#tagsdiv-post_tag').length ) {
577 $('#side-sortables, #normal-sortables, #advanced-sortables').children('div.postbox').each(function(){
578 if ( this.id.indexOf('tagsdiv-') === 0 ) {
586 $('.categorydiv').each( function(){
587 var this_id = $(this).attr('id'), catAddBefore, catAddAfter, taxonomyParts, taxonomy, settingName;
589 taxonomyParts = this_id.split('-');
590 taxonomyParts.shift();
591 taxonomy = taxonomyParts.join('-');
592 settingName = taxonomy + '_tab';
593 if ( taxonomy == 'category' )
594 settingName = 'cats';
596 // TODO: move to jQuery 1.3+, support for multiple hierarchical taxonomies, see wp-lists.js
597 $('a', '#' + taxonomy + '-tabs').click( function(){
598 var t = $(this).attr('href');
599 $(this).parent().addClass('tabs').siblings('li').removeClass('tabs');
600 $('#' + taxonomy + '-tabs').siblings('.tabs-panel').hide();
602 if ( '#' + taxonomy + '-all' == t )
603 deleteUserSetting( settingName );
605 setUserSetting( settingName, 'pop' );
609 if ( getUserSetting( settingName ) )
610 $('a[href="#' + taxonomy + '-pop"]', '#' + taxonomy + '-tabs').click();
613 $( '#new' + taxonomy ).one( 'focus', function() { $( this ).val( '' ).removeClass( 'form-input-tip' ); } );
615 $('#new' + taxonomy).keypress( function(event){
616 if( 13 === event.keyCode ) {
617 event.preventDefault();
618 $('#' + taxonomy + '-add-submit').click();
621 $('#' + taxonomy + '-add-submit').click( function(){ $('#new' + taxonomy).focus(); });
623 catAddBefore = function( s ) {
624 if ( !$('#new'+taxonomy).val() )
626 s.data += '&' + $( ':checked', '#'+taxonomy+'checklist' ).serialize();
627 $( '#' + taxonomy + '-add-submit' ).prop( 'disabled', true );
631 catAddAfter = function( r, s ) {
632 var sup, drop = $('#new'+taxonomy+'_parent');
634 $( '#' + taxonomy + '-add-submit' ).prop( 'disabled', false );
635 if ( 'undefined' != s.parsed.responses[0] && (sup = s.parsed.responses[0].supplemental.newcat_parent) ) {
641 $('#' + taxonomy + 'checklist').wpList({
643 response: taxonomy + '-ajax-response',
644 addBefore: catAddBefore,
645 addAfter: catAddAfter
648 $('#' + taxonomy + '-add-toggle').click( function() {
649 $('#' + taxonomy + '-adder').toggleClass( 'wp-hidden-children' );
650 $('a[href="#' + taxonomy + '-all"]', '#' + taxonomy + '-tabs').click();
651 $('#new'+taxonomy).focus();
655 $('#' + taxonomy + 'checklist, #' + taxonomy + 'checklist-pop').on( 'click', 'li.popular-category > label input[type="checkbox"]', function() {
656 var t = $(this), c = t.is(':checked'), id = t.val();
657 if ( id && t.parents('#taxonomy-'+taxonomy).length )
658 $('#in-' + taxonomy + '-' + id + ', #in-popular-' + taxonomy + '-' + id).prop( 'checked', c );
664 if ( $('#postcustom').length ) {
665 $( '#the-list' ).wpList( { addAfter: function() {
666 $('table#list-table').show();
667 }, addBefore: function( s ) {
668 s.data += '&post_id=' + $('#post_ID').val();
675 if ( $('#submitdiv').length ) {
676 stamp = $('#timestamp').html();
677 visibility = $('#post-visibility-display').html();
679 updateVisibility = function() {
680 if ( $postVisibilitySelect.find('input:radio:checked').val() != 'public' ) {
681 $('#sticky').prop('checked', false);
682 $('#sticky-span').hide();
684 $('#sticky-span').show();
686 if ( $postVisibilitySelect.find('input:radio:checked').val() != 'password' ) {
687 $('#password-span').hide();
689 $('#password-span').show();
693 updateText = function() {
695 if ( ! $timestampdiv.length )
698 var attemptedDate, originalDate, currentDate, publishOn, postStatus = $('#post_status'),
699 optPublish = $('option[value="publish"]', postStatus), aa = $('#aa').val(),
700 mm = $('#mm').val(), jj = $('#jj').val(), hh = $('#hh').val(), mn = $('#mn').val();
702 attemptedDate = new Date( aa, mm - 1, jj, hh, mn );
703 originalDate = new Date( $('#hidden_aa').val(), $('#hidden_mm').val() -1, $('#hidden_jj').val(), $('#hidden_hh').val(), $('#hidden_mn').val() );
704 currentDate = new Date( $('#cur_aa').val(), $('#cur_mm').val() -1, $('#cur_jj').val(), $('#cur_hh').val(), $('#cur_mn').val() );
706 if ( attemptedDate.getFullYear() != aa || (1 + attemptedDate.getMonth()) != mm || attemptedDate.getDate() != jj || attemptedDate.getMinutes() != mn ) {
707 $timestampdiv.find('.timestamp-wrap').addClass('form-invalid');
710 $timestampdiv.find('.timestamp-wrap').removeClass('form-invalid');
713 if ( attemptedDate > currentDate && $('#original_post_status').val() != 'future' ) {
714 publishOn = postL10n.publishOnFuture;
715 $('#publish').val( postL10n.schedule );
716 } else if ( attemptedDate <= currentDate && $('#original_post_status').val() != 'publish' ) {
717 publishOn = postL10n.publishOn;
718 $('#publish').val( postL10n.publish );
720 publishOn = postL10n.publishOnPast;
721 $('#publish').val( postL10n.update );
723 if ( originalDate.toUTCString() == attemptedDate.toUTCString() ) { //hack
724 $('#timestamp').html(stamp);
726 $('#timestamp').html(
728 postL10n.dateFormat.replace( '%1$s', $('option[value="' + $('#mm').val() + '"]', '#mm').text() )
729 .replace( '%2$s', jj )
730 .replace( '%3$s', aa )
731 .replace( '%4$s', hh )
732 .replace( '%5$s', mn ) +
737 if ( $postVisibilitySelect.find('input:radio:checked').val() == 'private' ) {
738 $('#publish').val( postL10n.update );
739 if ( 0 === optPublish.length ) {
740 postStatus.append('<option value="publish">' + postL10n.privatelyPublished + '</option>');
742 optPublish.html( postL10n.privatelyPublished );
744 $('option[value="publish"]', postStatus).prop('selected', true);
745 $('#misc-publishing-actions .edit-post-status').hide();
747 if ( $('#original_post_status').val() == 'future' || $('#original_post_status').val() == 'draft' ) {
748 if ( optPublish.length ) {
750 postStatus.val($('#hidden_post_status').val());
753 optPublish.html( postL10n.published );
755 if ( postStatus.is(':hidden') )
756 $('#misc-publishing-actions .edit-post-status').show();
758 $('#post-status-display').html($('option:selected', postStatus).text());
759 if ( $('option:selected', postStatus).val() == 'private' || $('option:selected', postStatus).val() == 'publish' ) {
760 $('#save-post').hide();
762 $('#save-post').show();
763 if ( $('option:selected', postStatus).val() == 'pending' ) {
764 $('#save-post').show().val( postL10n.savePending );
766 $('#save-post').show().val( postL10n.saveDraft );
772 $( '#visibility .edit-visibility').click( function () {
773 if ( $postVisibilitySelect.is(':hidden') ) {
775 $postVisibilitySelect.slideDown('fast').find('input[type="radio"]').first().focus();
781 $postVisibilitySelect.find('.cancel-post-visibility').click( function( event ) {
782 $postVisibilitySelect.slideUp('fast');
783 $('#visibility-radio-' + $('#hidden-post-visibility').val()).prop('checked', true);
784 $('#post_password').val($('#hidden-post-password').val());
785 $('#sticky').prop('checked', $('#hidden-post-sticky').prop('checked'));
786 $('#post-visibility-display').html(visibility);
787 $('#visibility .edit-visibility').show().focus();
789 event.preventDefault();
792 $postVisibilitySelect.find('.save-post-visibility').click( function( event ) { // crazyhorse - multiple ok cancels
793 $postVisibilitySelect.slideUp('fast');
794 $('#visibility .edit-visibility').show();
797 if ( $postVisibilitySelect.find('input:radio:checked').val() != 'public' ) {
798 $('#sticky').prop('checked', false);
801 if ( $('#sticky').prop('checked') ) {
807 $('#post-visibility-display').html( postL10n[ $postVisibilitySelect.find('input:radio:checked').val() + sticky ] );
808 event.preventDefault();
811 $postVisibilitySelect.find('input:radio').change( function() {
815 $timestampdiv.siblings('a.edit-timestamp').click( function( event ) {
816 if ( $timestampdiv.is( ':hidden' ) ) {
817 $timestampdiv.slideDown('fast');
821 event.preventDefault();
824 $timestampdiv.find('.cancel-timestamp').click( function( event ) {
825 $timestampdiv.slideUp('fast').siblings('a.edit-timestamp').show().focus();
826 $('#mm').val($('#hidden_mm').val());
827 $('#jj').val($('#hidden_jj').val());
828 $('#aa').val($('#hidden_aa').val());
829 $('#hh').val($('#hidden_hh').val());
830 $('#mn').val($('#hidden_mn').val());
832 event.preventDefault();
835 $timestampdiv.find('.save-timestamp').click( function( event ) { // crazyhorse - multiple ok cancels
836 if ( updateText() ) {
837 $timestampdiv.slideUp('fast');
838 $timestampdiv.siblings('a.edit-timestamp').show();
840 event.preventDefault();
843 $('#post').on( 'submit', function( event ) {
844 if ( ! updateText() ) {
845 event.preventDefault();
846 $timestampdiv.show();
849 wp.autosave.enableButtons();
852 $('#publishing-action .spinner').hide();
856 $postStatusSelect.siblings('a.edit-post-status').click( function( event ) {
857 if ( $postStatusSelect.is( ':hidden' ) ) {
858 $postStatusSelect.slideDown('fast').find('select').focus();
861 event.preventDefault();
864 $postStatusSelect.find('.save-post-status').click( function( event ) {
865 $postStatusSelect.slideUp('fast').siblings('a.edit-post-status').show();
867 event.preventDefault();
870 $postStatusSelect.find('.cancel-post-status').click( function( event ) {
871 $('#post-status-select').slideUp('fast').siblings( 'a.edit-post-status' ).show().focus();
872 $('#post_status').val( $('#hidden_post_status').val() );
874 event.preventDefault();
879 function editPermalink() {
882 e = $('#editable-post-name'),
884 real_slug = $('#post_name'),
885 revert_slug = real_slug.val(),
886 b = $('#edit-slug-buttons'),
888 full = $('#editable-post-name-full').html();
890 $('#view-post-btn').hide();
891 b.html('<a href="#" class="save button button-small">'+postL10n.ok+'</a> <a class="cancel" href="#">'+postL10n.cancel+'</a>');
892 b.children('.save').click(function() {
893 var new_slug = e.children('input').val();
894 if ( new_slug == $('#editable-post-name-full').text() ) {
895 b.children('.cancel').click();
899 action: 'sample-permalink',
902 new_title: $('#title').val(),
903 samplepermalinknonce: $('#samplepermalinknonce').val()
905 var box = $('#edit-slug-box');
907 if (box.hasClass('hidden')) {
908 box.fadeIn('fast', function () {
909 box.removeClass('hidden');
913 real_slug.val(new_slug);
914 $('#view-post-btn').show();
919 b.children('.cancel').click(function() {
920 $('#view-post-btn').show();
923 real_slug.val(revert_slug);
927 for ( i = 0; i < full.length; ++i ) {
928 if ( '%' == full.charAt(i) )
932 slug_value = ( c > full.length / 4 ) ? '' : full;
933 e.html('<input type="text" id="new-post-slug" value="'+slug_value+'" />').children('input').keypress(function(e) {
934 var key = e.keyCode || 0;
935 // on enter, just save the new slug, don't save the post
937 b.children('.save').click();
941 b.children('.cancel').click();
944 } ).keyup( function() {
945 real_slug.val(this.value);
949 if ( $editSlugWrap.length ) {
950 $editSlugWrap.on( 'click', function( event ) {
951 var $target = $( event.target );
953 if ( $target.is('#editable-post-name') || $target.hasClass('edit-slug') ) {
960 if ( typeof(wpWordCount) != 'undefined' ) {
961 $document.triggerHandler('wpcountwords', [ co.val() ]);
963 co.keyup( function(e) {
964 var k = e.keyCode || e.charCode;
969 if ( 13 == k || 8 == last || 46 == last )
970 $document.triggerHandler('wpcountwords', [ co.val() ]);
977 wptitlehint = function(id) {
980 var title = $('#' + id), titleprompt = $('#' + id + '-prompt-text');
982 if ( '' === title.val() )
983 titleprompt.removeClass('screen-reader-text');
985 titleprompt.click(function(){
986 $(this).addClass('screen-reader-text');
990 title.blur(function(){
991 if ( '' === this.value )
992 titleprompt.removeClass('screen-reader-text');
994 titleprompt.addClass('screen-reader-text');
995 }).keydown(function(e){
996 titleprompt.addClass('screen-reader-text');
1003 // Resize the visual and text editors
1005 var editor, offset, mce,
1006 $textarea = $('textarea#content'),
1007 $handle = $('#post-status-info'),
1008 $postdivrich = $('#postdivrich');
1010 // No point for touch devices
1011 if ( ! $textarea.length || 'ontouchstart' in window ) {
1012 // Hide the resize handle
1013 $('#content-resize-handle').hide();
1017 function dragging( event ) {
1018 if ( $postdivrich.hasClass( 'wp-editor-expand' ) ) {
1023 editor.theme.resizeTo( null, offset + event.pageY );
1025 $textarea.height( Math.max( 50, offset + event.pageY ) );
1028 event.preventDefault();
1031 function endDrag() {
1032 var height, toolbarHeight;
1034 if ( $postdivrich.hasClass( 'wp-editor-expand' ) ) {
1040 toolbarHeight = parseInt( $( '#wp-content-editor-container .mce-toolbar-grp' ).height(), 10 );
1042 if ( toolbarHeight < 10 || toolbarHeight > 200 ) {
1046 height = parseInt( $('#content_ifr').css('height'), 10 ) + toolbarHeight - 28;
1049 height = parseInt( $textarea.css('height'), 10 );
1052 $document.off( '.wp-editor-resize' );
1055 if ( height && height > 50 && height < 5000 ) {
1056 setUserSetting( 'ed_size', height );
1060 $handle.on( 'mousedown.wp-editor-resize', function( event ) {
1061 if ( typeof tinymce !== 'undefined' ) {
1062 editor = tinymce.get('content');
1065 if ( editor && ! editor.isHidden() ) {
1067 offset = $('#content_ifr').height() - event.pageY;
1070 offset = $textarea.height() - event.pageY;
1074 $document.on( 'mousemove.wp-editor-resize', dragging )
1075 .on( 'mouseup.wp-editor-resize mouseleave.wp-editor-resize', endDrag );
1077 event.preventDefault();
1078 }).on( 'mouseup.wp-editor-resize', endDrag );
1081 if ( typeof tinymce !== 'undefined' ) {
1082 // When changing post formats, change the editor body class
1083 $( '#post-formats-select input.post-format' ).on( 'change.set-editor-class', function() {
1084 var editor, body, format = this.id;
1086 if ( format && $( this ).prop( 'checked' ) && ( editor = tinymce.get( 'content' ) ) ) {
1087 body = editor.getBody();
1088 body.className = body.className.replace( /\bpost-format-[^ ]+/, '' );
1089 editor.dom.addClass( body, format == 'post-format-0' ? 'post-format-standard' : format );
1090 $( document ).trigger( 'editor-classchange' );