Skip to content
This repository has been archived by the owner on Dec 16, 2022. It is now read-only.

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

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

Comments

@westonruter
Copy link
Contributor

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
Copy link
Contributor Author

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 subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants