Abstracted inline JS helper to class #3282
This commit is contained in:
parent
64c75547f3
commit
b3f05bdd66
|
@ -162,7 +162,7 @@ function woocommerce_restrict_manage_coupons() {
|
|||
</select>
|
||||
<?php
|
||||
|
||||
$woocommerce->add_inline_js( "
|
||||
$woocommerce->get_helper( 'inline-javascript' )->add_inline_js( "
|
||||
jQuery('select#dropdown_shop_coupon_type, select[name=m]').css('width', '150px').chosen();
|
||||
" );
|
||||
}
|
||||
|
|
|
@ -310,7 +310,7 @@ function woocommerce_restrict_manage_orders() {
|
|||
</select>
|
||||
<?php
|
||||
|
||||
$woocommerce->add_inline_js( "
|
||||
$woocommerce->get_helper( 'inline-javascript' )->add_inline_js( "
|
||||
|
||||
jQuery('select#dropdown_shop_order_status, select[name=m]').css('width', '150px').chosen();
|
||||
|
||||
|
|
|
@ -101,7 +101,7 @@ function woocommerce_order_data_meta_box($post) {
|
|||
<?php
|
||||
|
||||
// Ajax Chosen Customer Selectors JS
|
||||
$woocommerce->add_inline_js( "
|
||||
$woocommerce->get_helper( 'inline-javascript' )->add_inline_js( "
|
||||
jQuery('select.ajax_chosen_select_customer').ajaxChosen({
|
||||
method: 'GET',
|
||||
url: '" . admin_url('admin-ajax.php') . "',
|
||||
|
|
|
@ -184,7 +184,7 @@ function woocommerce_order_downloads_meta_box() {
|
|||
});
|
||||
<?php
|
||||
$javascript = ob_get_clean();
|
||||
$woocommerce->add_inline_js( $javascript );
|
||||
$woocommerce->get_helper( 'inline-javascript' )->add_inline_js( $javascript );
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -616,7 +616,7 @@ function variable_product_type_options() {
|
|||
});
|
||||
<?php
|
||||
$javascript = ob_get_clean();
|
||||
$woocommerce->add_inline_js( $javascript );
|
||||
$woocommerce->get_helper( 'inline-javascript' )->add_inline_js( $javascript );
|
||||
}
|
||||
|
||||
add_action('woocommerce_product_write_panels', 'variable_product_type_options');
|
||||
|
|
|
@ -631,7 +631,7 @@ abstract class WC_Email extends WC_Settings_API {
|
|||
?>
|
||||
</div>
|
||||
<?php
|
||||
$woocommerce->add_inline_js("
|
||||
$woocommerce->get_helper( 'inline-javascript' )->add_inline_js("
|
||||
jQuery('select.email_type').change(function(){
|
||||
|
||||
var val = jQuery( this ).val();
|
||||
|
|
|
@ -422,7 +422,7 @@ class WC_Gateway_Paypal extends WC_Payment_Gateway {
|
|||
$paypal_args_array[] = '<input type="hidden" name="'.esc_attr( $key ).'" value="'.esc_attr( $value ).'" />';
|
||||
}
|
||||
|
||||
$woocommerce->add_inline_js( '
|
||||
$woocommerce->get_helper( 'inline-javascript' )->add_inline_js( '
|
||||
$.blockUI({
|
||||
message: "' . esc_js( __( 'Thank you for your order. We are now redirecting you to PayPal to make payment.', 'woocommerce' ) ) . '",
|
||||
baseZ: 99999,
|
||||
|
|
|
@ -0,0 +1,43 @@
|
|||
<?php
|
||||
|
||||
return new WC_Inline_Javascript_Helper();
|
||||
|
||||
class WC_Inline_Javascript_Helper extends WC_Helper {
|
||||
protected $_inline_js;
|
||||
|
||||
/**
|
||||
* Add some JavaScript inline to be output in the footer.
|
||||
*
|
||||
* @access public
|
||||
* @param string $code
|
||||
* @return void
|
||||
*/
|
||||
public function add_inline_js( $code ) {
|
||||
$this->_inline_js .= "\n" . $code . "\n";
|
||||
}
|
||||
|
||||
/**
|
||||
* Output any queued inline JS.
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
public function output_inline_js() {
|
||||
if ( $this->_inline_js ) {
|
||||
|
||||
echo "<!-- WooCommerce JavaScript-->\n<script type=\"text/javascript\">\njQuery(document).ready(function($) {";
|
||||
|
||||
// Sanitize
|
||||
$this->_inline_js = wp_check_invalid_utf8( $this->_inline_js );
|
||||
$this->_inline_js = preg_replace( '/&#(x)?0*(?(1)27|39);?/i', "'", $this->_inline_js );
|
||||
$this->_inline_js = str_replace( "\r", '', $this->_inline_js );
|
||||
|
||||
// Output
|
||||
echo $this->_inline_js;
|
||||
|
||||
echo "});\n</script>\n";
|
||||
|
||||
$this->_inline_js = '';
|
||||
}
|
||||
}
|
||||
}
|
|
@ -311,7 +311,7 @@ class WC_Google_Analytics extends WC_Integration {
|
|||
|
||||
$parameters = apply_filters( 'woocommerce_ga_event_tracking_parameters', $parameters );
|
||||
|
||||
$woocommerce->add_inline_js("
|
||||
$woocommerce->get_helper( 'inline-javascript' )->add_inline_js("
|
||||
$('" . $selector . "').click(function() {
|
||||
" . sprintf( "_gaq.push(['_trackEvent', %s, %s, %s]);", $parameters['category'], $parameters['action'], $parameters['label'] ) . "
|
||||
});
|
||||
|
|
|
@ -169,7 +169,7 @@ class WC_Widget_Layered_Nav extends WC_Widget {
|
|||
|
||||
echo '</select>';
|
||||
|
||||
$woocommerce->add_inline_js("
|
||||
$woocommerce->get_helper( 'inline-javascript' )->add_inline_js("
|
||||
|
||||
jQuery('#dropdown_layered_nav_$taxonomy_filter').change(function(){
|
||||
|
||||
|
|
|
@ -1489,44 +1489,6 @@ class Woocommerce {
|
|||
return $classes;
|
||||
}
|
||||
|
||||
/** Inline JavaScript Helper **********************************************/
|
||||
|
||||
/**
|
||||
* Add some JavaScript inline to be output in the footer.
|
||||
*
|
||||
* @access public
|
||||
* @param string $code
|
||||
* @return void
|
||||
*/
|
||||
public function add_inline_js( $code ) {
|
||||
$this->_inline_js .= "\n" . $code . "\n";
|
||||
}
|
||||
|
||||
/**
|
||||
* Output any queued inline JS.
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
public function output_inline_js() {
|
||||
if ( $this->_inline_js ) {
|
||||
|
||||
echo "<!-- WooCommerce JavaScript-->\n<script type=\"text/javascript\">\njQuery(document).ready(function($) {";
|
||||
|
||||
// Sanitize
|
||||
$this->_inline_js = wp_check_invalid_utf8( $this->_inline_js );
|
||||
$this->_inline_js = preg_replace( '/&#(x)?0*(?(1)27|39);?/i', "'", $this->_inline_js );
|
||||
$this->_inline_js = str_replace( "\r", '', $this->_inline_js );
|
||||
|
||||
// Output
|
||||
echo $this->_inline_js;
|
||||
|
||||
echo "});\n</script>\n";
|
||||
|
||||
$this->_inline_js = '';
|
||||
}
|
||||
}
|
||||
|
||||
/** Deprecated functions *********************************************************/
|
||||
|
||||
/**
|
||||
|
@ -1580,6 +1542,32 @@ class Woocommerce {
|
|||
$helper->clear_product_transients( $post_id );
|
||||
}
|
||||
|
||||
/**
|
||||
* Add some JavaScript inline to be output in the footer.
|
||||
*
|
||||
* @deprecated 2.1.0 Access via the helpers
|
||||
* @access public
|
||||
* @param string $code
|
||||
* @return void
|
||||
*/
|
||||
public function add_inline_js( $code ) {
|
||||
_deprecated_function( 'Woocommerce->add_inline_js', '2.1', 'WC_Inline_Javascript_Helper->add_inline_js' );
|
||||
$helper = $this->get_helper( 'inline-javascript' );
|
||||
$helper->add_inline_js( $code );
|
||||
}
|
||||
|
||||
/**
|
||||
* Output any queued inline JS.
|
||||
*
|
||||
* @deprecated 2.1.0 Access via the helpers
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
public function output_inline_js() {
|
||||
_deprecated_function( 'Woocommerce->output_inline_js', '2.1', 'WC_Inline_Javascript_Helper->output_inline_js' );
|
||||
$helper = $this->get_helper( 'inline-javascript' );
|
||||
$helper->output_inline_js();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in New Issue