[wp-trac] [WordPress Trac] #27993: Support for contexts in the Customizer

WordPress Trac noreply at wordpress.org
Mon Apr 28 22:39:12 UTC 2014


#27993: Support for contexts in the Customizer
-----------------------------+-----------------------------
 Reporter:  danielbachhuber  |       Owner:
     Type:  enhancement      |      Status:  new
 Priority:  normal           |   Milestone:  Future Release
Component:  Appearance       |     Version:
 Severity:  normal           |  Resolution:
 Keywords:  needs-patch      |     Focuses:
-----------------------------+-----------------------------

Comment (by westonruter):

 Yes. Love this. It could be as simple as the Customizer Section or
 Customizer Control taking a callback argument that returns `true` or
 `false` based on whether or not it is relevant to the currently-previewed
 URL. Each section and control could be iterated over in the preview, and
 the callbacks could be fired and then exported to the parent customizer
 frame which in turn would toggle the visibility of the respective Sections
 and Controls. (We may want to use the Customizer Setting instead of the
 Customizer Control for attaching these context callbacks, as I believe
 this would more easily facilitate dynamically-created Controls since the
 settings are what get POSTed to the preview, not the controls.)

 Just to note that the Widget Customizer takes this same approach of
 passing upstream the context (which `dynamic_sidebar()` calls are used at
 the previewed URL), but it's now using `postMessage` passing instead of
 doing direct cross-frame communication. We were using cross-frame
 communication initially and I never encountered a problem with cross-
 domain security (since the previewed is rendered via `document.write()`),
 but just to be safe we used the message passing system that the Customizer
 makes available.

 == IFRAME: `customize-preview-widgets.js` ==

 {{{
 this.preview.bind( 'active', function() {
         self.preview.send( 'rendered-sidebars', self.renderedSidebars );
         self.preview.send( 'rendered-widgets', self.renderedWidgets );
 } );
 }}}

 == Customizer parent frame: `customize-widgets.js` ==

 {{{
 // Update widget control to indicate whether it is currently rendered
 api.Widgets.Previewer.bind( 'rendered-widgets', function( renderedWidgets
 ) {
         var isRendered = !! renderedWidgets[self.params.widget_id];
         self.container.toggleClass( 'widget-rendered', isRendered );
 } );

 /* ... */

 // Update the model with whether or not the sidebar is rendered
 api.Widgets.Previewer.bind( 'rendered-sidebars', function(
 renderedSidebars ) {
         var isRendered = !! renderedSidebars[self.params.sidebar_id];
         registeredSidebar.set( 'is_rendered', isRendered );
 } );
 }}}

--
Ticket URL: <https://core.trac.wordpress.org/ticket/27993#comment:5>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list