Broke up scripts and made jquery ui optional

This commit is contained in:
Mike Jolley 2011-12-02 11:43:15 +00:00
parent 9eb7b4dd13
commit 172a34a9b9
7 changed files with 83 additions and 61 deletions

View File

@ -198,7 +198,7 @@ $woocommerce_settings['general'] = apply_filters('woocommerce_general_settings',
),
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',
'std' => 'yes',
'type' => 'checkbox',

54
assets/js/price_slider.js Normal file
View File

@ -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 ]);
}
});
});

1
assets/js/price_slider.min.js vendored Normal file
View File

@ -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])}})});

View File

@ -120,56 +120,7 @@ jQuery(document).ready(function($) {
$star.addClass('active');
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
$("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

View File

@ -131,7 +131,8 @@ class WooCommerce_Widget_Price_Filter extends WP_Widget {
endforeach;
$min = 0;
$min = $max = 0;
$post_min = $post_max = '';
if (sizeof($woocommerce->query->layered_nav_product_ids)==0) :
@ -155,14 +156,21 @@ class WooCommerce_Widget_Price_Filter extends WP_Widget {
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">
<div class="price_slider_wrapper">
<div class="price_slider"></div>
<div class="price_slider" style="display:none;"></div>
<div class="price_slider_amount">
<button type="submit" class="button">'.__('Filter', 'woothemes').'</button>'.__('Price:', 'woothemes').' <span></span>
<input type="hidden" id="max_price" name="max_price" value="'.esc_attr( $max ).'" />
<input type="hidden" id="min_price" name="min_price" value="'.esc_attr( $min ).'" />
<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="text" id="max_price" name="max_price" value="'.esc_attr( $post_max ).'" data-max="'.esc_attr( $max ).'" placeholder="'.__('Max price', 'woothemes').'" />
<button type="submit" class="button">'.__('Filter', 'woothemes').'</button>
<div class="price_label" style="display:none;">
'.__('Price:', 'woothemes').' <span></span>
</div>
'.$fields.'
<div class="clear"></div>
</div>
</div>
</form>';

View File

@ -251,7 +251,20 @@ function woocommerce_frontend_scripts() {
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( 'wc_price_slider', $woocommerce->plugin_url() . '/assets/js/price_slider'.$suffix.'.js', 'jqueryui', '1.0', $scripts_position );
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;
/* Script variables */
@ -259,8 +272,6 @@ function woocommerce_frontend_scripts() {
$states = (mb_detect_encoding($states, "UTF-8") == "UTF-8") ? $states : utf8_encode($states);
$woocommerce_params = array(
'currency_symbol' => get_woocommerce_currency_symbol(),
'currency_pos' => get_option('woocommerce_currency_pos'),
'countries' => $states,
'select_state_text' => __('Select a state&hellip;', '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')
);
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_pay_page'] = ( is_page(get_option('woocommerce_pay_page_id')) ) ? 1 : 0;
$woocommerce_params['is_cart'] = ( is_cart() ) ? 1 : 0;