Broke up scripts and made jquery ui optional
This commit is contained in:
parent
9eb7b4dd13
commit
172a34a9b9
|
@ -198,7 +198,7 @@ $woocommerce_settings['general'] = apply_filters('woocommerce_general_settings',
|
||||||
),
|
),
|
||||||
|
|
||||||
array(
|
array(
|
||||||
'desc' => __( 'Output JavaScript in the footer (<code>wp_footer</code>)', 'woothemes' ),
|
'desc' => __( 'Output WooCommerce JavaScript in the footer (<code>wp_footer</code>)', 'woothemes' ),
|
||||||
'id' => 'woocommerce_scripts_position',
|
'id' => 'woocommerce_scripts_position',
|
||||||
'std' => 'yes',
|
'std' => 'yes',
|
||||||
'type' => 'checkbox',
|
'type' => 'checkbox',
|
||||||
|
|
|
@ -0,0 +1,54 @@
|
||||||
|
jQuery(document).ready(function($) {
|
||||||
|
|
||||||
|
// Get markup ready for slider
|
||||||
|
$('input#min_price, input#max_price').hide();
|
||||||
|
$('.price_slider, .price_label').show();
|
||||||
|
|
||||||
|
// Price slider uses jquery ui
|
||||||
|
var min_price = $('.price_slider_amount #min_price').attr('data-min');
|
||||||
|
var max_price = $('.price_slider_amount #max_price').attr('data-max');
|
||||||
|
|
||||||
|
current_min_price = parseInt(min_price);
|
||||||
|
current_max_price = parseInt(max_price);
|
||||||
|
|
||||||
|
if (woocommerce_price_slider_params.min_price) current_min_price = parseInt(woocommerce_price_slider_params.min_price);
|
||||||
|
if (woocommerce_price_slider_params.max_price) current_max_price = parseInt(woocommerce_price_slider_params.max_price);
|
||||||
|
|
||||||
|
$('.price_slider').slider({
|
||||||
|
range: true,
|
||||||
|
animate: true,
|
||||||
|
min: min_price,
|
||||||
|
max: max_price,
|
||||||
|
values: [current_min_price,current_max_price],
|
||||||
|
create : function( event, ui ) {
|
||||||
|
|
||||||
|
if (woocommerce_price_slider_params.currency_pos == "left"){
|
||||||
|
$( ".price_slider_amount span" ).html( woocommerce_price_slider_params.currency_symbol + current_min_price + " - " + woocommerce_price_slider_params.currency_symbol + current_max_price );
|
||||||
|
} else if (woocommerce_price_slider_params.currency_pos == "left_space") {
|
||||||
|
$( ".price_slider_amount span" ).html( woocommerce_price_slider_params.currency_symbol + " " + current_min_price + " - " + woocommerce_price_slider_params.currency_symbol + " " + current_max_price );
|
||||||
|
} else if (woocommerce_price_slider_params.currency_pos == "right") {
|
||||||
|
$( ".price_slider_amount span" ).html( current_min_price + woocommerce_price_slider_params.currency_symbol + " - " + current_max_price + woocommerce_price_slider_params.currency_symbol );
|
||||||
|
} else if (woocommerce_price_slider_params.currency_pos == "right_space") {
|
||||||
|
$( ".price_slider_amount span" ).html( current_min_price + " " + woocommerce_price_slider_params.currency_symbol + " - " + current_max_price + " " + woocommerce_price_slider_params.currency_symbol );
|
||||||
|
}
|
||||||
|
|
||||||
|
$( ".price_slider_amount #min_price" ).val(current_min_price);
|
||||||
|
$( ".price_slider_amount #max_price" ).val(current_max_price);
|
||||||
|
},
|
||||||
|
slide: function( event, ui ) {
|
||||||
|
|
||||||
|
if (woocommerce_price_slider_params.currency_pos == "left"){
|
||||||
|
$( ".price_slider_amount span" ).html( woocommerce_price_slider_params.currency_symbol + ui.values[ 0 ] + " - " + woocommerce_price_slider_params.currency_symbol + ui.values[ 1 ] );
|
||||||
|
} else if (woocommerce_price_slider_params.currency_pos == "left_space") {
|
||||||
|
$( ".price_slider_amount span" ).html( woocommerce_price_slider_params.currency_symbol + " " + ui.values[ 0 ] + " - " + woocommerce_price_slider_params.currency_symbol + " " + ui.values[ 1 ] );
|
||||||
|
} else if (woocommerce_price_slider_params.currency_pos == "right") {
|
||||||
|
$( ".price_slider_amount span" ).html( ui.values[ 0 ] + woocommerce_price_slider_params.currency_symbol + " - " + ui.values[ 1 ] + woocommerce_price_slider_params.currency_symbol );
|
||||||
|
} else if (woocommerce_price_slider_params.currency_pos == "right_space") {
|
||||||
|
$( ".price_slider_amount span" ).html( ui.values[ 0 ] + " " + woocommerce_price_slider_params.currency_symbol + " - " + ui.values[ 1 ] + " " + woocommerce_price_slider_params.currency_symbol );
|
||||||
|
}
|
||||||
|
$( "input#min_price" ).val(ui.values[ 0 ]);
|
||||||
|
$( "input#max_price" ).val(ui.values[ 1 ]);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
});
|
|
@ -0,0 +1 @@
|
||||||
|
jQuery(document).ready(function(b){b("input#min_price, input#max_price").hide();b(".price_slider, .price_label").show();var a=b(".price_slider_amount #min_price").attr("data-min");var c=b(".price_slider_amount #max_price").attr("data-max");current_min_price=parseInt(a);current_max_price=parseInt(c);if(woocommerce_price_slider_params.min_price){current_min_price=parseInt(woocommerce_price_slider_params.min_price)}if(woocommerce_price_slider_params.max_price){current_max_price=parseInt(woocommerce_price_slider_params.max_price)}b(".price_slider").slider({range:true,animate:true,min:a,max:c,values:[current_min_price,current_max_price],create:function(d,e){if(woocommerce_price_slider_params.currency_pos=="left"){b(".price_slider_amount span").html(woocommerce_price_slider_params.currency_symbol+current_min_price+" - "+woocommerce_price_slider_params.currency_symbol+current_max_price)}else{if(woocommerce_price_slider_params.currency_pos=="left_space"){b(".price_slider_amount span").html(woocommerce_price_slider_params.currency_symbol+" "+current_min_price+" - "+woocommerce_price_slider_params.currency_symbol+" "+current_max_price)}else{if(woocommerce_price_slider_params.currency_pos=="right"){b(".price_slider_amount span").html(current_min_price+woocommerce_price_slider_params.currency_symbol+" - "+current_max_price+woocommerce_price_slider_params.currency_symbol)}else{if(woocommerce_price_slider_params.currency_pos=="right_space"){b(".price_slider_amount span").html(current_min_price+" "+woocommerce_price_slider_params.currency_symbol+" - "+current_max_price+" "+woocommerce_price_slider_params.currency_symbol)}}}}b(".price_slider_amount #min_price").val(current_min_price);b(".price_slider_amount #max_price").val(current_max_price)},slide:function(d,e){if(woocommerce_price_slider_params.currency_pos=="left"){b(".price_slider_amount span").html(woocommerce_price_slider_params.currency_symbol+e.values[0]+" - "+woocommerce_price_slider_params.currency_symbol+e.values[1])}else{if(woocommerce_price_slider_params.currency_pos=="left_space"){b(".price_slider_amount span").html(woocommerce_price_slider_params.currency_symbol+" "+e.values[0]+" - "+woocommerce_price_slider_params.currency_symbol+" "+e.values[1])}else{if(woocommerce_price_slider_params.currency_pos=="right"){b(".price_slider_amount span").html(e.values[0]+woocommerce_price_slider_params.currency_symbol+" - "+e.values[1]+woocommerce_price_slider_params.currency_symbol)}else{if(woocommerce_price_slider_params.currency_pos=="right_space"){b(".price_slider_amount span").html(e.values[0]+" "+woocommerce_price_slider_params.currency_symbol+" - "+e.values[1]+" "+woocommerce_price_slider_params.currency_symbol)}}}}b("input#min_price").val(e.values[0]);b("input#max_price").val(e.values[1])}})});
|
|
@ -121,55 +121,6 @@ jQuery(document).ready(function($) {
|
||||||
return false;
|
return false;
|
||||||
});
|
});
|
||||||
|
|
||||||
// Price slider (only if jquery UI exists)
|
|
||||||
if ($.slider) {
|
|
||||||
var min_price = $('.price_slider_amount #min_price').val();
|
|
||||||
var max_price = $('.price_slider_amount #max_price').val();
|
|
||||||
|
|
||||||
current_min_price = parseInt(min_price);
|
|
||||||
current_max_price = parseInt(max_price);
|
|
||||||
|
|
||||||
if (woocommerce_params.min_price) current_min_price = parseInt(woocommerce_params.min_price);
|
|
||||||
if (woocommerce_params.max_price) current_max_price = parseInt(woocommerce_params.max_price);
|
|
||||||
|
|
||||||
$('.price_slider').slider({
|
|
||||||
range: true,
|
|
||||||
animate: true,
|
|
||||||
min: min_price,
|
|
||||||
max: max_price,
|
|
||||||
values: [current_min_price,current_max_price],
|
|
||||||
create : function( event, ui ) {
|
|
||||||
|
|
||||||
if (woocommerce_params.currency_pos == "left"){
|
|
||||||
$( ".price_slider_amount span" ).html( woocommerce_params.currency_symbol + current_min_price + " - " + woocommerce_params.currency_symbol + current_max_price );
|
|
||||||
} else if (woocommerce_params.currency_pos == "left_space") {
|
|
||||||
$( ".price_slider_amount span" ).html( woocommerce_params.currency_symbol + " " + current_min_price + " - " + woocommerce_params.currency_symbol + " " + current_max_price );
|
|
||||||
} else if (woocommerce_params.currency_pos == "right") {
|
|
||||||
$( ".price_slider_amount span" ).html( current_min_price + woocommerce_params.currency_symbol + " - " + current_max_price + woocommerce_params.currency_symbol );
|
|
||||||
} else if (woocommerce_params.currency_pos == "right_space") {
|
|
||||||
$( ".price_slider_amount span" ).html( current_min_price + " " + woocommerce_params.currency_symbol + " - " + current_max_price + " " + woocommerce_params.currency_symbol );
|
|
||||||
}
|
|
||||||
|
|
||||||
$( ".price_slider_amount #min_price" ).val(current_min_price);
|
|
||||||
$( ".price_slider_amount #max_price" ).val(current_max_price);
|
|
||||||
},
|
|
||||||
slide: function( event, ui ) {
|
|
||||||
|
|
||||||
if (woocommerce_params.currency_pos == "left"){
|
|
||||||
$( ".price_slider_amount span" ).html( woocommerce_params.currency_symbol + ui.values[ 0 ] + " - " + woocommerce_params.currency_symbol + ui.values[ 1 ] );
|
|
||||||
} else if (woocommerce_params.currency_pos == "left_space") {
|
|
||||||
$( ".price_slider_amount span" ).html( woocommerce_params.currency_symbol + " " + ui.values[ 0 ] + " - " + woocommerce_params.currency_symbol + " " + ui.values[ 1 ] );
|
|
||||||
} else if (woocommerce_params.currency_pos == "right") {
|
|
||||||
$( ".price_slider_amount span" ).html( ui.values[ 0 ] + woocommerce_params.currency_symbol + " - " + ui.values[ 1 ] + woocommerce_params.currency_symbol );
|
|
||||||
} else if (woocommerce_params.currency_pos == "right_space") {
|
|
||||||
$( ".price_slider_amount span" ).html( ui.values[ 0 ] + " " + woocommerce_params.currency_symbol + " - " + ui.values[ 1 ] + " " + woocommerce_params.currency_symbol );
|
|
||||||
}
|
|
||||||
$( "input#min_price" ).val(ui.values[ 0 ]);
|
|
||||||
$( "input#max_price" ).val(ui.values[ 1 ]);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
// Quantity buttons
|
// Quantity buttons
|
||||||
$("div.quantity:not(.buttons_added), td.quantity:not(.buttons_added)").addClass('buttons_added').append('<input type="button" value="+" id="add1" class="plus" />').prepend('<input type="button" value="-" id="minus1" class="minus" />');
|
$("div.quantity:not(.buttons_added), td.quantity:not(.buttons_added)").addClass('buttons_added').append('<input type="button" value="+" id="add1" class="plus" />').prepend('<input type="button" value="-" id="minus1" class="minus" />');
|
||||||
|
|
||||||
|
|
File diff suppressed because one or more lines are too long
|
@ -131,7 +131,8 @@ class WooCommerce_Widget_Price_Filter extends WP_Widget {
|
||||||
|
|
||||||
endforeach;
|
endforeach;
|
||||||
|
|
||||||
$min = 0;
|
$min = $max = 0;
|
||||||
|
$post_min = $post_max = '';
|
||||||
|
|
||||||
if (sizeof($woocommerce->query->layered_nav_product_ids)==0) :
|
if (sizeof($woocommerce->query->layered_nav_product_ids)==0) :
|
||||||
|
|
||||||
|
@ -155,14 +156,21 @@ class WooCommerce_Widget_Price_Filter extends WP_Widget {
|
||||||
|
|
||||||
endif;
|
endif;
|
||||||
|
|
||||||
|
if (isset($_SESSION['min_price'])) $post_min = $_SESSION['min_price'];
|
||||||
|
if (isset($_SESSION['max_price'])) $post_max = $_SESSION['max_price'];
|
||||||
|
|
||||||
echo '<form method="get">
|
echo '<form method="get">
|
||||||
<div class="price_slider_wrapper">
|
<div class="price_slider_wrapper">
|
||||||
<div class="price_slider"></div>
|
<div class="price_slider" style="display:none;"></div>
|
||||||
<div class="price_slider_amount">
|
<div class="price_slider_amount">
|
||||||
<button type="submit" class="button">'.__('Filter', 'woothemes').'</button>'.__('Price:', 'woothemes').' <span></span>
|
<input type="text" id="min_price" name="min_price" value="'.esc_attr( $post_min ).'" data-min="'.esc_attr( $min ).'" placeholder="'.__('Min price', 'woothemes').'" />
|
||||||
<input type="hidden" id="max_price" name="max_price" value="'.esc_attr( $max ).'" />
|
<input type="text" id="max_price" name="max_price" value="'.esc_attr( $post_max ).'" data-max="'.esc_attr( $max ).'" placeholder="'.__('Max price', 'woothemes').'" />
|
||||||
<input type="hidden" id="min_price" name="min_price" value="'.esc_attr( $min ).'" />
|
<button type="submit" class="button">'.__('Filter', 'woothemes').'</button>
|
||||||
|
<div class="price_label" style="display:none;">
|
||||||
|
'.__('Price:', 'woothemes').' <span></span>
|
||||||
|
</div>
|
||||||
'.$fields.'
|
'.$fields.'
|
||||||
|
<div class="clear"></div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</form>';
|
</form>';
|
||||||
|
|
|
@ -251,7 +251,20 @@ function woocommerce_frontend_scripts() {
|
||||||
|
|
||||||
if ($jquery_ui_en) :
|
if ($jquery_ui_en) :
|
||||||
wp_register_script( 'jqueryui', $woocommerce->plugin_url() . '/assets/js/jquery-ui'.$suffix.'.js', 'jquery', '1.0', $scripts_position );
|
wp_register_script( 'jqueryui', $woocommerce->plugin_url() . '/assets/js/jquery-ui'.$suffix.'.js', 'jquery', '1.0', $scripts_position );
|
||||||
|
wp_register_script( 'wc_price_slider', $woocommerce->plugin_url() . '/assets/js/price_slider'.$suffix.'.js', 'jqueryui', '1.0', $scripts_position );
|
||||||
|
|
||||||
wp_enqueue_script( 'jqueryui' );
|
wp_enqueue_script( 'jqueryui' );
|
||||||
|
wp_enqueue_script( 'wc_price_slider' );
|
||||||
|
|
||||||
|
$woocommerce_price_slider_params = array(
|
||||||
|
'currency_symbol' => get_woocommerce_currency_symbol(),
|
||||||
|
'currency_pos' => get_option('woocommerce_currency_pos'),
|
||||||
|
);
|
||||||
|
|
||||||
|
if (isset($_SESSION['min_price'])) $woocommerce_price_slider_params['min_price'] = $_SESSION['min_price'];
|
||||||
|
if (isset($_SESSION['max_price'])) $woocommerce_price_slider_params['max_price'] = $_SESSION['max_price'];
|
||||||
|
|
||||||
|
wp_localize_script( 'wc_price_slider', 'woocommerce_price_slider_params', $woocommerce_price_slider_params );
|
||||||
endif;
|
endif;
|
||||||
|
|
||||||
/* Script variables */
|
/* Script variables */
|
||||||
|
@ -259,8 +272,6 @@ function woocommerce_frontend_scripts() {
|
||||||
$states = (mb_detect_encoding($states, "UTF-8") == "UTF-8") ? $states : utf8_encode($states);
|
$states = (mb_detect_encoding($states, "UTF-8") == "UTF-8") ? $states : utf8_encode($states);
|
||||||
|
|
||||||
$woocommerce_params = array(
|
$woocommerce_params = array(
|
||||||
'currency_symbol' => get_woocommerce_currency_symbol(),
|
|
||||||
'currency_pos' => get_option('woocommerce_currency_pos'),
|
|
||||||
'countries' => $states,
|
'countries' => $states,
|
||||||
'select_state_text' => __('Select a state…', 'woothemes'),
|
'select_state_text' => __('Select a state…', 'woothemes'),
|
||||||
'state_text' => __('state', 'woothemes'),
|
'state_text' => __('state', 'woothemes'),
|
||||||
|
@ -275,9 +286,6 @@ function woocommerce_frontend_scripts() {
|
||||||
'option_ajax_add_to_cart' => get_option('woocommerce_enable_ajax_add_to_cart')
|
'option_ajax_add_to_cart' => get_option('woocommerce_enable_ajax_add_to_cart')
|
||||||
);
|
);
|
||||||
|
|
||||||
if (isset($_SESSION['min_price'])) $woocommerce_params['min_price'] = $_SESSION['min_price'];
|
|
||||||
if (isset($_SESSION['max_price'])) $woocommerce_params['max_price'] = $_SESSION['max_price'];
|
|
||||||
|
|
||||||
$woocommerce_params['is_checkout'] = ( is_page(get_option('woocommerce_checkout_page_id')) ) ? 1 : 0;
|
$woocommerce_params['is_checkout'] = ( is_page(get_option('woocommerce_checkout_page_id')) ) ? 1 : 0;
|
||||||
$woocommerce_params['is_pay_page'] = ( is_page(get_option('woocommerce_pay_page_id')) ) ? 1 : 0;
|
$woocommerce_params['is_pay_page'] = ( is_page(get_option('woocommerce_pay_page_id')) ) ? 1 : 0;
|
||||||
$woocommerce_params['is_cart'] = ( is_cart() ) ? 1 : 0;
|
$woocommerce_params['is_cart'] = ( is_cart() ) ? 1 : 0;
|
||||||
|
|
Loading…
Reference in New Issue