Widget Customizer: Restore highlighting of widgets in preview.

props westonruter.
see #27358.
Built from https://develop.svn.wordpress.org/trunk@27584


git-svn-id: http://core.svn.wordpress.org/trunk@27427 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Dominik Schilling 2014-03-18 15:21:15 +00:00
parent 181c2d091e
commit 64af78ca43
5 changed files with 28 additions and 18 deletions

View File

@ -1442,7 +1442,7 @@ var WidgetCustomizer = ( function ($) {
getPreviewWidgetElement: function () {
var control = this,
widget_customizer_preview = self.getPreviewWindow().WidgetCustomizerPreview;
return widget_customizer_preview.getSidebarWidgetElement( control.params.sidebar_id, control.params.widget_id );
return widget_customizer_preview.getWidgetElement( control.params.widget_id );
},
/**

File diff suppressed because one or more lines are too long

View File

@ -756,12 +756,7 @@ class WP_Customize_Widgets {
array( 'jquery', 'wp-util', 'customize-preview' )
);
/*
wp_enqueue_style(
'widget-customizer-preview',
'widget-customizer-preview.css'
);
*/
add_action( 'wp_print_styles', array( __CLASS__, 'inject_preview_css' ), 1 );
// Why not wp_localize_script? Because we're not localizing, and it forces values into strings
global $wp_scripts;
@ -783,6 +778,24 @@ class WP_Customize_Widgets {
);
}
/**
* Insert default style for highlighted widget at early point so theme
* stylesheet can override.
*
* @action wp_print_styles
*/
static function inject_preview_css() {
?>
<style>
.widget-customizer-highlighted-widget {
border-radius: 2px;
outline: none;
box-shadow: 0 0 3px #ce0000;
}
</style>
<?php
}
/**
* At the very end of the page, at the very end of the wp_footer, communicate the sidebars that appeared on the page
*

View File

@ -52,19 +52,16 @@ var WidgetCustomizerPreview = (function ($) {
},
/**
* Obtain a widget instance if it was added to the provided sidebar
* This addresses a race condition where a widget is moved between sidebars
* We cannot use ID selector because jQuery will only return the first one
* that matches. We have to resort to an [id] attribute selector
* 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.
*
* @param {String} sidebar_id
* @param {String} widget_id
* @return {jQuery}
*/
getSidebarWidgetElement: function ( sidebar_id, widget_id ) {
return $( '[id=' + widget_id + ']' ).filter( function () {
return $( this ).data( 'widget_customizer_sidebar_id' ) === sidebar_id;
} );
getWidgetElement: function ( widget_id ) {
return $( '#' + widget_id );
},
/**

View File

@ -1 +1 @@
var WidgetCustomizerPreview=function(a){"use strict";var b,c={rendered_sidebars:{},rendered_widgets:{},registered_sidebars:[],registered_widgets:{},widget_selectors:[],render_widget_ajax_action:null,render_widget_nonce_value:null,render_widget_nonce_post_key:null,preview:null,i18n:{},init:function(){this.buildWidgetSelectors(),this.highlightControls(),c.preview.bind("active",function(){c.preview.send("rendered-sidebars",c.rendered_sidebars),c.preview.send("rendered-widgets",c.rendered_widgets)})},buildWidgetSelectors:function(){a.each(c.registered_sidebars,function(b,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(".")),c.widget_selectors.push(f)})},getSidebarWidgetElement:function(b,c){return a("[id="+c+"]").filter(function(){return a(this).data("widget_customizer_sidebar_id")===b})},highlightControls:function(){var b=this.widget_selectors.join(",");a(b).attr("title",c.i18n.widget_tooltip),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()}})}};return a.extend(c,WidgetCustomizerPreview_exports),b=wp.customize.Preview,wp.customize.Preview=b.extend({initialize:function(a,d){c.preview=this,b.prototype.initialize.call(this,a,d)}}),a(function(){c.init()}),c}(jQuery);
var WidgetCustomizerPreview=function(a){"use strict";var b,c={rendered_sidebars:{},rendered_widgets:{},registered_sidebars:[],registered_widgets:{},widget_selectors:[],render_widget_ajax_action:null,render_widget_nonce_value:null,render_widget_nonce_post_key:null,preview:null,i18n:{},init:function(){this.buildWidgetSelectors(),this.highlightControls(),c.preview.bind("active",function(){c.preview.send("rendered-sidebars",c.rendered_sidebars),c.preview.send("rendered-widgets",c.rendered_widgets)})},buildWidgetSelectors:function(){a.each(c.registered_sidebars,function(b,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(".")),c.widget_selectors.push(f)})},getWidgetElement:function(b){return a("#"+b)},highlightControls:function(){var b=this.widget_selectors.join(",");a(b).attr("title",c.i18n.widget_tooltip),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()}})}};return a.extend(c,WidgetCustomizerPreview_exports),b=wp.customize.Preview,wp.customize.Preview=b.extend({initialize:function(a,d){c.preview=this,b.prototype.initialize.call(this,a,d)}}),a(function(){c.init()}),c}(jQuery);