Widget Customizer: Restore highlighting of widgets in preview.

props westonruter.
see #27358.

git-svn-id: https://develop.svn.wordpress.org/trunk@27584 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Dominik Schilling (ocean90) 2014-03-18 15:20:38 +00:00
parent d91dd88edc
commit c2a4665966
3 changed files with 26 additions and 16 deletions

View File

@ -1442,7 +1442,7 @@ var WidgetCustomizer = ( function ($) {
getPreviewWidgetElement: function () { getPreviewWidgetElement: function () {
var control = this, var control = this,
widget_customizer_preview = self.getPreviewWindow().WidgetCustomizerPreview; 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 );
}, },
/** /**

View File

@ -756,12 +756,7 @@ class WP_Customize_Widgets {
array( 'jquery', 'wp-util', 'customize-preview' ) array( 'jquery', 'wp-util', 'customize-preview' )
); );
/* add_action( 'wp_print_styles', array( __CLASS__, 'inject_preview_css' ), 1 );
wp_enqueue_style(
'widget-customizer-preview',
'widget-customizer-preview.css'
);
*/
// Why not wp_localize_script? Because we're not localizing, and it forces values into strings // Why not wp_localize_script? Because we're not localizing, and it forces values into strings
global $wp_scripts; 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 * 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 * Obtain a rendered widget element. Assumes standard practice of using
* This addresses a race condition where a widget is moved between sidebars * the widget ID as the ID for the DOM element. To eliminate this
* We cannot use ID selector because jQuery will only return the first one * assumption, additional data-* attributes would need to be injected
* that matches. We have to resort to an [id] attribute selector * onto the rendered widget root element.
* *
* @param {String} sidebar_id
* @param {String} widget_id * @param {String} widget_id
* @return {jQuery} * @return {jQuery}
*/ */
getSidebarWidgetElement: function ( sidebar_id, widget_id ) { getWidgetElement: function ( widget_id ) {
return $( '[id=' + widget_id + ']' ).filter( function () { return $( '#' + widget_id );
return $( this ).data( 'widget_customizer_sidebar_id' ) === sidebar_id;
} );
}, },
/** /**