Changeset 27653
- Timestamp:
- 03/22/2014 09:03:18 PM (11 years ago)
- Location:
- trunk/src
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-admin/js/customize-widgets.js
r27652 r27653 1511 1511 getPreviewWidgetElement: function () { 1512 1512 var control = this, 1513 widget_customizer_preview = self.getPreviewWindow(). WidgetCustomizerPreview;1513 widget_customizer_preview = self.getPreviewWindow().wp.customize.WidgetCustomizerPreview; 1514 1514 return widget_customizer_preview.getWidgetElement( control.params.widget_id ); 1515 1515 }, -
trunk/src/wp-includes/class-wp-customize-widgets.php
r27652 r27653 697 697 static function customize_preview_init() { 698 698 add_filter( 'sidebars_widgets', array( __CLASS__, 'preview_sidebars_widgets' ), 1 ); 699 add_action( 'wp_enqueue_scripts', array( __CLASS__, 'customize_preview_enqueue_deps' ) ); 700 add_action( 'wp_footer', array( __CLASS__, 'export_preview_data' ), 9999 ); 699 add_action( 'wp_enqueue_scripts', array( __CLASS__, 'customize_preview_enqueue' ) ); 700 add_action( 'wp_print_styles', array( __CLASS__, 'inject_preview_css' ), 1 ); 701 add_action( 'wp_footer', array( __CLASS__, 'export_preview_data' ), 20 ); 701 702 } 702 703 … … 720 721 * @action wp_enqueue_scripts 721 722 */ 722 static function customize_preview_enqueue _deps() {723 static function customize_preview_enqueue() { 723 724 wp_enqueue_script( 'customize-preview-widgets' ); 724 725 add_action( 'wp_print_styles', array( __CLASS__, 'inject_preview_css' ), 1 ); 726 727 // Why not wp_localize_script? Because we're not localizing, and it forces values into strings 728 global $wp_scripts; 729 $exports = array( 730 'registered_sidebars' => array_values( $GLOBALS['wp_registered_sidebars'] ), 731 'registered_widgets' => $GLOBALS['wp_registered_widgets'], 732 'i18n' => array( 733 'widget_tooltip' => ( 'Shift-click to edit this widget.' ), 734 ), 735 ); 736 foreach ( $exports['registered_widgets'] as &$registered_widget ) { 737 unset( $registered_widget['callback'] ); // may not be JSON-serializeable 738 } 739 $wp_scripts->add_data( 740 'customize-preview-widgets', 741 'data', 742 sprintf( 'var WidgetCustomizerPreview_exports = %s;', json_encode( $exports ) ) 743 ); 744 } 725 } 745 726 746 727 /** … … 768 749 */ 769 750 static function export_preview_data() { 770 wp_print_scripts( array( 'customize-preview-widgets' ) ); 751 // Prepare customizer settings to pass to Javascript. 752 $settings = array( 753 'renderedSidebars' => array_fill_keys( array_unique( self::$rendered_sidebars ), true ), 754 'renderedWidgets' => array_fill_keys( array_keys( self::$rendered_widgets ), true ), 755 'registeredSidebars' => array_values( $GLOBALS['wp_registered_sidebars'] ), 756 'registeredWidgets' => $GLOBALS['wp_registered_widgets'], 757 'l10n' => array( 758 'widgetTooltip' => ( 'Shift-click to edit this widget.' ), 759 ), 760 ); 761 foreach ( $settings['registeredWidgets'] as &$registered_widget ) { 762 unset( $registered_widget['callback'] ); // may not be JSON-serializeable 763 } 764 771 765 ?> 772 <script> 773 (function () { 774 /*global WidgetCustomizerPreview */ 775 WidgetCustomizerPreview.rendered_sidebars = <?php echo json_encode( array_fill_keys( array_unique( self::$rendered_sidebars ), true ) ) ?>; 776 WidgetCustomizerPreview.rendered_widgets = <?php echo json_encode( array_fill_keys( array_keys( self::$rendered_widgets ), true ) ); ?>; 777 }()); 766 <script type="text/javascript"> 767 var _wpWidgetCustomizerPreviewSettings = <?php echo json_encode( $settings ); ?>; 778 768 </script> 779 769 <?php -
trunk/src/wp-includes/js/customize-preview-widgets.js
r27588 r27653 1 /*global jQuery, WidgetCustomizerPreview_exports */ 2 /*exported WidgetCustomizerPreview */ 3 var WidgetCustomizerPreview = (function ($) { 4 'use strict'; 1 (function( $, wp ){ 5 2 6 var OldPreview, self = { 7 rendered_sidebars: {}, // @todo Make rendered a property of the Backbone model 8 rendered_widgets: {}, // @todo Make rendered a property of the Backbone model 9 registered_sidebars: [], // @todo Make a Backbone collection 10 registered_widgets: {}, // @todo Make array, Backbone collection 11 widget_selectors: [], 3 if ( ! wp || ! wp.customize ) { return; } 4 5 var api = wp.customize, 6 OldPreview; 7 8 /** 9 * wp.customize.WidgetCustomizerPreview 10 * 11 */ 12 api.WidgetCustomizerPreview = { 13 renderedSidebars: {}, // @todo Make rendered a property of the Backbone model 14 renderedWidgets: {}, // @todo Make rendered a property of the Backbone model 15 registeredSidebars: [], // @todo Make a Backbone collection 16 registeredWidgets: {}, // @todo Make array, Backbone collection 17 widgetSelectors: [], 12 18 preview: null, 13 i18n: {},19 l10n: {}, 14 20 15 21 init: function () { 22 var self = this; 16 23 this.buildWidgetSelectors(); 17 24 this.highlightControls(); 18 25 19 self.preview.bind( 'active', function() {20 self.preview.send( 'rendered-sidebars', self.rendered _sidebars ); // @todo Only send array of IDs21 self.preview.send( 'rendered-widgets', self.rendered _widgets ); // @todo Only send array of IDs26 this.preview.bind( 'active', function() { 27 self.preview.send( 'rendered-sidebars', self.renderedSidebars ); // @todo Only send array of IDs 28 self.preview.send( 'rendered-widgets', self.renderedWidgets ); // @todo Only send array of IDs 22 29 } ); 23 30 }, … … 27 34 */ 28 35 buildWidgetSelectors: function () { 29 $.each( self.registered_sidebars, function ( i, sidebar ) { 30 var widget_tpl = [ 36 var self = this; 37 38 $.each( this.registeredSidebars, function ( i, sidebar ) { 39 var widgetTpl = [ 31 40 sidebar.before_widget.replace('%1$s', '').replace('%2$s', ''), 32 41 sidebar.before_title, … … 34 43 sidebar.after_widget 35 44 ].join(''), 36 empty _widget,37 widget _selector,38 widget _classes;45 emptyWidget, 46 widgetSelector, 47 widgetClasses; 39 48 40 empty _widget = $(widget_tpl);41 widget _selector = empty_widget.prop('tagName');42 widget _classes = empty_widget.prop('className').replace(/^\s+|\s+$/g, '');49 emptyWidget = $(widgetTpl); 50 widgetSelector = emptyWidget.prop('tagName'); 51 widgetClasses = emptyWidget.prop('className').replace(/^\s+|\s+$/g, ''); 43 52 44 if ( widget _classes ) {45 widget _selector += '.' + widget_classes.split(/\s+/).join('.');53 if ( widgetClasses ) { 54 widgetSelector += '.' + widgetClasses.split(/\s+/).join('.'); 46 55 } 47 self.widget _selectors.push(widget_selector);56 self.widgetSelectors.push(widgetSelector); 48 57 }); 49 58 }, … … 66 75 */ 67 76 highlightControls: function() { 77 var selector = this.widgetSelectors.join(','); 68 78 69 var selector = this.widget_selectors.join(','); 70 71 $(selector).attr( 'title', self.i18n.widget_tooltip ); 79 $(selector).attr( 'title', this.l10n.widgetTooltip ); 72 80 73 81 $(document).on( 'mouseenter', selector, function () { … … 90 98 }); 91 99 } 92 93 100 }; 94 95 $.extend(self, WidgetCustomizerPreview_exports);96 101 97 102 /** 98 103 * Capture the instance of the Preview since it is private 99 104 */ 100 OldPreview = wp.customize.Preview;101 wp.customize.Preview = OldPreview.extend( {105 OldPreview = api.Preview; 106 api.Preview = OldPreview.extend( { 102 107 initialize: function( params, options ) { 103 self.preview = this;108 api.WidgetCustomizerPreview.preview = this; 104 109 OldPreview.prototype.initialize.call( this, params, options ); 105 110 } 106 111 } ); 107 112 108 // @todo on customize ready?109 113 $(function () { 110 self.init(); 114 var settings = window._wpWidgetCustomizerPreviewSettings; 115 if ( ! settings ) { 116 return; 117 } 118 119 $.extend( api.WidgetCustomizerPreview, settings ); 120 121 api.WidgetCustomizerPreview.init(); 111 122 }); 112 123 113 return self; 114 }( jQuery )); 124 })( jQuery, window.wp );
Note: See TracChangeset
for help on using the changeset viewer.