Skip to content

Instantly share code, notes, and snippets.

@be3
Created September 21, 2011 05:30
Show Gist options
  • Select an option

  • Save be3/1231328 to your computer and use it in GitHub Desktop.

Select an option

Save be3/1231328 to your computer and use it in GitHub Desktop.
test
$().ready(function() {
var from_submit = false;
$('#order-form') . data ('percentage', 0);
$('#order-form') . data ('percentage2', 0);
$('#order-form select') . each(function(index, element){
$(this) . trigger('change');
});
$("#contact-form").validate({
rules: {
option_groups_option_37: {
required: true
},
option_groups_option_40: {
required: true
},
option_groups_option_41: {
required: true,
email: true
}
}
});
$("#order-form").validate({
rules: {
option_groups_option_37: {
required: true
},
option_groups_option_40: {
required: true
},
option_groups_option_41: {
required: true,
email: true
}
}
});
$('.order-button') . click (function(){
if($(".not_need").is(':checked')){
$("#confirm_error").hide();
}
else {
$("#confirm_error").show();
return false;
}
if($('#order-form').valid())
{
if($('#product-grid-value') . val() == '' && $('#uniform-option_groups_option_32 span') . hasClass('checked'))
{
from_submit = true;
$('#grid-table')
. css('top', $(window) . scrollTop() + ($(window) . height() - $('#grid-table') . height()) / 2 + 'px')
. css('left', ($(window) . width() - $('#grid-table') . width()) / 2 + 'px');
$('#grid-table') . fadeIn(600);
}
else
{
$('#total-price') . val($('#order-summ') . html());
$('#order-form') . submit();
}
}
});
$('#grid-table table tr td') . click(function() {
$('#product-grid-value') . val($(this) . children('img') . attr('src'));
$('#grid-table') . fadeOut(600);
if(from_submit)
{
setTimeout(function(){$('.order-button').trigger('click')}, 100);
}
});
$('#grid-link') . click(function(e) {
$('#uniform-option_groups_option_32 span') . addClass('checked');
$('#option_groups_option_32').attr('checked', 'checked');
updateSumm();
$('#grid-table')
. css('top', $(window) . scrollTop() + ($(window) . height() - $('#grid-table') . height()) / 2 + 'px')
. css('left', ($(window) . width() - $('#grid-table') . width()) / 2 + 'px');
$('#grid-table') . fadeIn(1000);
e . preventDefault();
});
});
$('input[type=radio]') . click(function(){
var vars = $(this) . data('vars');
if(vars . result == 'percentage_add')
$('#order-form') . data ('percentage', (vars . value / 100));
if($(this) . attr('id') == 'radio_button_69')
$('#order-form') . data ('percentage', 0);
updateSumm();
});
$('input[type=checkbox]') . click(function(){
updateSumm();
});
$('#order-form select') . change(function(){
var vars = $(this) . data('vars');
if(vars . result == 'percentage_add')
{
var qnt = this.options[this.selectedIndex].value;
$('#order-form') . data ('percentage2', (qnt / 100));
}
else
{
var qnt = this.options[this.selectedIndex].value;
$('#qnt') . html(qnt);
}
updateSumm();
});
function updateSumm()
{
var qnt = $('#qnt') . html();
var base = $('#base-price') . html();
var summ = 0;
var single_summ = 0;
var percentage = $('#order-form') . data ('percentage');
var percentage2 = $('#order-form') . data ('percentage2');
$('input[type=radio]') . filter(":checked") . each(function(index, element) {
var vars = $(this) . data('vars');
if(vars . single == 'yes')
{
if(vars . result == 'add')
{
single_summ += vars . value * 1.0;
}
if(vars . result == 'minus')
{
single_summ -= vars . value * 1.0;
}
}
else
{
if(vars . result == 'add')
{
summ += vars . value * 1.0;
}
if(vars . result == 'minus')
{
summ -= vars . value * 1.0;
}
}
});
$('input[type=checkbox]') . filter(":checked") . each(function(index, element) {
if($(this).hasClass('not_need')){
} else {
var vars = $(this) . data('vars');
if(vars . single == 'yes')
{
if(vars . result == 'add')
{
single_summ += vars . value * 1.0;
}
if(vars . result == 'minus')
{
single_summ -= vars . value * 1.0;
}
}
else
{
if(vars . result == 'add')
{
summ += vars . value * 1.0;
}
if(vars . result == 'minus')
{
summ -= vars . value * 1.0;
}
}
}
});
summ = (base * 1.0 + summ) * qnt;
$('#order-summ') . html(summ + (Math.round(summ * percentage)) + (Math.round(summ * percentage2)) + single_summ);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment