1// Cost calculator 2// author: Bold Themes - http://www.bold-themes.com/ 3// Date: 15 Nov, 2017 4// web: http://www.bold-themes.com 5 6(function( $ ) { 7 8 var is_rtl = false; 9 var rtl_direction = 1; 10 11 // --------------- 12 // Functions start 13 // --------------- 14 15 // Base functions 16 17 window.bt_parse_float = function( x ) { 18 r = parseFloat( x ); 19 if ( isNaN( r ) ) r = 0; 20 return r; 21 } 22 23 $.fn.bt_cc_lock = function(){ 24 $(this).addClass( 'btCCLock' ); 25 return $(this); 26 } 27 28 $.fn.bt_cc_unlock = function(){ 29 $(this).removeClass( 'btCCLock' ); 30 return $(this); 31 } 32 33 // function to be called from element conditions 34 35 window.bt_cc_set_slider_value = function( elem, value, calc ){ 36 if ( elem.slider( 'instance' ) ) { 37 elem.slider( 'value', value ); 38 elem.find('.btQuoteSliderValue').html( value ); 39 if ( calc ) { 40 bt_quote_total( elem.closest( '.btQuoteBooking' ) ); 41 bt_paypal_items( elem.closest( '.btQuoteBooking' ) ); 42 } 43 } 44 45 } 46 window.bt_cc_get_slider_value = function( elem ){ 47 if ( elem.slider( 'instance' ) ) { 48 // console.log( 'elem.slider_html: ' + elem.find('.btQuoteSliderValue').html() ); 49 // val = bt_parse_float( window.rtl_direction * elem.slider( 'value' ) ); 50 val = bt_parse_float( elem.find('.btQuoteSliderValue').html() ); 51 } else { 52 val = bt_parse_float( elem.data( 'initial-value' ) ); 53 } 54 // console.log( 'bt_cc_get_slider_value: ' + val ); 55 return val; 56 57 } 58 59 $.fn.bt_cc_set_value = function( value ){ 60 if ( value !== null && value !== 'undefined' && value !== undefined ) { 61 var initial_value = value; 62 } else { 63 var initial_value = $( this ).find( '.btQuoteElement' ).data( 'initial-value' ); 64 } 65 if ( $( this ).find( '.btQuoteItemInput > .btQuoteSelect' ).length > 0 ) { 66 var oDropdown = $( this ).find( '.btQuoteSelect' ).data("dd"); 67 if ( oDropdown !== undefined ) { 68 bt_cc_init_dropdown( oDropdown, "#"+$( this ).attr('id'), initial_value ); 69 } 70 } else if ( $( this ).find( '.btQuoteItemInput > .btQuoteSlider' ).length > 0 ) { 71 if ( $( this ).find( '.btQuoteItemInput > .btQuoteSlider' ).slider( 'instance' ) ) { 72 bt_cc_set_slider_value( $( this ).find( '.btQuoteItemInput > .btQuoteSlider' ), initial_value ); 73 } else { 74 /* W3 Tiotal cache safe path */ 75 setTimeout( bt_cc_set_slider_value, 2000, $( this ).find( '.btQuoteItemInput > .btQuoteSlider' ), initial_value, true ); 76 } 77 78 } else if ( $( this ).find( '.btQuoteItemInput > .btQuoteText' ).length > 0 ) { 79 $( this ).find( '.btQuoteText' ).val( initial_value ); 80 } else if ( $( this ).find( '.btQuoteItemInput > .btQuoteSwitch' ).length > 0 ) { 81 if ( 82 ( $( this ).find( '.btQuoteSwitch' ).data('on') == initial_value && !$( this ).find( '.btQuoteSwitch' ).hasClass('on') ) || 83 ( $( this ).find( '.btQuoteSwitch' ).data('off') == initial_value && $( this ).find( '.btQuoteSwitch' ).hasClass('on') ) 84 ) { 85 $( this ).find( '.btQuoteSwitch' ).trigger('click'); 86 } 87 } 88 bt_cc_eval_conditions( initial_value, $( this ).find( '.btQuoteElement' ).data( 'condition' ) ); 89 bt_quote_total( $( this ).closest( '.btQuoteBooking' ) ); 90 bt_paypal_items( $( this ).closest( '.btQuoteBooking' ) ); 91 return $(this); 92 } 93 94 window.bt_cc_eval_conditions = function( val, conditions ){ 95 // alert(conditions); 96 if ( conditions == '' || conditions == undefined ) return false; 97 if ( val == '' ) val = 0; 98 99 if ( conditions.indexOf(';') == -1 ) { 100 conditions = atob( conditions ); 101 var bt_cc_conditions = conditions.split(/\r?\n/); 102 } else { 103 var bt_cc_conditions = conditions.split("#bt_cc_nl#"); 104 } 105 $.each( bt_cc_conditions, function( index, value ) { 106 if ( bt_cc_conditions[index] != undefined ) { 107 var bt_cc_single_condition = bt_cc_conditions[index].split(";"); 108 var eval_action = bt_cc_single_condition[2]; 109 if ( bt_cc_single_condition[3] == 'lock' ) { 110 eval_action += '.bt_cc_lock()'; 111 } else if ( bt_cc_single_condition[3] == 'unlock' ) { 112 eval_action += '.bt_cc_unlock()'; 113 } 114 if ( bt_cc_single_condition[0] != '' ) { 115 var eval_code = 'if ( ' + val + decodeURIComponent( bt_cc_single_condition[0] ) + ' ) { $(\'#' + bt_cc_single_condition[1] + '\').' + eval_action + '; }' ; 116 eval( eval_code ); 117 } 118 } 119 120 }); 121 return false;
122 } 123 124 125 // Paypal calculation 126 127 window.bt_paypal_items = function( c ) { 128 129 $( c ).each(function() { 130 131 if ( $( this ).find( '.btPayPalButton' ).length > 0 ) { 132 133 var form = $( this ).find( '.btPayPalButton' ).next(); 134 form.find( '.btPayPalItem' ).remove(); 135 136 var x = 0; 137 138 // items not in multiply and group 139 $( this ).find( '.btQuoteBookingForm' ).find( '.btQuoteItem' ).not( '.btQuoteMBlock .btQuoteItem' ).not( '.btQuoteGBlock .btQuoteItem' ).each(function() { 140 141 var unit_price = 0; 142 var val = 0; 143 144 var selected_name = ''; 145 146 $( this ).find( '.btQuoteText' ).each(function() { 147 unit_price = bt_parse_float( $( this ).data( 'price' ) ); 148 val = bt_parse_float( $( this ).val() ); 149 }); 150 151 $( this ).find( '.btQuoteSelect' ).find( '._msddli_.selected' ).each(function() { 152 unit_price = bt_parse_float( $( this ).data( 'value' ) ); 153 val = 1; 154 selected_name = $( this ).find( '.ddlabel' )[0].innerHTML; 155 if ( $( this ).is( ':first-child' ) ) { 156 selected_name = ''; 157 } 158 }); 159 160 var is_slider = false;
161 $( this ).find( '.btQuoteSlider' ).each(function() { 162 unit_price = bt_parse_float( $( this ).data( 'price' ) ); 163 val = bt_cc_get_slider_value ( $( this ) ); 164 is_slider = true; 165 }); 166 167 $( this ).find( '.btQuoteSwitch' ).each(function() { 168 if ( $( this ).hasClass( 'on' ) ) { 169 unit_price = bt_parse_float( $( this ).data( 'on' ) ); 170 } else { 171 unit_price = bt_parse_float( $( this ).data( 'off' ) ); 172 } 173 val = 1; 174 }); 175 176 var label = $( this ).find( 'label' ).html(); 177 178 if ( is_slider ) { 179 label = label + ': ' + val; 180 } 181 182 if ( selected_name != '' ) { 183 selected_name = selected_name.replace( '<span class="description">', '/' ); 184 selected_name = selected_name.replace( '</span>', '' ); 185 if ( label.endsWith( '?' ) || label.endsWith( ':' ) ) { 186 label = label + ' ' + selected_name; 187 } else { 188 label = label + ': ' + selected_name; 189 } 190 191 } 192 193 val = val * unit_price; 194 195 196 if ( label !== undefined && val > 0 ) { 197 x++; 198 val = val.toFixed( 2 ); 199 form.append( '<input type="hidden" name="item_name_' + x + '" value="' + label + '" class="btPayPalItem"><input type="hidden" name="amount_' + x + '" value="' + val + '" class="btPayPalItem">' ); 200 } 201 }); 202 203 204 // multiply 205 206 $( this ).find( '.btQuoteBookingForm' ).find( '.btQuoteMBlock' ).each(function() { 207 208 var m_total = 1; 209 var m_first = true; 210 var m_val = 0; 211 var selected_name = ''; 212 var label = ''; 213 214 $( this ).find( '.btQuoteItem' ).each(function() { 215 216 $( this ).find( '.btQuoteText' ).each(function() { 217 var unit_price = bt_parse_float( $( this ).data( 'price' ) ); 218 var val = bt_parse_float( $( this ).val() ); 219 val = val * unit_price; 220 if ( m_first ) { 221 m_val = val; 222 label = $( this ).closest( '.btQuoteItem' ).find( 'label' ).html(); 223 } else { 224 m_total *= val; 225 } 226 m_first = false; 227 }); 228 229 $( this ).find( '.btQuoteSelect' ).find( '._msddli_.selected' ).each(function() { 230 var val = bt_parse_float( $( this ).data( 'value' ) ); 231 if ( m_first ) { 232 m_val = val; 233 label = $( this ).closest( '.btQuoteItem' ).find( 'label' ).html(); 234 selected_name = $( this ).find( '.ddlabel' )[0].innerHTML; 235 selected_name = selected_name.substring( 0, selected_name.indexOf( '<span' ) ); 236 if ( $( this ).is( ':first-child' ) ) { 237 selected_name = ''; 238 } 239 if ( selected_name != '' ) label = label + ': ' + selected_name; 240 } else { 241 m_total *= val; 242 } 243 m_first = false; 244 }); 245 246 $( this ).find( '.btQuoteSlider' ).each(function() { 247 var unit_price = bt_parse_float( $( this ).data( 'price' ) ); 248 // var val = bt_parse_float( $( this ).slider( 'value' ) ); 249 var val = bt_cc_get_slider_value ( $( this ) ); 250 val = val * unit_price; 251 if ( m_first ) { 252 m_val = val; 253 label = $( this ).closest( '.btQuoteItem' ).find( 'label' ).html(); 254 } else { 255 m_total *= val; 256 } 257 m_first = false; 258 }); 259 260 $( this ).find( '.btQuoteSwitch' ).each(function() { 261 if ( $( this ).hasClass( 'on' ) ) { 262 var val = bt_parse_float( $( this ).data( 'on' ) ); 263 } else { 264 var val = bt_parse_float( $( this ).data( 'off' ) ); 265 } 266 if ( m_first ) { 267 m_val = val; 268 label = $( this ).closest( '.btQuoteItem' ).find( 'label' ).html(); 269 } else { 270 m_total *= val; 271 } 272 m_first = false; 273 }); 274 275 276 }); 277 278 if ( m_total > 0 && m_val > 0 ) { 279 x++; 280 m_val = m_val.toFixed( 2 ); 281 form.append( '<input type="hidden" name="item_name_' + x + '" value="' + label + '" class="btPayPalItem"><input type="hidden" name="amount_' + x + '" value="' + m_val + '" class="btPayPalItem"><input type="hidden" name="quantity_' + x + '" value="' + m_total + '" class="btPayPalItem">' ); 282 } 283 284 }); 285 286 287 // group 288 289 $( this ).find( '.btQuoteBookingForm' ).find( '.btQuoteGBlock' ).each(function() { 290 291 var eval_code = $( this ).data( 'eval' ); 292 293 var paypal_label = $( this ).data( 'paypal_label' ); 294 295 var group_array = []; 296 297 $( this ).find( '.btQuoteItem' ).each(function() { 298 299 var val; 300 301 $( this ).find( '.btQuoteText' ).each(function() { 302 var unit_price = bt_parse_float( $( this ).data( 'price' ) ); 303 val = bt_parse_float( $( this ).val() ); 304 val = val * unit_price; 305 }); 306 307 $( this ).find( '.btQuoteSelect' ).find( '._msddli_.selected' ).each(function() { 308 val = bt_parse_float( $( this ).data( 'value' ) ); 309 }); 310 311 $( this ).find( '.btQuoteSlider' ).each(function() { 312 var unit_price = bt_parse_float( $( this ).data( 'price' ) ); 313 // val = bt_parse_float( $( this ).slider( 'value' ) ); 314 val = bt_cc_get_slider_value ( $( this ) ); 315 val = val * unit_price; 316 }); 317 318 $( this ).find( '.btQuoteSwitch' ).each(function() { 319 if ( $( this ).hasClass( 'on' ) ) { 320 val = bt_parse_float( $( this ).data( 'on' ) ); 321 } else { 322 val = bt_parse_float( $( this ).data( 'off' ) ); 323 } 324 }); 325 326 group_array.push( val ); 327 328 }); 329 330 var patt = /\$\d+/igm; 331 var match = eval_code.match( patt ); 332 333 if ( match === null ) { 334 eval_code = atob( eval_code ); 335 match = eval_code.match( patt ); 336 } 337 338 if ( match === null ) { 339 return; 340 } 341 342 for ( var i = 0; i < match.length; i++ ) { 343 eval_code = eval_code.replace( match[ i ], group_array[ i ] ); 344 } 345 var g_total = eval( '(function() {' + decodeURIComponent(eval_code) + '}())' ); 346 347 if ( paypal_label != '' && g_total > 0 ) { 348 x++; 349 g_total = g_total.toFixed( 2 ); 350 form.append( '<input type="hidden" name="item_name_' + x + '" value="' + paypal_label + '" class="btPayPalItem"><input type="hidden" name="amount_' + x + '" value="' + g_total + '" class="btPayPalItem"><input type="hidden" name="quantity_' + x + '" value="1" class="btPayPalItem">' ); 351 } 352 353 }); 354 } 355 }); 356 } 357 358 // Currency format 359 360 window.bt_cc_currency_format = function( c, n ) { 361 var regex = /(\d)(?=(\d{3})+\.)/g; 362 var regex_replace = '$1,'; 363 364 var format = c.data( 'total_format' ); 365 var decimals = c.data( 'total_decimals' ); 366 367 if ( format == 'currency_1' || format == 'currency_2' || format == 'currency_3' ) { 368 369 n = n.toFixed( decimals ); 370 371 if ( format == 'currency_2' || format == 'currency_3' ) { 372 n = n.replace( '.', ',' ); 373 regex = /(\d)(?=(\d{3})+\,)/g; 374 if ( format == 'currency_2' ) { 375 regex_replace = '$1.';
376 } else if ( format == 'currency_3' ) { 377 regex_replace = '$1 '; 378 } 379 } 380 381 n = n.replace( regex, regex_replace ); 382 383 } else if ( format == 'decimal_1' || format == 'decimal_2' ) { 384 385 n = parseFloat( n.toFixed( decimals ) ).toString(); 386 387 } else if ( format == 'rounded' ) { 388 389 n = Math.round( n ); 390 391 } 392 393 return n; 394 } 395 396 // Total calculation 397 398 window.bt_quote_total = function( c ) { 399 400 var c = $( c ); 401 402 total = 0; 403 404 405 c.find( '.btQuoteText' ).not( '.btQuoteMBlock .btQuoteText' ).not( '.btQuoteGBlock .btQuoteText' ).each(function() { 406 var unit_price = bt_parse_float( $( this ).data( 'price' ) ); 407 var val = bt_parse_float( $( this ).val() ); 408 val = val * unit_price; 409 total += val; 410 }); 411 412 c.find( '.btQuoteSelect' ).not( '.btQuoteMBlock .btQuoteSelect' ).not( '.btQuoteGBlock .btQuoteSelect' ).find( '._msddli_.selected' ).each(function() { 413 var val = bt_parse_float( $( this ).data( 'value' ) ); 414 total += val; 415 }); 416 417 c.find( '.btQuoteSlider' ).not( '.btQuoteMBlock .btQuoteSlider' ).not( '.btQuoteGBlock .btQuoteSlider' ).each(function() { 418 var unit_price = bt_parse_float( $( this ).data( 'price' ) ); 419 var offset = bt_parse_float( $( this ).data( 'offset' ) ); 420 var val = bt_cc_get_slider_value ( $( this ) ); 421 val = val * unit_price; 422 total += val; 423 if ( ! $( this ).closest( '.btQuoteBooking' ).find( '.btPayPalButton' ).length > 0 ) { 424 total += offset; 425 } 426 }); 427 428 c.find( '.btQuoteSwitch' ).not( '.btQuoteMBlock .btQuoteSwitch' ).not( '.btQuoteGBlock .btQuoteSwitch' ).each(function() { 429 if ( $( this ).hasClass( 'on' ) ) { 430 total += bt_parse_float( $( this ).data( 'on' ) ); 431 } else { 432 total += bt_parse_float( $( this ).data( 'off' ) ); 433 } 434 }); 435 436 437 // multiply 438 439 c.find( '.btQuoteMBlock' ).each(function() { 440 441 var m_total = 0; 442 var m_first = true; 443 $( this ).find( '.btQuoteText' ).each(function() { 444 445 var unit_price = bt_parse_float( $( this ).data( 'price' ) ); 446 var val = bt_parse_float( $( this ).val() ); 447 val = val * unit_price; 448 if ( m_first ) { 449 m_total = val; 450 } else { 451 m_total *= val; 452 } 453 m_first = false; 454 455 }); 456 457 $( this ).find( '.btQuoteSelect' ).find( '._msddli_.selected' ).each(function() { 458 459 460 var val = bt_parse_float( $( this ).data( 'value' ) ); 461 462 if ( m_first ) { 463 m_total = val; 464 } else { 465 m_total *= val; 466 } 467 m_first = false; 468 469 }); 470 471 $( this ).find( '.btQuoteSlider' ).each(function() { 472 473 var unit_price = bt_parse_float( $( this ).data( 'price' ) ); 474 var offset = bt_parse_float( $( this ).data( 'offset' ) ); 475 //var val = bt_parse_float( $( this ).slider( 'value' ) ); 476 var val = bt_cc_get_slider_value ( $( this ) ); 477 val = val * unit_price; 478 if ( m_first ) { 479 m_total = val; 480 } else { 481 m_total *= val; 482 } 483 m_total += offset; 484 m_first = false; 485 486 }); 487 488 $( this ).find( '.btQuoteSwitch' ).each(function() { 489 490 if ( $( this ).hasClass( 'on' ) ) { 491 var val = bt_parse_float( $( this ).data( 'on' ) ); 492 } else { 493 var val = bt_parse_float( $( this ).data( 'off' ) ); 494 } 495 if ( m_first ) { 496 m_total = val; 497 } else { 498 m_total *= val; 499 } 500 m_first = false; 501 502 }); 503 504 505 total += m_total; 506 507 }); 508 509 510 511 // group 512 513 c.find( '.btQuoteGBlock' ).each(function() { 514 515 var eval_code = $( this ).data( 'eval' ); 516 517 var group_array = []; 518 519 $( this ).find( '.btQuoteItem .btQuoteItemInput' ).each(function() { 520 521 var val = 0; 522 523 $( this ).find( '.btQuoteText' ).each(function() { 524 var unit_price = bt_parse_float( $( this ).data( 'price' ) ); 525 val = bt_parse_float( $( this ).val() ); 526 val = val * unit_price; 527 }); 528 529 $( this ).find( '.btQuoteSelect' ).find( '._msddli_.selected' ).each(function() { 530 val = bt_parse_float( $( this ).data( 'value' ) ); 531 }); 532 533 $( this ).find( '.btQuoteSlider' ).each(function() { 534 var unit_price = bt_parse_float( $( this ).data( 'price' ) ); 535 var offset = bt_parse_float( $( this ).data( 'offset' ) ); 536 val = bt_cc_get_slider_value( $( this ) ); 537 val = val * unit_price; 538 }); 539 540 $( this ).find( '.btQuoteSwitch' ).each(function() { 541 if ( $( this ).hasClass( 'on' ) ) { 542 val = bt_parse_float( $( this ).data( 'on' ) ); 543 } else { 544 val = bt_parse_float( $( this ).data( 'off' ) ); 545 } 546 }); 547 548 group_array.push( val ); 549 550 }); 551 552 var patt = /\$\d+/igm; 553 var match = eval_code.match( patt ); 554 555 if ( match === null ) { 556 eval_code = atob( eval_code ); 557 match = eval_code.match( patt ); 558 } 559 560 if ( match === null ) { 561 return; 562 } 563 564 for ( var i = 0; i < match.length; i++ ) { 565 eval_code = eval_code.replace( match[ i ], group_array[ i ] ); 566 } 567 568 var g_total = eval( '(function() {' + decodeURIComponent( eval_code ) + '}())' ); 569 570 total += g_total; 571 572 }); 573 574 total = bt_cc_currency_format( c, total ); 575 576 c.find( '.btQuoteTotalCalc' ).html( total ); 577 c.find( '.btQuoteTotalCalc' ).data( 'total', total ); 578 } 579 580 // Init functions 581 582 // Dropdown init 583 584 window.bt_cc_init_dropdown = function( elem, id, index ) { 585 elem.set( "selectedIndex", index ); 586 var ui2 = $( id ).find( '._msddli_.selected' ); 587 var val = elem.getData().data.value; 588 ui2.data( 'value', val ); 589 bt_cc_eval_conditions( val, ui2.closest( '.btQuoteSelect' ).data( 'condition' ) ); 590 bt_quote_total( ui2.closest( '.btQuoteBooking' ) ); 591 bt_paypal_items( ui2.closest( '.btQuoteBooking' ) ); 592 } 593 594 // Base init 595 596 window.bt_cc_init = function( ) { 597 598 $( ".btQuoteBooking" ).each(function( index ) { 599 var c = $( this ); 600 601 // Init elements 602 603 c.find( '.btContactDate' ).datepicker({ 604 prevText: window.bt_cc_translate['prev'], 605 nextText: window.bt_cc_translate['next'],
606 dateFormat: c.data( 'date_format' ), 607 dayNamesMin: [ window.bt_cc_translate['su'], window.bt_cc_translate['mo'], window.bt_cc_translate['tu'], window.bt_cc_translate['we'], window.bt_cc_translate['th'], window.bt_cc_translate['fr'], window.bt_cc_translate['sa'] ], 608 beforeShow: function( input, inst ) { 609 $( '.ui-datepicker' ).addClass( 'btDatePicker' ); 610 } 611 }); 612 // console.log(window.is_rtl); 613 // console.log(window.rtl_direction); 614 c.find( '.btQuoteSlider' ).each(function() { 615 $( this ).slider({ 616 min: ! window.is_rtl ? $( this ).data( 'min' ) : -$( this ).data( 'max' ), 617 max: ! window.is_rtl ? $( this ).data( 'max' ) : -$( this ).data( 'min' ), 618 step: $( this ).data( 'step' ), 619 value: ! window.is_rtl ? $( this ).data( 'value' ) : -$( this ).data( 'value' ), 620 change: function( event, ui ) { 621 // console.log( 'ui.value change: ' + ui.value ); 622 $( this ).find('.btQuoteSliderValue').html( window.rtl_direction * $( this ).slider( 'value' ) ); 623 bt_cc_eval_conditions( window.rtl_direction * $( this ).slider( 'value' ), $( this ).data( 'condition' ) ); 624 } 625 }); 626 bt_cc_eval_conditions( window.rtl_direction * $( this ).data( 'value' ), $( this ).data( 'condition' ) ); 627 }); 628 629 c.find( '.ui-slider-handle' ).each(function() { 630 $( this ).append( $( this ).closest( '.btQuoteItemInput' ).find( $( '.btQuoteSliderValue' ) ) ); 631 }); 632 633 634 c.find( '.btQuoteSlider' ).each(function() { 635 var this_slider = $( this ); 636 $( this ).slider({ 637 slide: function( event, ui ) { 638 var val = window.rtl_direction * ui.value; 639 // console.log( 'ui.value slide: ' + ui.value ); 640 // console.log( 'val slide: ' + val ); 641 this_slider.slider( 'value', val ); 642 this_slider.find('.btQuoteSliderValue').html( val ); 643 bt_quote_total( c ); 644 bt_paypal_items( c ); 645 } 646 }); 647 }); 648 649 650 c.find( '.btQuoteSwitch' ).on( 'click', function() { 651 if ( $( this ).hasClass( 'on' ) ) { 652 $( this ).removeClass( 'on' ); 653 bt_cc_eval_conditions( $( this ).data( 'off' ), $( this ).data( 'condition' ) ); 654 } else { 655 $( this ).addClass( 'on' ); 656 bt_cc_eval_conditions( $( this ).data( 'on' ), $( this ).data( 'condition' ) ); 657 } 658 bt_quote_total( c ); 659 bt_paypal_items( c ); 660 }); 661 662 c.find( '.btQuoteSwitch' ).each( function() { 663 if ( $( this ).hasClass( 'on' ) ) { 664 bt_cc_eval_conditions( $( this ).data( 'on' ), $( this ).data( 'condition' ) ); 665 } else { 666 bt_cc_eval_conditions( $( this ).data( 'off' ), $( this ).data( 'condition' ) ); 667 } 668 }); 669 670 c.find( '.btPayPalButton' ).on( 'click', function() { 671 $( this ).next().submit(); 672 }); 673 674 c.find( '.btQuoteText' ).each(function() { 675 bt_cc_eval_conditions( $( this ).val(), $( this ).data( 'condition' ) ); 676 }); 677 678 c.find( '.btQuoteText' ).keyup(function() { 679 bt_quote_total( c ); 680 bt_paypal_items( c ); 681 bt_cc_eval_conditions( $( this ).val(), $( this ).data( 'condition' ) ); 682 }); 683 684 c.find( '.btContactNext' ).click(function() { 685 $( 'html, body' ).delay( 1000 ).animate({ 686 scrollTop: ( $( this ).closest( '.btQuoteBooking' ).find( '.btTotalQuoteContactGroup' ).offset().top - 30 ) 687 }, 400 ); 688 689 var contact_group = $( this ).closest( '.btQuoteBooking' ).find( '.btTotalQuoteContactGroup' ); 690 691 $( this ).closest( '.btQuoteBooking' ).find( '.btTotalQuoteContactGroup' ).addClass( 'btActive' ); 692 $( this ).closest( '.btQuoteBooking' ).find( '.btQuoteBookingForm' ).removeClass( 'btActive' ); 693 }); 694 695 c.find( '.btContactSubmit' ).click(function() { 696 697 c.find( '.btContactFieldError' ).removeClass( 'btContactFieldError' ); 698 699 var val = true; 700 701 c.find( '.btContactField' ).each(function() { 702 if ( $( this ).parent().hasClass( 'btContactFieldMandatory' ) 703 && ( ( $( this ).val() == '' && ! $( this ).hasClass( 'btContactTime' ) ) 704 || ( $( this ).hasClass( 'btContactTime' ) && $( this ).hasClass( 'btNotSelected' ) ) ) ) { 705 $( this ).parent().addClass( 'btContactFieldError' ); 706 val = false;
707 } 708 }); 709 710 if ( ! val ) { 711 c.find( '.btSubmitMessage' ).hide().html( c.data( 'message_mandatory' ) ).fadeIn(); 712 return false; 713 } 714 715 var quote = ''; 716 var back = 0; 717 var bt_is_odd = function( n ) { 718 return ( n % 2 ) == 1; 719 } 720 721 c.find( '.btQuoteItem' ).each(function() { 722 back++; 723 var item_val = 0; 724 var selected_name = ''; 725 726 $( this ).find( '.btQuoteText' ).each(function() { 727 item_val = bt_parse_float( $( this ).val() ); 728 }); 729 730 $( this ).find( '.btQuoteSelect' ).find( '._msddli_.selected' ).each(function() { 731 selected_name = $( this ).find( '.ddlabel' )[0].innerHTML; 732 if ( $( this ).is( ':first-child' ) ) { 733 selected_name = ''; 734 } 735 item_val = bt_parse_float( $( this ).data( 'value' ) ); 736 }); 737 738 var is_slider = false; 739 var slider_val; 740 $( this ).find( '.btQuoteSlider' ).each(function() { 741 var unit_price = bt_parse_float( $( this ).data( 'price' ) ); 742 // slider_val = bt_parse_float( $( this ).slider( 'value' ) ); 743 slider_val = bt_cc_get_slider_value ( $( this ) ); 744 item_val = slider_val * unit_price; 745 is_slider = true; 746 }); 747 748 $( this ).find( '.btQuoteSwitch' ).each(function() { 749 if ( $( this ).hasClass( 'on' ) ) { 750 item_val = bt_parse_float( $( this ).data( 'on' ) ); 751 } else { 752 item_val = bt_parse_float( $( this ).data( 'off' ) ); 753 } 754 }); 755 756 var label = $( this ).find( 'label' ).html(); 757 758 if ( is_slider ) { 759 label = label + ': ' + slider_val; 760 } 761 762 if ( selected_name != '' ) { 763 selected_name = selected_name.replace( '<span class="description">', '/' ); 764 selected_name = selected_name.replace( '</span>', '' ); 765 label = label + ': ' + selected_name; 766 } 767 768 var background = ''; 769 if ( bt_is_odd( back ) ) background = ' ' + 'style="background:#eee;"'; 770 771 item_val = bt_cc_currency_format( c, item_val ); 772 773 if ( label !== undefined && label !== null ) { 774 quote += encodeURI( '<tr' + background + '>\r\n<td style="padding:.5em;">' + label + '</td>\r\n<td style="text-align:right;padding:.5em;">' + item_val + '</td>\r\n</tr>' ) + "\r\n"; 775 } 776 }); 777 778 var recaptcha_response = ''; 779 if ( typeof grecaptcha !== 'undefined' ) { 780 var recaptcha_response = grecaptcha.getResponse( c.find( '.g-rec' ).data( 'widget_id' ) ); 781 grecaptcha.reset( c.find( '.g-rec' ).data( 'widget_id' ) ); 782 } 783 784 var email_confirmation = 'no'; 785 if ( c.find( '.bt_cc_email_confirmation' ).length ) { 786 if ( c.find( '.bt_cc_email_confirmation' ).prop( 'checked' ) ) { 787 email_confirmation = 'yes'; 788 } 789 } else { 790 email_confirmation = 'yes'; 791 } 792 793 var data = { 794 'action': 'bt_cc', 795 'recaptcha_response': recaptcha_response, 796 'recaptcha_secret': c.data( 'rec_secret_key' ), 797 'admin_email': c.data( 'admin_email' ), 798 'email_client': c.data( 'email_client' ), 799 'currency': c.data( 'currency' ), 800 'currency_after': c.data( 'currency_after' ), 801 'currency_space': c.data( 'currency_space' ), 802 'email_confirmation': email_confirmation, 803 'url_confirmation': c.data( 'url_confirmation' ), 804 'subject': c.data( 'subject' ), 805 'email_header': c.data( 'email_header' ), 806 'email_footer': c.data( 'email_footer' ), 807 'quote' : quote, 808 'total' : c.find( '.btQuoteTotalCalc' ).data( 'total' ), 809 'total_text' : c.data( 'total_text' ), 810 'name' : c.find( '.btContactName' ).val(), 811 'email' : c.find( '.btContactEmail' ).val(), 812 'phone' : c.find( '.btContactPhone' ).val(), 813 'address' : c.find( '.btContactAddress' ).val(), 814 'date' : c.find( '.btContactDate' ).val(), 815 'time' : c.find( '.btContactTime option:selected' ).val(), 816 'date_text': c.data( 'date_text' ), 817 'time_text': c.data( 'time_text' ), 818 'message' : c.find( '.btContactMessage' ).val(), 819 'bt_cc_nonce': c.data( 'bt_cc_nonce' ) 820 }; 821 822 c.find( '.btSubmitMessage' ).hide().html( c.data( 'message_please_wait' ) ).fadeIn(); 823 824 $.ajax({ 825 type: 'POST', 826 url: c.data( 'url_ajax' ),
827 data: data, 828 async: true, 829 success: function( response ) { 830 response = $.trim( response ); 831 if ( response == 'ok' ) { 832 if ( c.data( 'url_confirmation' ) == '' || c.data( 'url_confirmation' ) == null ) { 833 c.find( '.btSubmitMessage' ).hide().html( c.data( 'message_success' ) ).fadeIn(); 834 } else { 835 window.location = c.data( 'url_confirmation' ); 836 } 837 838 } else { 839 c.find( '.btSubmitMessage' ).hide().html( c.data( 'message_error' ) ).fadeIn(); 840 } 841 }, 842 error: function( xhr, status, error ) { 843 c.find( '.btSubmitMessage' ).hide().html( c.data( 'message_error' ) ).fadeIn(); 844 } 845 }); 846 847 return false; 848 849 }); 850 851 // CF 7 support 852 853 c.find( '.wpcf7-submit' ).click(function() { 854 855 856 var val = true; 857 var quote = ''; 858 859 c.find( '.btQuoteItem' ).each(function() { 860 var item_val = 0; 861 var selected_name = ''; 862 863 $( this ).find( '.btQuoteText' ).each(function() { 864 item_val = bt_parse_float( $( this ).val() ); 865 }); 866 867 $( this ).find( '.btQuoteSelect' ).find( '._msddli_.selected' ).each(function() { 868 selected_name = $( this ).find( '.ddlabel' )[0].innerHTML; 869 if ( $( this ).is( ':first-child' ) ) { 870 selected_name = ''; 871 } 872 item_val = bt_parse_float( $( this ).data( 'value' ) ); 873 }); 874 875 var is_slider = false;
876 var slider_val; 877 $( this ).find( '.btQuoteSlider' ).each(function() { 878 var unit_price = bt_parse_float( $( this ).data( 'price' ) ); 879 // slider_val = bt_parse_float( $( this ).slider( 'value' ) ); 880 slider_val = bt_cc_get_slider_value ( $( this ) ); 881 item_val = slider_val * unit_price; 882 is_slider = true; 883 }); 884 885 $( this ).find( '.btQuoteSwitch' ).each(function() { 886 if ( $( this ).hasClass( 'on' ) ) { 887 item_val = bt_parse_float( $( this ).data( 'on' ) ); 888 } else { 889 item_val = bt_parse_float( $( this ).data( 'off' ) ); 890 } 891 }); 892 893 var label = $( this ).find( 'label' ).html(); 894 895 if ( is_slider ) { 896 label = label + ' (' + slider_val + ') ' ; 897 } 898 899 if ( selected_name != '' ) { 900 selected_name = selected_name.replace( '<span class="description">', '/' ); 901 selected_name = selected_name.replace( '</span>', '' ); 902 label = label + ' (' + selected_name + ') '; 903 } 904 905 item_val = bt_cc_currency_format( c, item_val ); 906 907 if ( label !== undefined && label !== null ) { 908 quote += label + ': ' + item_val + "\r\n"; 909 } 910 911 }); 912 913 quote += c.data( 'total_text' ) + ': ' + c.find( '.btQuoteTotalCalc' ).data( 'total' ) + "\r\n"; 914 915 916 c.find( 'input[name=bt-cc-data]' ).val( quote ); 917 //alert( c.find( '[name=bt-cc-data]' ).val() ); 918 919 }); 920 921 922 923 var total = 0; 924 total = total.toFixed( 2 ); 925 bt_quote_total( c ); 926 bt_paypal_items( c ); 927 }); 928 929 930 931 } 932 933 // --------------- 934 // Functions end 935 // --------------- 936 937 // Init 938 939 var bt_cc_init_finished = false; 940 941 document.addEventListener( 'readystatechange', function() { 942 if ( ! bt_cc_init_finished && ( document.readyState === 'interactive' || document.readyState === 'complete' ) ) { 943 944 // base variables 945 window.is_rtl = $( 'body' ).hasClass( 'rtl' ); 946 window.rtl_direction = !window.is_rtl ? 1 : -1; 947 948 bt_cc_init(); 949 bt_cc_init_finished = true; 950 951 } 952 }); 953 954})( jQuery );
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.