{"action":"created","comment":{"url":"https://api.github.com/repos/xwp/wp-customize-partial-refresh/pulls/comments/49501312","id":49501312,"diff_hunk":"@@ -0,0 +1,128 @@\n+/* global jQuery, _customizePartialRefreshSettings, JSON, _ */\n+/* exported customizePartialRefreshSettings */\n+var customizePartialRefreshSettings = ( function( $ ) {\n+\t'use strict';\n+\n+\tvar self, api = wp.customize;\n+\n+\tself = {\n+\t\tsetting: null\n+\t};\n+\n+\t$.extend( self, _customizePartialRefreshSettings );\n+\n+\t/**\n+\t * Inject the functionality.\n+\t */\n+\tself.init = function() {\n+\t\tapi.bind( 'ready', function() {\n+\t\t\tself.onChangeSetting();\n+\t\t} );\n+\n+\t\tapi.bind( 'setting-partial', function( response ) {\n+\t\t\tvar that = $( 'iframe' ).contents(),\n+\t\t\t\tvalue = $.trim( response );\n+\n+\t\t\t$( self.setting.selector, that ).html( value );","path":"js/customize-partial-refresh-settings.js","position":26,"original_position":26,"commit_id":"f0d5de431870f09742352d0f755f5a78ad14b3f5","original_commit_id":"f0d5de431870f09742352d0f755f5a78ad14b3f5","user":{"login":"westonruter","id":134745,"avatar_url":"https://avatars.githubusercontent.com/u/134745?v=3","gravatar_id":"","url":"https://api.github.com/users/westonruter","html_url":"https://github.com/westonruter","followers_url":"https://api.github.com/users/westonruter/followers","following_url":"https://api.github.com/users/westonruter/following{/other_user}","gists_url":"https://api.github.com/users/westonruter/gists{/gist_id}","starred_url":"https://api.github.com/users/westonruter/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/westonruter/subscriptions","organizations_url":"https://api.github.com/users/westonruter/orgs","repos_url":"https://api.github.com/users/westonruter/repos","events_url":"https://api.github.com/users/westonruter/events{/privacy}","received_events_url":"https://api.github.com/users/westonruter/received_events","type":"User","site_admin":false},"body":"If the given selector matches no elements, then maybe this should also be a scenario where the preview refreshes?\r\n\r\nIn the case of sending messages, the preview would then need to do `wp.customize.preview.send( 'refresh' )` if it can't find the given selector, if the pane is doing something like this:\r\n\r\n```js\r\nwp.customize.previewer.send( 'selective-refresh', selector, response );\r\n```\r\n\r\nThe preview can then do:\r\n\r\n```js\r\nwp.customize.preview.bind( 'selective-refresh', function( selector, response ) {\r\n    var elements = jQuery( selector );\r\n    if ( elements.length ) {\r\n        elements.html( jQuery.trim( response ) );\r\n    } else {\r\n        wp.customize.preview.send( 'refresh' )\r\n    }\r\n} );\r\n```","created_at":"2016-01-12T19:28:55Z","updated_at":"2016-01-12T19:28:55Z","html_url":"https://github.com/xwp/wp-customize-partial-refresh/pull/17#discussion_r49501312","pull_request_url":"https://api.github.com/repos/xwp/wp-customize-partial-refresh/pulls/17","_links":{"self":{"href":"https://api.github.com/repos/xwp/wp-customize-partial-refresh/pulls/comments/49501312"},"html":{"href":"https://github.com/xwp/wp-customize-partial-refresh/pull/17#discussion_r49501312"},"pull_request":{"href":"https://api.github.com/repos/xwp/wp-customize-partial-refresh/pulls/17"}}},"pull_request":{"url":"https://api.github.com/repos/xwp/wp-customize-partial-refresh/pulls/17","id":50912637,"html_url":"https://github.com/xwp/wp-customize-partial-refresh/pull/17","diff_url":"https://github.com/xwp/wp-customize-partial-refresh/pull/17.diff","patch_url":"https://github.com/xwp/wp-customize-partial-refresh/pull/17.patch","issue_url":"https://api.github.com/repos/xwp/wp-customize-partial-refresh/issues/17","number":17,"state":"open","locked":false,"title":"Introduce framework for registering new partials","user":{"login":"valendesigns","id":62798,"avatar_url":"https://avatars.githubusercontent.com/u/62798?v=3","gravatar_id":"","url":"https://api.github.com/users/valendesigns","html_url":"https://github.com/valendesigns","followers_url":"https://api.github.com/users/valendesigns/followers","following_url":"https://api.github.com/users/valendesigns/following{/other_user}","gists_url":"https://api.github.com/users/valendesigns/gists{/gist_id}","starred_url":"https://api.github.com/users/valendesigns/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/valendesigns/subscriptions","organizations_url":"https://api.github.com/users/valendesigns/orgs","repos_url":"https://api.github.com/users/valendesigns/repos","events_url":"https://api.github.com/users/valendesigns/events{/privacy}","received_events_url":"https://api.github.com/users/valendesigns/received_events","type":"User","site_admin":false},"body":"The current implementation introduces the `partialRefresh` transport. When used in combination with the setting `selector` will essentially filter the PHP output in a similar fashion to the JavaScript, except through initiating a server side Ajax request for the value.\r\n\r\nThis request is ran through two new filters that let you change the markup displayed inside the selector. The first is a global filter for all selectors `customize_partial_refresh_settings`, the second is to directly filter the control you want without checking it exists using `customize_partial_refresh_{$setting->id}` making it easier to separate your markup functions.\r\n\r\nHere are very simple examples of how you filter `blogname`.\r\n\r\n```PHP\r\nadd_filter( 'customize_partial_refresh_settings', function ( $partial, $setting ) {\r\n\tif ( 'blogname' === $setting->id ) {\r\n\t\t$value = $setting->post_value();\r\n\t\tif ( ! empty( $value ) ) {\r\n\t\t\t$partial = $value;\r\n\t\t}\r\n\t}\r\n\treturn $partial;\r\n}, 10, 2 );\r\n```\r\n\r\n```PHP\r\nadd_filter( 'customize_partial_refresh_blogname', function ( $partial, $setting ) {\r\n\t$value = $setting->post_value();\r\n\tif ( ! empty( $value ) ) {\r\n\t\t$partial = $value;\r\n\t}\r\n\treturn $partial;\r\n}, 10, 2 );\r\n```\r\n\r\nYou add support to your theme like so:\r\n```PHP\r\nadd_theme_support( 'customize-partial-refresh', array(\r\n\t'settings'\r\n) );\r\n```\r\n\r\n```PHP\r\n$wp_customize->get_setting( 'blogname' )->transport = 'partialRefresh';\r\n$wp_customize->get_setting( 'blogname' )->selector = '.site-title a';\r\n```\r\n\r\nIt's important to note four things. First, a successful Ajax return value is injected into the selector with JavaScript using jQuery's `.html()` function. Second, even though the Ajax requests are debouncing and working as expected, if you rapid fire text changes they tend to make the preview out of sync. So the initial ajax request should have a timeout on it to slow down the responsiveness by maybe 250 milliseconds, which should allow the requests to properly debounce for things so trivial as a text chance. Third, when the return value is `null` the preview pane will do a full refresh to try and resolve potential Ajax errors, or when a refresh should add or remove an entire sections like a sidebar because there are no widgets. The last, is that since this is not included in the core you can't add `selector` support in the tradition way. You would expect this would work, but it doesn't because `selector` is not a public class member.\r\n\r\n__No Good__\r\n```PHP\r\n$wp_customize->add_setting( 'color_scheme', array(\r\n\t'default'           => 'default',\r\n\t'sanitize_callback' => 'twentyfifteen_sanitize_color_scheme',\r\n\t'transport'         => 'partialRefresh',\r\n\t'selector'          => '#twentyfifteen-color-scheme-css',\r\n) );\r\n```\r\n\r\n__Good__\r\n```PHP\r\n$wp_customize->add_setting( 'color_scheme', array(\r\n\t'default'           => 'default',\r\n\t'sanitize_callback' => 'twentyfifteen_sanitize_color_scheme',\r\n\t'transport'         => 'partialRefresh',\r\n) );\r\n$wp_customize->get_setting( 'color_scheme' )->selector = '#twentyfifteen-color-scheme-css';\r\n```\r\n\r\nI've added unit tests that cover all of the new code, including Ajax requests that result in errors. I believe what is completed so far is a good _phase 1_. The next _phase_ should be making it work with widgets. Please share your ideas and/or concerns with this direction.\r\n\r\nCloses #11","created_at":"2015-11-17T07:26:19Z","updated_at":"2016-01-12T19:28:55Z","closed_at":null,"merged_at":null,"merge_commit_sha":"28b1ec1798023dab80e87f2d9c8eaedd447897d6","assignee":{"login":"valendesigns","id":62798,"avatar_url":"https://avatars.githubusercontent.com/u/62798?v=3","gravatar_id":"","url":"https://api.github.com/users/valendesigns","html_url":"https://github.com/valendesigns","followers_url":"https://api.github.com/users/valendesigns/followers","following_url":"https://api.github.com/users/valendesigns/following{/other_user}","gists_url":"https://api.github.com/users/valendesigns/gists{/gist_id}","starred_url":"https://api.github.com/users/valendesigns/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/valendesigns/subscriptions","organizations_url":"https://api.github.com/users/valendesigns/orgs","repos_url":"https://api.github.com/users/valendesigns/repos","events_url":"https://api.github.com/users/valendesigns/events{/privacy}","received_events_url":"https://api.github.com/users/valendesigns/received_events","type":"User","site_admin":false},"milestone":null,"commits_url":"https://api.github.com/repos/xwp/wp-customize-partial-refresh/pulls/17/commits","review_comments_url":"https://api.github.com/repos/xwp/wp-customize-partial-refresh/pulls/17/comments","review_comment_url":"https://api.github.com/repos/xwp/wp-customize-partial-refresh/pulls/comments{/number}","comments_url":"https://api.github.com/repos/xwp/wp-customize-partial-refresh/issues/17/comments","statuses_url":"https://api.github.com/repos/xwp/wp-customize-partial-refresh/statuses/f0d5de431870f09742352d0f755f5a78ad14b3f5","head":{"label":"xwp:feature/framework","ref":"feature/framework","sha":"f0d5de431870f09742352d0f755f5a78ad14b3f5","user":{"login":"xwp","id":9003139,"avatar_url":"https://avatars.githubusercontent.com/u/9003139?v=3","gravatar_id":"","url":"https://api.github.com/users/xwp","html_url":"https://github.com/xwp","followers_url":"https://api.github.com/users/xwp/followers","following_url":"https://api.github.com/users/xwp/following{/other_user}","gists_url":"https://api.github.com/users/xwp/gists{/gist_id}","starred_url":"https://api.github.com/users/xwp/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/xwp/subscriptions","organizations_url":"https://api.github.com/users/xwp/orgs","repos_url":"https://api.github.com/users/xwp/repos","events_url":"https://api.github.com/users/xwp/events{/privacy}","received_events_url":"https://api.github.com/users/xwp/received_events","type":"Organization","site_admin":false},"repo":{"id":28034966,"name":"wp-customize-partial-refresh","full_name":"xwp/wp-customize-partial-refresh","owner":{"login":"xwp","id":9003139,"avatar_url":"https://avatars.githubusercontent.com/u/9003139?v=3","gravatar_id":"","url":"https://api.github.com/users/xwp","html_url":"https://github.com/xwp","followers_url":"https://api.github.com/users/xwp/followers","following_url":"https://api.github.com/users/xwp/following{/other_user}","gists_url":"https://api.github.com/users/xwp/gists{/gist_id}","starred_url":"https://api.github.com/users/xwp/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/xwp/subscriptions","organizations_url":"https://api.github.com/users/xwp/orgs","repos_url":"https://api.github.com/users/xwp/repos","events_url":"https://api.github.com/users/xwp/events{/privacy}","received_events_url":"https://api.github.com/users/xwp/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/xwp/wp-customize-partial-refresh","description":"Customize Partial Refresh plugin for WordPress","fork":false,"url":"https://api.github.com/repos/xwp/wp-customize-partial-refresh","forks_url":"https://api.github.com/repos/xwp/wp-customize-partial-refresh/forks","keys_url":"https://api.github.com/repos/xwp/wp-customize-partial-refresh/keys{/key_id}","collaborators_url":"https://api.github.com/repos/xwp/wp-customize-partial-refresh/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/xwp/wp-customize-partial-refresh/teams","hooks_url":"https://api.github.com/repos/xwp/wp-customize-partial-refresh/hooks","issue_events_url":"https://api.github.com/repos/xwp/wp-customize-partial-refresh/issues/events{/number}","events_url":"https://api.github.com/repos/xwp/wp-customize-partial-refresh/events","assignees_url":"https://api.github.com/repos/xwp/wp-customize-partial-refresh/assignees{/user}","branches_url":"https://api.github.com/repos/xwp/wp-customize-partial-refresh/branches{/branch}","tags_url":"https://api.github.com/repos/xwp/wp-customize-partial-refresh/tags","blobs_url":"https://api.github.com/repos/xwp/wp-customize-partial-refresh/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/xwp/wp-customize-partial-refresh/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/xwp/wp-customize-partial-refresh/git/refs{/sha}","trees_url":"https://api.github.com/repos/xwp/wp-customize-partial-refresh/git/trees{/sha}","statuses_url":"https://api.github.com/repos/xwp/wp-customize-partial-refresh/statuses/{sha}","languages_url":"https://api.github.com/repos/xwp/wp-customize-partial-refresh/languages","stargazers_url":"https://api.github.com/repos/xwp/wp-customize-partial-refresh/stargazers","contributors_url":"https://api.github.com/repos/xwp/wp-customize-partial-refresh/contributors","subscribers_url":"https://api.github.com/repos/xwp/wp-customize-partial-refresh/subscribers","subscription_url":"https://api.github.com/repos/xwp/wp-customize-partial-refresh/subscription","commits_url":"https://api.github.com/repos/xwp/wp-customize-partial-refresh/commits{/sha}","git_commits_url":"https://api.github.com/repos/xwp/wp-customize-partial-refresh/git/commits{/sha}","comments_url":"https://api.github.com/repos/xwp/wp-customize-partial-refresh/comments{/number}","issue_comment_url":"https://api.github.com/repos/xwp/wp-customize-partial-refresh/issues/comments{/number}","contents_url":"https://api.github.com/repos/xwp/wp-customize-partial-refresh/contents/{+path}","compare_url":"https://api.github.com/repos/xwp/wp-customize-partial-refresh/compare/{base}...{head}","merges_url":"https://api.github.com/repos/xwp/wp-customize-partial-refresh/merges","archive_url":"https://api.github.com/repos/xwp/wp-customize-partial-refresh/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/xwp/wp-customize-partial-refresh/downloads","issues_url":"https://api.github.com/repos/xwp/wp-customize-partial-refresh/issues{/number}","pulls_url":"https://api.github.com/repos/xwp/wp-customize-partial-refresh/pulls{/number}","milestones_url":"https://api.github.com/repos/xwp/wp-customize-partial-refresh/milestones{/number}","notifications_url":"https://api.github.com/repos/xwp/wp-customize-partial-refresh/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/xwp/wp-customize-partial-refresh/labels{/name}","releases_url":"https://api.github.com/repos/xwp/wp-customize-partial-refresh/releases{/id}","created_at":"2014-12-15T12:05:25Z","updated_at":"2015-10-31T14:44:51Z","pushed_at":"2016-01-12T05:44:07Z","git_url":"git://github.com/xwp/wp-customize-partial-refresh.git","ssh_url":"git@github.com:xwp/wp-customize-partial-refresh.git","clone_url":"https://github.com/xwp/wp-customize-partial-refresh.git","svn_url":"https://github.com/xwp/wp-customize-partial-refresh","homepage":"https://wordpress.org/plugins/customize-partial-refresh/","size":80,"stargazers_count":5,"watchers_count":5,"language":"PHP","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":1,"mirror_url":null,"open_issues_count":3,"forks":1,"open_issues":3,"watchers":5,"default_branch":"master"}},"base":{"label":"xwp:master","ref":"master","sha":"e1d4d3ddc4ca2b7c8c9febbe6646482ffa6075f9","user":{"login":"xwp","id":9003139,"avatar_url":"https://avatars.githubusercontent.com/u/9003139?v=3","gravatar_id":"","url":"https://api.github.com/users/xwp","html_url":"https://github.com/xwp","followers_url":"https://api.github.com/users/xwp/followers","following_url":"https://api.github.com/users/xwp/following{/other_user}","gists_url":"https://api.github.com/users/xwp/gists{/gist_id}","starred_url":"https://api.github.com/users/xwp/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/xwp/subscriptions","organizations_url":"https://api.github.com/users/xwp/orgs","repos_url":"https://api.github.com/users/xwp/repos","events_url":"https://api.github.com/users/xwp/events{/privacy}","received_events_url":"https://api.github.com/users/xwp/received_events","type":"Organization","site_admin":false},"repo":{"id":28034966,"name":"wp-customize-partial-refresh","full_name":"xwp/wp-customize-partial-refresh","owner":{"login":"xwp","id":9003139,"avatar_url":"https://avatars.githubusercontent.com/u/9003139?v=3","gravatar_id":"","url":"https://api.github.com/users/xwp","html_url":"https://github.com/xwp","followers_url":"https://api.github.com/users/xwp/followers","following_url":"https://api.github.com/users/xwp/following{/other_user}","gists_url":"https://api.github.com/users/xwp/gists{/gist_id}","starred_url":"https://api.github.com/users/xwp/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/xwp/subscriptions","organizations_url":"https://api.github.com/users/xwp/orgs","repos_url":"https://api.github.com/users/xwp/repos","events_url":"https://api.github.com/users/xwp/events{/privacy}","received_events_url":"https://api.github.com/users/xwp/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/xwp/wp-customize-partial-refresh","description":"Customize Partial Refresh plugin for WordPress","fork":false,"url":"https://api.github.com/repos/xwp/wp-customize-partial-refresh","forks_url":"https://api.github.com/repos/xwp/wp-customize-partial-refresh/forks","keys_url":"https://api.github.com/repos/xwp/wp-customize-partial-refresh/keys{/key_id}","collaborators_url":"https://api.github.com/repos/xwp/wp-customize-partial-refresh/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/xwp/wp-customize-partial-refresh/teams","hooks_url":"https://api.github.com/repos/xwp/wp-customize-partial-refresh/hooks","issue_events_url":"https://api.github.com/repos/xwp/wp-customize-partial-refresh/issues/events{/number}","events_url":"https://api.github.com/repos/xwp/wp-customize-partial-refresh/events","assignees_url":"https://api.github.com/repos/xwp/wp-customize-partial-refresh/assignees{/user}","branches_url":"https://api.github.com/repos/xwp/wp-customize-partial-refresh/branches{/branch}","tags_url":"https://api.github.com/repos/xwp/wp-customize-partial-refresh/tags","blobs_url":"https://api.github.com/repos/xwp/wp-customize-partial-refresh/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/xwp/wp-customize-partial-refresh/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/xwp/wp-customize-partial-refresh/git/refs{/sha}","trees_url":"https://api.github.com/repos/xwp/wp-customize-partial-refresh/git/trees{/sha}","statuses_url":"https://api.github.com/repos/xwp/wp-customize-partial-refresh/statuses/{sha}","languages_url":"https://api.github.com/repos/xwp/wp-customize-partial-refresh/languages","stargazers_url":"https://api.github.com/repos/xwp/wp-customize-partial-refresh/stargazers","contributors_url":"https://api.github.com/repos/xwp/wp-customize-partial-refresh/contributors","subscribers_url":"https://api.github.com/repos/xwp/wp-customize-partial-refresh/subscribers","subscription_url":"https://api.github.com/repos/xwp/wp-customize-partial-refresh/subscription","commits_url":"https://api.github.com/repos/xwp/wp-customize-partial-refresh/commits{/sha}","git_commits_url":"https://api.github.com/repos/xwp/wp-customize-partial-refresh/git/commits{/sha}","comments_url":"https://api.github.com/repos/xwp/wp-customize-partial-refresh/comments{/number}","issue_comment_url":"https://api.github.com/repos/xwp/wp-customize-partial-refresh/issues/comments{/number}","contents_url":"https://api.github.com/repos/xwp/wp-customize-partial-refresh/contents/{+path}","compare_url":"https://api.github.com/repos/xwp/wp-customize-partial-refresh/compare/{base}...{head}","merges_url":"https://api.github.com/repos/xwp/wp-customize-partial-refresh/merges","archive_url":"https://api.github.com/repos/xwp/wp-customize-partial-refresh/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/xwp/wp-customize-partial-refresh/downloads","issues_url":"https://api.github.com/repos/xwp/wp-customize-partial-refresh/issues{/number}","pulls_url":"https://api.github.com/repos/xwp/wp-customize-partial-refresh/pulls{/number}","milestones_url":"https://api.github.com/repos/xwp/wp-customize-partial-refresh/milestones{/number}","notifications_url":"https://api.github.com/repos/xwp/wp-customize-partial-refresh/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/xwp/wp-customize-partial-refresh/labels{/name}","releases_url":"https://api.github.com/repos/xwp/wp-customize-partial-refresh/releases{/id}","created_at":"2014-12-15T12:05:25Z","updated_at":"2015-10-31T14:44:51Z","pushed_at":"2016-01-12T05:44:07Z","git_url":"git://github.com/xwp/wp-customize-partial-refresh.git","ssh_url":"git@github.com:xwp/wp-customize-partial-refresh.git","clone_url":"https://github.com/xwp/wp-customize-partial-refresh.git","svn_url":"https://github.com/xwp/wp-customize-partial-refresh","homepage":"https://wordpress.org/plugins/customize-partial-refresh/","size":80,"stargazers_count":5,"watchers_count":5,"language":"PHP","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":1,"mirror_url":null,"open_issues_count":3,"forks":1,"open_issues":3,"watchers":5,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/xwp/wp-customize-partial-refresh/pulls/17"},"html":{"href":"https://github.com/xwp/wp-customize-partial-refresh/pull/17"},"issue":{"href":"https://api.github.com/repos/xwp/wp-customize-partial-refresh/issues/17"},"comments":{"href":"https://api.github.com/repos/xwp/wp-customize-partial-refresh/issues/17/comments"},"review_comments":{"href":"https://api.github.com/repos/xwp/wp-customize-partial-refresh/pulls/17/comments"},"review_comment":{"href":"https://api.github.com/repos/xwp/wp-customize-partial-refresh/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/xwp/wp-customize-partial-refresh/pulls/17/commits"},"statuses":{"href":"https://api.github.com/repos/xwp/wp-customize-partial-refresh/statuses/f0d5de431870f09742352d0f755f5a78ad14b3f5"}}}}