Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add live JS updates to post titles while waiting for selective refresh #43

Closed
westonruter opened this issue Mar 9, 2016 · 1 comment

Comments

Projects
None yet
2 participants
@westonruter
Copy link
Contributor

commented Mar 9, 2016

We can do instant previews of post titles by injecting the post title into the .entry-title via JS as a low-fidelity preview until we wait for the selective refresh response to return. This is similar to what has been implemented for blogname and blogdescription in 4.5.

@westonruter

This comment has been minimized.

Copy link
Contributor Author

commented Jul 11, 2016

This almost does it:

--- a/js/customize-post-field-partial.js
+++ b/js/customize-post-field-partial.js
@@ -41,6 +41,22 @@
        /**
         * @inheritdoc
         */
+       preparePlacement: function( placement ) {
+           var partial = this, setting = api( partial.settings()[0] ), a;
+           if ( 'post_title' === partial.params.field_id && setting ) {
+               a = placement.container.find( 'a' );
+               if ( a.length ) {
+                   a.text( setting().post_title );
+               } else {
+                   placement.container.text( setting().post_title );
+               }
+           }
+           api.previewPosts.Partial.prototype.preparePlacement.call( partial, placement );
+       },
+
+       /**
+        * @inheritdoc
+        */
        showControl: function() {
            var partial = this, settingId = partial.params.primarySetting;
            if ( ! settingId ) {

The problem is that preparePlacement isn't called when a selective refresh request is currently open, so it only does a live JS update for the first change.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.