Widget Customizer: Use postMessage to highlight widgets in preview or sections/controls in Customizer.
fixes #27622. Built from https://develop.svn.wordpress.org/trunk@27892 git-svn-id: http://core.svn.wordpress.org/trunk@27723 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
@@ -27,6 +27,8 @@
|
||||
self.preview.send( 'rendered-sidebars', self.renderedSidebars ); // @todo Only send array of IDs
|
||||
self.preview.send( 'rendered-widgets', self.renderedWidgets ); // @todo Only send array of IDs
|
||||
} );
|
||||
|
||||
this.preview.bind( 'highlight-widget', self.highlightWidget );
|
||||
},
|
||||
|
||||
/**
|
||||
@@ -58,31 +60,34 @@
|
||||
},
|
||||
|
||||
/**
|
||||
* Obtain a rendered widget element. Assumes standard practice of using
|
||||
* the widget ID as the ID for the DOM element. To eliminate this
|
||||
* assumption, additional data-* attributes would need to be injected
|
||||
* onto the rendered widget root element.
|
||||
* Highlight the widget on widget updates or widget control mouse overs.
|
||||
*
|
||||
* @param {String} widget_id
|
||||
* @return {jQuery}
|
||||
* @param {string} widgetId ID of the widget.
|
||||
*/
|
||||
getWidgetElement: function ( widget_id ) {
|
||||
return $( '#' + widget_id );
|
||||
highlightWidget: function( widgetId ) {
|
||||
var $body = $( document.body ),
|
||||
$widget = $( '#' + widgetId );
|
||||
|
||||
$body.find( '.widget-customizer-highlighted-widget' ).removeClass( 'widget-customizer-highlighted-widget' );
|
||||
|
||||
$widget.addClass( 'widget-customizer-highlighted-widget' );
|
||||
setTimeout( function () {
|
||||
$widget.removeClass( 'widget-customizer-highlighted-widget' );
|
||||
}, 500 );
|
||||
},
|
||||
|
||||
/**
|
||||
*
|
||||
* Show a title and highlight widgets on hover. On shift+clicking
|
||||
* focus the widget control.
|
||||
*/
|
||||
highlightControls: function() {
|
||||
var selector = this.widgetSelectors.join(',');
|
||||
var self = this,
|
||||
selector = this.widgetSelectors.join(',');
|
||||
|
||||
$(selector).attr( 'title', this.l10n.widgetTooltip );
|
||||
|
||||
$(document).on( 'mouseenter', selector, function () {
|
||||
var control = parent.WidgetCustomizer.getWidgetFormControlForWidget( $(this).prop('id') );
|
||||
if ( control ) {
|
||||
control.highlightSectionAndControl();
|
||||
}
|
||||
self.preview.send( 'highlight-widget-control', $( this ).prop( 'id' ) );
|
||||
});
|
||||
|
||||
// Open expand the widget control when shift+clicking the widget element
|
||||
@@ -91,10 +96,8 @@
|
||||
return;
|
||||
}
|
||||
e.preventDefault();
|
||||
var control = parent.WidgetCustomizer.getWidgetFormControlForWidget( $(this).prop('id') );
|
||||
if ( control ) {
|
||||
control.focus();
|
||||
}
|
||||
|
||||
self.preview.send( 'focus-widget-control', $( this ).prop( 'id' ) );
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
@@ -1 +1 @@
|
||||
!function(a,b){if(b&&b.customize){var c,d=b.customize;d.WidgetCustomizerPreview={renderedSidebars:{},renderedWidgets:{},registeredSidebars:[],registeredWidgets:{},widgetSelectors:[],preview:null,l10n:{},init:function(){var a=this;this.buildWidgetSelectors(),this.highlightControls(),this.preview.bind("active",function(){a.preview.send("rendered-sidebars",a.renderedSidebars),a.preview.send("rendered-widgets",a.renderedWidgets)})},buildWidgetSelectors:function(){var b=this;a.each(this.registeredSidebars,function(c,d){var e,f,g,h=[d.before_widget.replace("%1$s","").replace("%2$s",""),d.before_title,d.after_title,d.after_widget].join("");e=a(h),f=e.prop("tagName"),g=e.prop("className").replace(/^\s+|\s+$/g,""),g&&(f+="."+g.split(/\s+/).join(".")),b.widgetSelectors.push(f)})},getWidgetElement:function(b){return a("#"+b)},highlightControls:function(){var b=this.widgetSelectors.join(",");a(b).attr("title",this.l10n.widgetTooltip),a(document).on("mouseenter",b,function(){var b=parent.WidgetCustomizer.getWidgetFormControlForWidget(a(this).prop("id"));b&&b.highlightSectionAndControl()}),a(document).on("click",b,function(b){if(b.shiftKey){b.preventDefault();var c=parent.WidgetCustomizer.getWidgetFormControlForWidget(a(this).prop("id"));c&&c.focus()}})}},c=d.Preview,d.Preview=c.extend({initialize:function(a,b){d.WidgetCustomizerPreview.preview=this,c.prototype.initialize.call(this,a,b)}}),a(function(){var b=window._wpWidgetCustomizerPreviewSettings;b&&(a.extend(d.WidgetCustomizerPreview,b),d.WidgetCustomizerPreview.init())})}}(jQuery,window.wp);
|
||||
!function(a,b){if(b&&b.customize){var c,d=b.customize;d.WidgetCustomizerPreview={renderedSidebars:{},renderedWidgets:{},registeredSidebars:[],registeredWidgets:{},widgetSelectors:[],preview:null,l10n:{},init:function(){var a=this;this.buildWidgetSelectors(),this.highlightControls(),this.preview.bind("active",function(){a.preview.send("rendered-sidebars",a.renderedSidebars),a.preview.send("rendered-widgets",a.renderedWidgets)}),this.preview.bind("highlight-widget",a.highlightWidget)},buildWidgetSelectors:function(){var b=this;a.each(this.registeredSidebars,function(c,d){var e,f,g,h=[d.before_widget.replace("%1$s","").replace("%2$s",""),d.before_title,d.after_title,d.after_widget].join("");e=a(h),f=e.prop("tagName"),g=e.prop("className").replace(/^\s+|\s+$/g,""),g&&(f+="."+g.split(/\s+/).join(".")),b.widgetSelectors.push(f)})},highlightWidget:function(b){var c=a(document.body),d=a("#"+b);c.find(".widget-customizer-highlighted-widget").removeClass("widget-customizer-highlighted-widget"),d.addClass("widget-customizer-highlighted-widget"),setTimeout(function(){d.removeClass("widget-customizer-highlighted-widget")},500)},highlightControls:function(){var b=this,c=this.widgetSelectors.join(",");a(c).attr("title",this.l10n.widgetTooltip),a(document).on("mouseenter",c,function(){b.preview.send("highlight-widget-control",a(this).prop("id"))}),a(document).on("click",c,function(c){c.shiftKey&&(c.preventDefault(),b.preview.send("focus-widget-control",a(this).prop("id")))})}},c=d.Preview,d.Preview=c.extend({initialize:function(a,b){d.WidgetCustomizerPreview.preview=this,c.prototype.initialize.call(this,a,b)}}),a(function(){var b=window._wpWidgetCustomizerPreviewSettings;b&&(a.extend(d.WidgetCustomizerPreview,b),d.WidgetCustomizerPreview.init())})}}(jQuery,window.wp);
|
||||
Reference in New Issue
Block a user