Skip to content
This repository was archived by the owner on Aug 15, 2022. It is now read-only.

Commit f2bae81

Browse files
committed
Change sticky toggle for proper post update.
Switch the functionality to handle multiple properties for update.
1 parent 15d5099 commit f2bae81

File tree

1 file changed

+9
-10
lines changed

1 file changed

+9
-10
lines changed

assets/js/rest-example-jquery.js

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -61,15 +61,15 @@ jQuery( function( $ ) {
6161
var titleCell = $( '<td/>' ).appendTo( row );
6262
$( '<a/>', {
6363
'href': post.link,
64-
text: post.title.rendered
64+
html: post.title.rendered
6565
} ).appendTo( titleCell );
6666

6767
// Post Author
6868
var author = users[ post.author.toString() ];
6969
var authorCell = $( '<td/>' ).appendTo( row );
7070
$( '<a/>', {
7171
'href': author.link,
72-
text: author.name
72+
html: author.name
7373
} ).appendTo( authorCell );
7474

7575
// Sticky
@@ -80,7 +80,11 @@ jQuery( function( $ ) {
8080
stickyInput.prop( 'checked', post.sticky );
8181

8282
stickyInput.on( 'change', function( evt ) {
83-
toggleSticky( post, stickyInput );
83+
stickyInput.prop( 'disabled', true );
84+
var props = {
85+
sticky: (! post.sticky)
86+
};
87+
updatePost( post, props );
8488
} );
8589

8690
return row;
@@ -139,20 +143,15 @@ jQuery( function( $ ) {
139143
} );
140144
};
141145

142-
// Toggles the sticky state of a post.
143-
var toggleSticky = function( post, checkbox ) {
144-
var sticky = ! post.sticky;
145-
checkbox.prop( 'disabled', true );
146+
var updatePost = function( post, props ) {
146147

147148
$.ajax( {
148149
url: screen_data.api_root + 'wp/v2/posts/' + post.id,
149150
method: 'POST',
150151
beforeSend: function( req ) {
151152
req.setRequestHeader( 'X-WP-Nonce', screen_data.api_nonce );
152153
},
153-
data: {
154-
'sticky': sticky
155-
},
154+
data: props,
156155
success: function( data ) {
157156
// Update the global state
158157
regeneratePost( data );

0 commit comments

Comments
 (0)