add_inline_js helper for adding javascript to the footer

This commit is contained in:
Mike Jolley 2011-12-07 17:36:58 +00:00
parent c607cb3488
commit d3e122641d
2 changed files with 50 additions and 26 deletions

View File

@ -277,32 +277,30 @@ class woocommerce_paypal extends woocommerce_payment_gateway {
$paypal_args_array[] = '<input type="hidden" name="'.esc_attr( $key ).'" value="'.esc_attr( $value ).'" />';
}
return '<form action="'.esc_url( $paypal_adr ).'" method="post" id="paypal_payment_form" target="paypal">
$woocommerce->add_inline_js('
jQuery("body").block({
message: "<img src=\"'.esc_url( $woocommerce->plugin_url() ).'/assets/images/ajax-loader.gif\" alt=\"Redirecting...\" style=\"float:left; margin-right: 10px;\" />'.__('Thank you for your order. We are now redirecting you to PayPal to make payment.', 'woothemes').'",
overlayCSS:
{
background: "#fff",
opacity: 0.6
},
css: {
padding: 20,
textAlign: "center",
color: "#555",
border: "3px solid #aaa",
backgroundColor:"#fff",
cursor: "wait",
lineHeight: "32px"
}
});
jQuery("#submit_paypal_payment_form").click();
');
return '<form action="'.esc_url( $paypal_adr ).'" method="post" id="paypal_payment_form">
' . implode('', $paypal_args_array) . '
<input type="submit" class="button-alt" id="submit_paypal_payment_form" value="'.__('Pay via PayPal', 'woothemes').'" /> <a class="button cancel" href="'.esc_url( $order->get_cancel_order_url() ).'">'.__('Cancel order &amp; restore cart', 'woothemes').'</a>
<script type="text/javascript">
(function($) {
jQuery("body").block(
{
message: "<img src=\"'.esc_url( $woocommerce->plugin_url() ).'/assets/images/ajax-loader.gif\" alt=\"Redirecting...\" style=\"float:left; margin-right: 10px;\" />'.__('Thank you for your order. We are now redirecting you to PayPal to make payment.', 'woothemes').'",
overlayCSS:
{
background: "#fff",
opacity: 0.6
},
css: {
padding: 20,
textAlign: "center",
color: "#555",
border: "3px solid #aaa",
backgroundColor:"#fff",
cursor: "wait",
lineHeight: "32px"
}
});
jQuery("#submit_paypal_payment_form").click();
})(jQuery);
</script>
</form>';
}

View File

@ -15,6 +15,7 @@ class woocommerce {
var $attribute_taxonomies; // Stores the attribute taxonomies used in the store
var $plugin_url;
var $plugin_path;
var $inline_js = '';
// Class instances
var $query;
@ -40,9 +41,10 @@ class woocommerce {
$this->load_messages();
// Hooks
add_filter('wp_redirect', array(&$this, 'redirect'), 1, 2);
add_filter( 'wp_redirect', array(&$this, 'redirect'), 1, 2 );
add_action( 'woocommerce_before_single_product', array(&$this, 'show_messages'), 10);
add_action( 'woocommerce_before_shop_loop', array(&$this, 'show_messages'), 10);
add_action( 'wp_footer', array(&$this, 'output_inline_js'), 25);
// Queue shipping and payment gateways
add_action('plugins_loaded', array( &$this->shipping, 'init' ), 1); // Load shipping methods - some may be added by plugins
@ -351,5 +353,29 @@ class woocommerce {
$wpdb->query("DELETE FROM `$wpdb->options` WHERE `option_name` LIKE ('_transient_woocommerce_product_total_stock_%')");
endif;
}
/*-----------------------------------------------------------------------------------*/
/* Inline JavaScript Helper (for adding it to the footer) */
/*-----------------------------------------------------------------------------------*/
function add_inline_js( $code ) {
$this->inline_js .= "\n" . $code . "\n";
}
function output_inline_js() {
if ($this->inline_js) :
echo "<!-- WooCommerce JavaScript-->\n<script type=\"text/javascript\">\njQuery(document).ready(function($) {";
echo $this->inline_js;
echo "});\n</script>\n";
endif;
}
}