Changeset 42613
- Timestamp:
- 01/29/2018 11:55:44 PM (7 years ago)
- Location:
- trunk
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/js/customize-selective-refresh.js
r42037 r42613 487 487 if ( wp.mediaelement ) { 488 488 wp.mediaelement.initialize(); 489 } 490 491 if ( wp.playlist ) { 492 wp.playlist.initialize(); 489 493 } 490 494 -
trunk/src/wp-includes/js/mediaelement/wp-playlist.js
r42403 r42613 3 3 (function ($, _, Backbone) { 4 4 'use strict'; 5 6 /** @namespace wp */ 7 window.wp = window.wp || {}; 5 8 6 9 var WPPlaylistView = Backbone.View.extend(/** @lends WPPlaylistView.prototype */{ … … 169 172 }); 170 173 171 $(document).ready(function () { 172 $('.wp-playlist').each( function() { 173 return new WPPlaylistView({ el: this }); 174 /** 175 * Initialize media playlists in the document. 176 * 177 * Only initializes new playlists not previously-initialized. 178 * 179 * @since 4.9.3 180 * @returns {void} 181 */ 182 function initialize() { 183 $( '.wp-playlist:not(:has(.mejs-container))' ).each( function() { 184 new WPPlaylistView( { el: this } ); 174 185 } ); 175 }); 186 } 187 188 /** 189 * Expose the API publicly on window.wp.playlist. 190 * 191 * @namespace wp.playlist 192 * @since 4.9.3 193 * @type {object} 194 */ 195 window.wp.playlist = { 196 initialize: initialize 197 }; 198 199 $( document ).ready( initialize ); 176 200 177 201 window.WPPlaylistView = WPPlaylistView; -
trunk/src/wp-includes/widgets/class-wp-widget-text.php
r42545 r42613 57 57 58 58 wp_add_inline_script( 'text-widgets', sprintf( 'wp.textWidgets.idBases.push( %s );', wp_json_encode( $this->id_base ) ) ); 59 60 if ( $this->is_preview() ) { 61 add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_preview_scripts' ) ); 62 } 59 63 60 64 // Note that the widgets component in the customizer will also do the 'admin_print_scripts-widgets.php' action in WP_Customize_Widgets::print_scripts(). … … 392 396 393 397 return $instance; 398 } 399 400 /** 401 * Enqueue preview scripts. 402 * 403 * These scripts normally are enqueued just-in-time when a playlist shortcode is used. 404 * However, in the customizer, a playlist shortcode may be used in a text widget and 405 * dynamically added via selective refresh, so it is important to unconditionally enqueue them. 406 * 407 * @since 4.9.3 408 */ 409 public function enqueue_preview_scripts() { 410 require_once dirname( dirname( __FILE__ ) ) . '/media.php'; 411 412 wp_playlist_scripts( 'audio' ); 413 wp_playlist_scripts( 'video' ); 394 414 } 395 415 -
trunk/tests/phpunit/tests/widgets/text-widget.php
r42343 r42613 67 67 $this->assertEquals( 10, has_action( 'admin_footer-widgets.php', array( 'WP_Widget_Text', 'render_control_template_scripts' ) ) ); 68 68 $this->assertContains( 'wp.textWidgets.idBases.push( "text" );', wp_scripts()->registered['text-widgets']->extra['after'] ); 69 $this->assertFalse( has_action( 'wp_enqueue_scripts', array( $widget, 'enqueue_preview_scripts' ) ) ); 70 } 71 72 /** 73 * Test register in customize preview. 74 * 75 * @global WP_Customize_Manager $wp_customize 76 * @covers WP_Widget_Text::__construct() 77 * @covers WP_Widget_Text::_register() 78 */ 79 function test__register_in_customize_preview() { 80 global $wp_customize; 81 wp_set_current_user( 82 $this->factory()->user->create( 83 array( 84 'role' => 'administrator', 85 ) 86 ) 87 ); 88 require_once ABSPATH . WPINC . '/class-wp-customize-manager.php'; 89 $wp_customize = new WP_Customize_Manager( 90 array( 91 'changeset_uuid' => wp_generate_uuid4(), 92 ) 93 ); 94 $wp_customize->start_previewing_theme(); 95 96 $widget = new WP_Widget_Text(); 97 $widget->_register(); 98 $this->assertEquals( 10, has_action( 'wp_enqueue_scripts', array( $widget, 'enqueue_preview_scripts' ) ) ); 99 } 100 101 /** 102 * Test enqueue_preview_scripts method. 103 * 104 * @global WP_Scripts $wp_scripts 105 * @global WP_Styles $wp_styles 106 * @covers WP_Widget_Text::enqueue_preview_scripts 107 */ 108 function test_enqueue_preview_scripts() { 109 global $wp_scripts, $wp_styles; 110 $wp_scripts = null; 111 $wp_styles = null; 112 $widget = new WP_Widget_Text(); 113 114 $this->assertFalse( wp_style_is( 'wp-mediaelement' ) ); 115 $this->assertFalse( wp_script_is( 'wp-playlist' ) ); 116 117 ob_start(); 118 $widget->enqueue_preview_scripts(); 119 ob_end_clean(); 120 121 $this->assertTrue( wp_style_is( 'wp-mediaelement' ) ); 122 $this->assertTrue( wp_script_is( 'wp-playlist' ) ); 69 123 } 70 124
Note: See TracChangeset
for help on using the changeset viewer.