WC_Plugin_Updates::generic_modal_js()protectedWC 1.0

Common JS for initializing and managing thickbox-based modals.

Method of the class: WC_Plugin_Updates{}

No Hooks.

Return

null. Nothing (null).

Usage

// protected - for code of main (parent) or child class
$result = $this->generic_modal_js();

WC_Plugin_Updates::generic_modal_js() code WC 8.7.0

<?php
protected function generic_modal_js() {
	?>
	<script>
		( function( $ ) {
			// Initialize thickbox.
			tb_init( '.wc-thickbox' );

			var old_tb_position = false;

			// Make the WC thickboxes look good when opened.
			$( '.wc-thickbox' ).on( 'click', function( evt ) {
				var $overlay = $( '#TB_overlay' );
				if ( ! $overlay.length ) {
					$( 'body' ).append( '<div id="TB_overlay"></div><div id="TB_window" class="wc_untested_extensions_modal_container"></div>' );
				} else {
					$( '#TB_window' ).removeClass( 'thickbox-loading' ).addClass( 'wc_untested_extensions_modal_container' );
				}

				// WP overrides the tb_position function. We need to use a different tb_position function than that one.
				// This is based on the original tb_position.
				if ( ! old_tb_position ) {
					old_tb_position = tb_position;
				}
				tb_position = function() {
					$( '#TB_window' ).css( { marginLeft: '-' + parseInt( ( TB_WIDTH / 2 ), 10 ) + 'px', width: TB_WIDTH + 'px' } );
					$( '#TB_window' ).css( { marginTop: '-' + parseInt( ( TB_HEIGHT / 2 ), 10 ) + 'px' } );
				};
			});

			// Reset tb_position to WP default when modal is closed.
			$( 'body' ).on( 'thickbox:removed', function() {
				if ( old_tb_position ) {
					tb_position = old_tb_position;
				}
			});
		})( jQuery );
	</script>
	<?php
}