1 /* global postL10n, ajaxurl, wpAjax, setPostThumbnailL10n, postboxes, pagenow, tinymce, alert, deleteUserSetting */ |
|
2 /* global theList:true, theExtraList:true, getUserSetting, setUserSetting, commentReply */ |
|
3 |
|
4 /** |
1 /** |
5 * Contains all dynamic functionality needed on post and term pages. |
2 * @file Contains all dynamic functionality needed on post and term pages. |
6 * |
3 * |
7 * @summary Control page and term functionality. |
4 * @output wp-admin/js/post.js |
8 */ |
5 */ |
9 |
6 |
10 var commentsBox, WPSetThumbnailHTML, WPSetThumbnailID, WPRemoveThumbnail, wptitlehint, makeSlugeditClickable, editPermalink; |
7 /* global postL10n, ajaxurl, wpAjax, setPostThumbnailL10n, postboxes, pagenow, tinymce, alert, deleteUserSetting */ |
|
8 /* global theList:true, theExtraList:true, getUserSetting, setUserSetting, commentReply, commentsBox */ |
|
9 /* global WPSetThumbnailHTML, wptitlehint */ |
|
10 |
11 // Backwards compatibility: prevent fatal errors. |
11 // Backwards compatibility: prevent fatal errors. |
12 makeSlugeditClickable = editPermalink = function(){}; |
12 window.makeSlugeditClickable = window.editPermalink = function(){}; |
13 |
13 |
14 // Make sure the wp object exists. |
14 // Make sure the wp object exists. |
15 window.wp = window.wp || {}; |
15 window.wp = window.wp || {}; |
16 |
16 |
17 ( function( $ ) { |
17 ( function( $ ) { |
22 * |
22 * |
23 * @type {{st: number, get: commentsBox.get, load: commentsBox.load}} |
23 * @type {{st: number, get: commentsBox.get, load: commentsBox.load}} |
24 * |
24 * |
25 * @namespace commentsBox |
25 * @namespace commentsBox |
26 */ |
26 */ |
27 commentsBox = { |
27 window.commentsBox = { |
28 // Comment offset to use when fetching new comments. |
28 // Comment offset to use when fetching new comments. |
29 st : 0, |
29 st : 0, |
30 |
30 |
31 /** |
31 /** |
32 * Fetch comments using AJAX and display them in the box. |
32 * Fetch comments using AJAX and display them in the box. |
|
33 * |
|
34 * @memberof commentsBox |
33 * |
35 * |
34 * @param {int} total Total number of comments for this post. |
36 * @param {int} total Total number of comments for this post. |
35 * @param {int} num Optional. Number of comments to fetch, defaults to 20. |
37 * @param {int} num Optional. Number of comments to fetch, defaults to 20. |
36 * @returns {boolean} Always returns false. |
38 * @returns {boolean} Always returns false. |
37 * |
|
38 * @memberof commentsBox |
|
39 */ |
39 */ |
40 get : function(total, num) { |
40 get : function(total, num) { |
41 var st = this.st, data; |
41 var st = this.st, data; |
42 if ( ! num ) |
42 if ( ! num ) |
43 num = 20; |
43 num = 20; |
106 * |
106 * |
107 * @param {string} html New HTML to be displayed in the content area of the postbox. |
107 * @param {string} html New HTML to be displayed in the content area of the postbox. |
108 * |
108 * |
109 * @global |
109 * @global |
110 */ |
110 */ |
111 WPSetThumbnailHTML = function(html){ |
111 window.WPSetThumbnailHTML = function(html){ |
112 $('.inside', '#postimagediv').html(html); |
112 $('.inside', '#postimagediv').html(html); |
113 }; |
113 }; |
114 |
114 |
115 /** |
115 /** |
116 * Set the Image ID of the Featured Image |
116 * Set the Image ID of the Featured Image |
117 * |
117 * |
118 * @param {int} id The post_id of the image to use as Featured Image. |
118 * @param {int} id The post_id of the image to use as Featured Image. |
119 * |
119 * |
120 * @global |
120 * @global |
121 */ |
121 */ |
122 WPSetThumbnailID = function(id){ |
122 window.WPSetThumbnailID = function(id){ |
123 var field = $('input[value="_thumbnail_id"]', '#list-table'); |
123 var field = $('input[value="_thumbnail_id"]', '#list-table'); |
124 if ( field.length > 0 ) { |
124 if ( field.length > 0 ) { |
125 $('#meta\\[' + field.attr('id').match(/[0-9]+/) + '\\]\\[value\\]').text(id); |
125 $('#meta\\[' + field.attr('id').match(/[0-9]+/) + '\\]\\[value\\]').text(id); |
126 } |
126 } |
127 }; |
127 }; |
131 * |
131 * |
132 * @param {string} nonce Nonce to use in the request. |
132 * @param {string} nonce Nonce to use in the request. |
133 * |
133 * |
134 * @global |
134 * @global |
135 */ |
135 */ |
136 WPRemoveThumbnail = function(nonce){ |
136 window.WPRemoveThumbnail = function(nonce){ |
137 $.post(ajaxurl, { |
137 $.post(ajaxurl, { |
138 action: 'set-post-thumbnail', post_id: $( '#post_ID' ).val(), thumbnail_id: -1, _ajax_nonce: nonce, cookie: encodeURIComponent( document.cookie ) |
138 action: 'set-post-thumbnail', post_id: $( '#post_ID' ).val(), thumbnail_id: -1, _ajax_nonce: nonce, cookie: encodeURIComponent( document.cookie ) |
139 }, |
139 }, |
140 /** |
140 /** |
141 * Handle server response |
141 * Handle server response |
660 if ( $('#postcustom').length ) { |
660 if ( $('#postcustom').length ) { |
661 $( '#the-list' ).wpList( { |
661 $( '#the-list' ).wpList( { |
662 /** |
662 /** |
663 * Add current post_ID to request to fetch custom fields |
663 * Add current post_ID to request to fetch custom fields |
664 * |
664 * |
|
665 * @ignore |
|
666 * |
665 * @param {Object} s Request object. |
667 * @param {Object} s Request object. |
666 * |
668 * |
667 * @returns {Object} Data modified with post_ID attached. |
669 * @returns {Object} Data modified with post_ID attached. |
668 */ |
670 */ |
669 addBefore: function( s ) { |
671 addBefore: function( s ) { |
670 s.data += '&post_id=' + $('#post_ID').val(); |
672 s.data += '&post_id=' + $('#post_ID').val(); |
671 return s; |
673 return s; |
672 }, |
674 }, |
673 /** |
675 /** |
674 * Show the listing of custom fields after fetching. |
676 * Show the listing of custom fields after fetching. |
|
677 * |
|
678 * @ignore |
675 */ |
679 */ |
676 addAfter: function() { |
680 addAfter: function() { |
677 $('table#list-table').show(); |
681 $('table#list-table').show(); |
678 } |
682 } |
679 }); |
683 }); |
686 stamp = $('#timestamp').html(); |
690 stamp = $('#timestamp').html(); |
687 visibility = $('#post-visibility-display').html(); |
691 visibility = $('#post-visibility-display').html(); |
688 |
692 |
689 /** |
693 /** |
690 * When the visibility of a post changes sub-options should be shown or hidden. |
694 * When the visibility of a post changes sub-options should be shown or hidden. |
|
695 * |
|
696 * @ignore |
691 * |
697 * |
692 * @returns void |
698 * @returns void |
693 */ |
699 */ |
694 updateVisibility = function() { |
700 updateVisibility = function() { |
695 // Show sticky for public posts. |
701 // Show sticky for public posts. |
785 if ( postStatus.is(':hidden') ) |
793 if ( postStatus.is(':hidden') ) |
786 $('#misc-publishing-actions .edit-post-status').show(); |
794 $('#misc-publishing-actions .edit-post-status').show(); |
787 } |
795 } |
788 |
796 |
789 // Update "Status:" to currently selected status. |
797 // Update "Status:" to currently selected status. |
790 $('#post-status-display').html($('option:selected', postStatus).text()); |
798 $('#post-status-display').text( |
|
799 wp.sanitize.stripTagsAndEncodeText( $('option:selected', postStatus).text() ) // Remove any potential tags from post status text. |
|
800 ); |
791 |
801 |
792 // Show or hide the "Save Draft" button. |
802 // Show or hide the "Save Draft" button. |
793 if ( $('option:selected', postStatus).val() == 'private' || $('option:selected', postStatus).val() == 'publish' ) { |
803 if ( $('option:selected', postStatus).val() == 'private' || $('option:selected', postStatus).val() == 'publish' ) { |
794 $('#save-post').hide(); |
804 $('#save-post').hide(); |
795 } else { |
805 } else { |
1031 $( '#titlediv' ).on( 'click', '.edit-slug', function() { |
1040 $( '#titlediv' ).on( 'click', '.edit-slug', function() { |
1032 editPermalink(); |
1041 editPermalink(); |
1033 }); |
1042 }); |
1034 |
1043 |
1035 /** |
1044 /** |
1036 * Add screen reader text to the title prompt when needed. |
1045 * Adds screen reader text to the title label when needed. |
1037 * |
1046 * |
1038 * @summary Title screen reader text handler. |
1047 * Use the 'screen-reader-text' class to emulate a placeholder attribute |
|
1048 * and hide the label when entering a value. |
1039 * |
1049 * |
1040 * @param {string} id Optional. HTML ID to add the screen reader helper text to. |
1050 * @param {string} id Optional. HTML ID to add the screen reader helper text to. |
1041 * |
1051 * |
1042 * @global |
1052 * @global |
1043 * |
1053 * |
1044 * @returns void |
1054 * @returns void |
1045 */ |
1055 */ |
1046 wptitlehint = function(id) { |
1056 window.wptitlehint = function( id ) { |
1047 id = id || 'title'; |
1057 id = id || 'title'; |
1048 |
1058 |
1049 var title = $('#' + id), titleprompt = $('#' + id + '-prompt-text'); |
1059 var title = $( '#' + id ), titleprompt = $( '#' + id + '-prompt-text' ); |
1050 |
1060 |
1051 if ( '' === title.val() ) |
1061 if ( '' === title.val() ) { |
1052 titleprompt.removeClass('screen-reader-text'); |
1062 titleprompt.removeClass( 'screen-reader-text' ); |
1053 |
1063 } |
1054 titleprompt.click(function(){ |
1064 |
1055 $(this).addClass('screen-reader-text'); |
1065 title.on( 'input', function() { |
1056 title.focus(); |
1066 if ( '' === this.value ) { |
1057 }); |
1067 titleprompt.removeClass( 'screen-reader-text' ); |
1058 |
1068 return; |
1059 title.blur(function(){ |
1069 } |
1060 if ( '' === this.value ) |
1070 |
1061 titleprompt.removeClass('screen-reader-text'); |
1071 titleprompt.addClass( 'screen-reader-text' ); |
1062 }).focus(function(){ |
1072 } ); |
1063 titleprompt.addClass('screen-reader-text'); |
|
1064 }).keydown(function(e){ |
|
1065 titleprompt.addClass('screen-reader-text'); |
|
1066 $(this).unbind(e); |
|
1067 }); |
|
1068 }; |
1073 }; |
1069 |
1074 |
1070 wptitlehint(); |
1075 wptitlehint(); |
1071 |
1076 |
1072 // Resize the WYSIWYG and plain text editors. |
1077 // Resize the WYSIWYG and plain text editors. |