woocommerce/assets/js/frontend/single-product.js

70 lines
2.2 KiB
JavaScript
Raw Normal View History

jQuery( function( $ ) {
2012-12-10 13:11:05 +00:00
// wc_single_product_params is required to continue, ensure the object exists
if ( typeof wc_single_product_params === 'undefined' ) {
return false;
}
// Tabs
$('.wc-tabs-wrapper, .woocommerce-tabs')
.on( 'init', function() {
$('.wc-tab, .panel:not(.panel .panel)').hide();
var hash = window.location.hash;
var url = window.location.href;
var $tabs = $( this ).find('.wc-tabs, ul.tabs').first();
if ( hash.toLowerCase().indexOf( "comment-" ) >= 0 || hash == '#reviews' ) {
$tabs.find('li.reviews_tab a').click();
} else if ( url.indexOf( "comment-page-" ) > 0 || url.indexOf( "cpage=" ) > 0 ) {
$tabs.find('li.reviews_tab a').click();
} else {
$tabs.find('li:first a').click();
}
})
.on( 'click', '.wc-tabs li a, ul.tabs li a', function() {
var $tab = $( this );
var $tabs_wrapper = $tab.closest( '.wc-tabs-wrapper, .woocommerce-tabs' );
var $tabs = $tabs_wrapper.find( '.wc-tabs, ul.tabs' );
$tabs.find('li').removeClass( 'active' );
$tabs_wrapper.find('.wc-tab, .panel:not(.panel .panel)').hide();
$tab.closest('li').addClass( 'active' );
$tabs_wrapper.find( $tab.attr( 'href' ) ).show();
return false;
})
.trigger('init');
2012-12-10 13:11:05 +00:00
$( 'a.woocommerce-review-link' ).click( function() {
$( '.reviews_tab a' ).click();
return true;
});
// Star ratings for comments
$( '#rating' ).hide().before( '<p class="stars"><span><a class="star-1" href="#">1</a><a class="star-2" href="#">2</a><a class="star-3" href="#">3</a><a class="star-4" href="#">4</a><a class="star-5" href="#">5</a></span></p>' );
2012-12-10 13:11:05 +00:00
$( 'body' )
.on( 'click', '#respond p.stars a', function() {
var $star = $( this ),
$rating = $( this ).closest( '#respond' ).find( '#rating' );
2012-12-10 13:11:05 +00:00
2013-02-11 15:37:26 +00:00
$rating.val( $star.text() );
$star.siblings( 'a' ).removeClass( 'active' );
$star.addClass( 'active' );
2012-12-10 13:11:05 +00:00
return false;
2013-02-11 15:37:26 +00:00
})
.on( 'click', '#respond #submit', function() {
var $rating = $( this ).closest( '#respond' ).find( '#rating' ),
rating = $rating.val();
if ( $rating.size() > 0 && ! rating && wc_single_product_params.review_rating_required === 'yes' ) {
alert( wc_single_product_params.i18n_required_rating_text );
2013-02-11 15:37:26 +00:00
return false;
}
});
});