igro

Code

Mar 20th, 2015
493
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*
  2. @author Dmitriy Kubarev
  3. @link   http://www.simpleopencart.com
  4. @link   http://www.opencart.com/index.php?route=extension/extension/info&extension_id=4811
  5. */
  6.  
  7. function simplecheckout_submit() {
  8.     simple_fix_onchange_and_click = true;
  9.     if (can_submit_payment_form()) {
  10.         payment_form_submit();
  11.     } else {
  12.         jQuery('#simple_create_order').val(1);
  13.         simplecheckout_reload('create_order');
  14.     }
  15. }
  16.  
  17. function can_submit_payment_form() {
  18.     return jQuery('#simplecheckout_payment_form').length && jQuery('#simplecheckout_payment_form #payment_form_reload').length == 0 && jQuery('#simplecheckout_payment_form .simplecheckout_overlay').length == 0 && jQuery('.agree-warning:visible').length == 0;
  19. }
  20.  
  21. function payment_form_submit() {
  22.     var simplecheckout_payment_form = jQuery('#simplecheckout_payment_form .simplecheckout-block-content');
  23.     var gateway_link = simplecheckout_payment_form.find('div.buttons a:last').attr('href');
  24.     var submit_button = simplecheckout_payment_form.find('div.buttons a:last,div.buttons input[type=button]:last,div.buttons input[type=submit]:last');
  25.     var last_button = simplecheckout_payment_form.find('input[type=button]:last,input[type=submit]:last');
  26.     var last_link = simplecheckout_payment_form.find('a:last').attr('href');
  27.  
  28.     jQuery('#simplecheckout_payment_form').data('is_confirmed', true);
  29.  
  30.     var proceed_show = false;
  31.  
  32.     if (typeof gateway_link != 'undefined' && gateway_link != '' && gateway_link != '#') {
  33.         set_location_hash('proceed_payment');
  34.         overlay_button();
  35.         jQuery.get('index.php?'+simple_route+'route=checkout/simplecheckout/prevent_delete', function(){
  36.             overlay_button_remove();
  37.             location = gateway_link;
  38.             if (!payment_form_visible()) {
  39.                 jQuery('#simplecheckout_proceed_payment').show();
  40.             }
  41.         });
  42.     } else if (submit_button.length) {
  43.         set_location_hash('proceed_payment');
  44.         overlay_button();
  45.         jQuery.get('index.php?'+simple_route+'route=checkout/simplecheckout/prevent_delete', function(){
  46.             overlay_button_remove();
  47.             !submit_button.attr('disabled') && submit_button.click();
  48.             if (!payment_form_visible()) {
  49.                 jQuery('#simplecheckout_proceed_payment').show();
  50.             }
  51.         });
  52.     } else if (last_button.length) {
  53.         set_location_hash('proceed_payment');
  54.         overlay_button();  
  55.         jQuery.get('index.php?'+simple_route+'route=checkout/simplecheckout/prevent_delete', function(){
  56.             overlay_button_remove();
  57.             !last_button.attr('disabled') && last_button.click();
  58.             if (!payment_form_visible()) {
  59.                 jQuery('#simplecheckout_proceed_payment').show();
  60.             }
  61.         });
  62.     } else if (typeof last_link != 'undefined' && last_link != '' && last_link != '#') {
  63.         set_location_hash('proceed_payment');
  64.         overlay_button();
  65.         jQuery.get('index.php?'+simple_route+'route=checkout/simplecheckout/prevent_delete', function(){
  66.             overlay_button_remove();
  67.             location = last_link;
  68.             if (!payment_form_visible()) {
  69.                 jQuery('#simplecheckout_proceed_payment').show();
  70.             }
  71.         });
  72.     }
  73. }
  74.  
  75. function set_button_text() {
  76.     if (can_submit_payment_form()) {
  77.         var simplecheckout_payment_form = jQuery('#simplecheckout_payment_form .simplecheckout-block-content');
  78.  
  79.         var gateway_link = simplecheckout_payment_form.find('div.buttons a:last');
  80.         var submit_button = simplecheckout_payment_form.find('div.buttons input[type=button]:last,div.buttons input[type=submit]:last');
  81.         var last_button = simplecheckout_payment_form.find('input[type=button]:last,input[type=submit]:last');
  82.         var last_link = simplecheckout_payment_form.find('a:last');
  83.        
  84.         if (gateway_link.length) {
  85.             if (gateway_link.text() != '') {
  86.                 jQuery('#simplecheckout_button_confirm span').text(gateway_link.text());  
  87.             } else {
  88.                 jQuery('#simplecheckout_button_confirm span').html(gateway_link.html());  
  89.                 jQuery('#simplecheckout_button_confirm').removeClass('button');
  90.                 jQuery('#simplecheckout_button_confirm').removeClass('btn');
  91.             }
  92.         } else if (submit_button.length) {
  93.             if (submit_button.val() != '') {
  94.                 jQuery('#simplecheckout_button_confirm span').text(submit_button.val());
  95.             }
  96.         } else if (last_button.length) {
  97.             if (last_button.val() != '') {
  98.                 jQuery('#simplecheckout_button_confirm span').text(last_button.val());
  99.             }
  100.         } else if (last_link.length) {
  101.             if (last_link.text() != '') {
  102.                 jQuery('#simplecheckout_button_confirm span').text(last_link.text());
  103.             } else {
  104.                 jQuery('#simplecheckout_button_confirm span').html(last_link.html());
  105.                 jQuery('#simplecheckout_button_confirm').removeClass('button');
  106.                 jQuery('#simplecheckout_button_confirm').removeClass('btn');
  107.             }
  108.         } else {
  109.             jQuery.get('index.php?'+simple_route+'route=checkout/simplecheckout/prevent_delete');
  110.             jQuery('#simplecheckout_form #buttons').hide();
  111.         }
  112.     }
  113. }
  114.  
  115. function move_confirm_button() {
  116.     if (!simple_steps && can_submit_payment_form()) {
  117.         var simplecheckout_payment_form = jQuery('#simplecheckout_payment_form .simplecheckout-block-content');
  118.  
  119.         var gateway_link = simplecheckout_payment_form.find('div.buttons a:last');
  120.         var submit_button = simplecheckout_payment_form.find('div.buttons input[type=button]:last,div.buttons input[type=submit]:last');
  121.         var last_button = simplecheckout_payment_form.find('input[type=button]:last,input[type=submit]:last');
  122.         var last_link = simplecheckout_payment_form.find('a:last');
  123.        
  124.         var obj = false;
  125.  
  126.         if (gateway_link.length) {
  127.             obj = gateway_link;
  128.         } else if (submit_button.length) {
  129.             obj = submit_button;
  130.         } else if (last_button.length) {
  131.             obj = last_button;
  132.         } else if (last_link.length) {
  133.             obj = last_link;
  134.         }
  135.  
  136.         if (obj && obj.hasClass('need_move')) {
  137.             jQuery('#simplecheckout_button_confirm').hide();
  138.             jQuery('#simplecheckout_button_confirm').before(obj);
  139.  
  140.             obj.bind('click', function() {
  141.                 if (!payment_form_visible()) {
  142.                     jQuery('#simplecheckout_proceed_payment').show();
  143.                 }
  144.                 jQuery.get('index.php?'+simple_route+'route=checkout/simplecheckout/prevent_delete');
  145.             });
  146.  
  147.             obj.addClass('simplecheckout_moved_button');
  148.         }
  149.     }
  150. }
  151.  
  152. function set_button_text_for_last_step() {
  153.     if (can_submit_payment_form()) {
  154.         var simplecheckout_payment_form = jQuery('#simplecheckout_payment_form .simplecheckout-block-content');
  155.  
  156.         var gateway_link = simplecheckout_payment_form.find('div.buttons a:last');
  157.         var submit_button = simplecheckout_payment_form.find('div.buttons input[type=button]:last,div.buttons input[type=submit]:last');
  158.         var last_button = simplecheckout_payment_form.find('input[type=button]:last,input[type=submit]:last');
  159.         var last_link = simplecheckout_payment_form.find('a:last');
  160.        
  161.         if (gateway_link.length) {
  162.             jQuery('#simplecheckout_next span').text(gateway_link.text());
  163.         } else if (submit_button.length) {
  164.             jQuery('#simplecheckout_next span').text(submit_button.val());
  165.         } else if (last_button.length) {
  166.             jQuery('#simplecheckout_next span').text(last_button.val());
  167.         } else if (last_link.length && last_link.text().trim() != '') {
  168.             jQuery('#simplecheckout_next span').text(last_link.text());
  169.         } else {
  170.             jQuery.get('index.php?'+simple_route+'route=checkout/simplecheckout/prevent_delete');
  171.             jQuery('#simplecheckout_next').hide();
  172.         }
  173.     }
  174. }
  175.  
  176. function payment_form_visible() {
  177.     return jQuery('#simplecheckout_payment_form .simplecheckout-block-content :visible:not(form)').length > 0;
  178. }
  179.  
  180. function hide_payment_form() {
  181.     if (jQuery('#simplecheckout_payment_form div.buttons').length > 1) {
  182.         jQuery('#simplecheckout_payment_form div.buttons:not(:last)').removeClass('buttons');
  183.         jQuery('#simplecheckout_payment_form div.buttons:last').hide();
  184.     }
  185.  
  186.     if (!payment_form_visible()) {
  187.         jQuery('#simplecheckout_payment_form').hide();
  188.     }
  189. }
  190.  
  191. function block_form() {
  192.     jQuery('input,select,textarea','#simplecheckout_form').attr('disabled', 'disabled');
  193. }
  194.  
  195. function unblock_form() {
  196.     jQuery('input,select,textarea','#simplecheckout_form').removeAttr('disabled');
  197. }
  198.  
  199. function overlay_block(selector) {
  200.     var obj = jQuery("#" + selector);
  201.     if (obj.length > 0) {
  202.         var blockHeight = obj.height();
  203.         var blockWidth =  obj.width();
  204.         var blockOffset = obj.offset();
  205.         obj.append("<div class='simplecheckout_overlay'></div>");
  206.         jQuery("#" + selector + " .simplecheckout_overlay")
  207.             .css({
  208.                 'background' : 'url('+simple_path+'catalog/view/image/loading.gif) no-repeat center center',
  209.                 'opacity' : 0.4,
  210.                 'position': 'absolute',
  211.                 'width': blockWidth,
  212.                 'height': blockHeight,
  213.                 'z-index': 5000
  214.             })
  215.             .offset({top: blockOffset.top,left: blockOffset.left});
  216.     }
  217. }
  218.  
  219. function overlay_button() {
  220.     jQuery('#simplecheckout_button_confirm').attr('disabled', true);
  221.     if (jQuery('.wait').length == 0) {
  222.         jQuery('#simplecheckout_button_confirm').after('<span class="wait">&nbsp;<img src="'+simple_path+'catalog/view/theme/default/image/loading.gif" alt="" /></span>');        
  223.     }
  224. }
  225.  
  226. function overlay_button_remove() {
  227.     jQuery('#simplecheckout_button_confirm').attr('disabled', false);
  228.     jQuery('.wait').remove();
  229. }
  230.  
  231. function customer_field_changed() {
  232.     simplecheckout_reload.field = null;
  233.     if (payment_form_visible()) {
  234.         jQuery('#simplecheckout_payment_form').show();
  235.     }
  236.     var obj = jQuery('#simplecheckout_payment_form');
  237.     if (obj.length > 0 && obj.find('#payment_form_reload').length == 0) {
  238.         obj.find('.simplecheckout-block-content').empty().append('<div id="payment_form_reload" style="padding:5px;height:60px;cursor:pointer;background:url('+simple_path+'catalog/view/image/simple_update.png) no-repeat center center" onclick="simplecheckout_submit(\'save_changes\');">'+jQuery('#need_save_changes').text()+'</div>');
  239.         jQuery('#simplecheckout_button_confirm span').text(jQuery('#default_button').text());
  240.         jQuery('#simplecheckout_button_confirm').show();
  241.         if (!jQuery('#simplecheckout_button_confirm').hasClass('button')) {
  242.             jQuery('#simplecheckout_button_confirm').addClass('button');
  243.             jQuery('#simplecheckout_button_confirm').addClass('btn');
  244.         }
  245.         jQuery('.simplecheckout_moved_button').remove();
  246.         if (!simple_steps) {
  247.             jQuery('#simplecheckout_form #buttons').show();
  248.         }
  249.     }
  250. }
  251.  
  252. function overlay_simplecheckout() {
  253.     overlay_block('simplecheckout_help');
  254.     overlay_block('simplecheckout_agreement');
  255.     overlay_block('simplecheckout_cart');
  256.     overlay_block('simplecheckout_customer');
  257.     overlay_block('simplecheckout_shipping');
  258.     overlay_block('simplecheckout_payment');
  259.     overlay_block('simplecheckout_payment_form');
  260. }
  261.  
  262. function overlay_remove() {
  263.     jQuery(".simplecheckout_overlay").remove();
  264. }
  265.  
  266. function scroll_to_error() {
  267.     if (!simple_steps) {
  268.         if (jQuery('.simplecheckout-warning-block:visible').length > 0) {
  269.             jQuery('.simplecheckout-warning-block').parent().show();
  270.         }
  271.  
  272.         if (jQuery('#simplecheckout_customer .simplecheckout-error-text:visible').length > 0 || jQuery('#simplecheckout-customer-fields .simplecheckout-error-text').length > 0 || jQuery('.simplecheckout-warning-block:visible').length > 0) {
  273.             var offset1 = jQuery('#simplecheckout_customer .simplecheckout-error-text:first').prev().offset();
  274.             offset1 = offset1 ? offset1.top : 10000;
  275.             var offset2 = jQuery('.simplecheckout-warning-block:first').offset();
  276.             offset2 = offset2 ? offset2.top : 10000;
  277.             var offset3 = jQuery('#simplecheckout-customer-fields .simplecheckout-error-text:first').offset();
  278.             offset3 = offset3 ? offset3.top : 10000;
  279.             var offset = offset1 >= offset2 ? offset2 : offset1;
  280.  
  281.             jQuery('html, body').animate({ scrollTop: offset }, 'slow');
  282.         }
  283.  
  284.         if (can_submit_payment_form()) {
  285.             var offset = jQuery('#simplecheckout_payment_form').offset();
  286.             jQuery('html, body').animate({ scrollTop: offset.top }, 'slow');
  287.         }
  288.     }
  289. }
  290.  
  291. function make_tab() {
  292.     if (typeof simplecheckout_reload.field !== 'undefined') {
  293.         var fields = [];
  294.         jQuery('input[type=text]:visible,select:visible,textarea:visible','#simplecheckout_customer').each(function(){
  295.             fields[fields.length] = jQuery(this).attr('id');
  296.         });
  297.  
  298.         var focus = false;
  299.         var focus_key = '';
  300.         for (var i=0;i<fields.length;i++) {
  301.             if (focus) {
  302.                 focus_key = fields[i];
  303.                 break;
  304.             }
  305.             if (fields[i] == simplecheckout_reload.field) {
  306.                 focus = true;
  307.             }
  308.         }
  309.         focus_key = focus_key ? focus_key : simplecheckout_reload.field;
  310.         jQuery('#'+focus_key).focus();
  311.     }
  312. }
  313.  
  314. function set_special_hash() {
  315.     if (jQuery('#customer_registered').length) {
  316.         set_location_hash('customer_registered');
  317.     }
  318.     if (jQuery('.simplecheckout-error-text:visible').length) {
  319.         set_location_hash('warn_in_customer');
  320.     }
  321.     if (jQuery('.simplecheckout-warning-block:visible').length > 0) {
  322.         set_location_hash('warn_in_'+jQuery('.simplecheckout-warning-block:first').parents('div').attr('id'));
  323.     }
  324.     if (can_submit_payment_form()) {
  325.         set_location_hash('wait_for_payment');
  326.     }
  327. }
  328.  
  329. function set_location_hash(hash) {
  330.     window.location.hash = hash;
  331.     back_count--;
  332. }
  333.  
  334. function simplecheckout_step_hide_steps() {
  335.     jQuery('.simplecheckout-block').hide();
  336.     jQuery('.simple-content #buttons').hide();
  337. }
  338.  
  339. function simplecheckout_step_get_current() {
  340.     var step_current = jQuery('#simple_step').val();
  341.     if (!step_current) {
  342.         step_current = jQuery('.simplecheckout-block:not(.simplecheckout-skip):first').attr('id');
  343.         jQuery('#simple_step').val(step_current);
  344.     }
  345.     return step_current;
  346. }
  347.  
  348. function simplecheckout_step_set_current(step) {
  349.     jQuery('#simple_step').val(step);
  350.     set_location_hash(step);
  351. }
  352.  
  353. function simplecheckout_step_create_menu() {
  354.     jQuery('#simplecheckout_step_menu').remove();
  355.     var tpl = '<div id="simplecheckout_step_menu" style="margin-bottom: 10px;">';
  356.     var blocks = [];
  357.     var step_current = simplecheckout_step_get_current();
  358.     var href = true;
  359.     var add_payment_step = true;
  360.     var is_current_step = false;
  361.  
  362.     jQuery('.simplecheckout-block:not(.simplecheckout-skip)').each(function() {
  363.         is_current_step = false;
  364.  
  365.         var text = jQuery(this).find('.simplecheckout-block-heading:first').contents(':not(span)').text().trim();
  366.  
  367.         var step = jQuery(this).attr('id');
  368.        
  369.         if (step == 'simplecheckout_cart') {
  370.             text = jQuery('#text_cart').text().trim();
  371.         }
  372.        
  373.         if (step == step_current) {
  374.             href = false;
  375.             is_current_step = true;
  376.         }
  377.        
  378.         if (href) {
  379.             blocks[blocks.length] = '<span class="' + (is_current_step ? 'simple-step-current simple-step-completed' : 'simple-step-completed') + '">' + '<a href="'+window.location+'" onclick="simplecheckout_step_show(\''+step+'\'); return false;">'+text+'</a>' + '</span>';
  380.         } else {
  381.             blocks[blocks.length] = '<span class="' + (is_current_step ? 'simple-step-current simple-step-completed' : 'simple-step') + '">' + text + '</span>';  
  382.         }
  383.        
  384.         if (step == 'simplecheckout_payment_form') {
  385.             add_payment_step = false;
  386.         }
  387.     });
  388.    
  389.     if (add_payment_step) {
  390.         blocks[blocks.length] = '<span class="simple-step">' + jQuery('#payment_form_title').text().trim() + '</span>';
  391.     }
  392.  
  393.     tpl = tpl + blocks.join('&nbsp;<span class="simple-step-delimiter">&raquo;</span>&nbsp;') + '</div>';
  394.    
  395.     jQuery('#simplecheckout_form').prepend(tpl);
  396.  
  397.     jQuery('.simple-step-delimiter').html('<img src="'+simple_path+'catalog/view/image/next_gray.png">');
  398.     jQuery('.simple-step-delimiter + .simple-step-completed').prev().html('<img src="'+simple_path+'catalog/view/image/next_green.png">');
  399. }
  400.  
  401. function simplecheckout_step_show(step) {
  402.     if (step) {
  403.         simplecheckout_step_hide_steps();
  404.         step_prev = jQuery('#'+step).prev('.simplecheckout-block:not(.simplecheckout-skip)').attr('id');
  405.         if (!step_prev) {
  406.             jQuery('#simplecheckout_prev').hide();
  407.         } else {
  408.             jQuery('#simplecheckout_prev').show();
  409.         }
  410.         simplecheckout_step_set_current(step);
  411.         simplecheckout_step_check_agree(step);
  412.         simplecheckout_step_check_comment();
  413.         jQuery('#simplecheckout_next span').text(jQuery('#button_next').text());
  414.         simplecheckout_step_create_menu();
  415.         jQuery('#'+step).slideDown('slow');
  416.     }
  417. }
  418.  
  419. function simplecheckout_step_check_agree(step) {
  420.     if (jQuery('#agree').length) {
  421.         var step_checking = 'simplecheckout_agreement';
  422.         if (jQuery('#simplecheckout_agreement').length == 0) {
  423.             step_checking = jQuery('.simplecheckout-block:not(.simplecheckout-skip):last').attr('id');
  424.             if (step_checking == 'simplecheckout_payment_form') {
  425.                 step_checking = jQuery('#'+step_checking).prev('.simplecheckout-block:not(.simplecheckout-skip)').attr('id');
  426.             }
  427.         }
  428.         if (step == step_checking) {
  429.             if (jQuery('#simple_agree_for_step').length == 0) {
  430.                 var tpl = '<span id="simple_agree_for_step">'+jQuery('#agree').parent().html()+'</span>&nbsp;';
  431.                 jQuery('#simplecheckout_next').before(tpl);
  432.                 jQuery('#buttons #agree').remove();
  433.             } else {
  434.                 jQuery('#simple_agree_for_step').show();
  435.             }
  436.         } else {
  437.             jQuery('#simple_agree_for_step').hide();
  438.             jQuery('.agree-warning').hide();
  439.         }
  440.     }
  441. }
  442.  
  443. function simplecheckout_step_check_comment() {
  444.     var step_current = simplecheckout_step_get_current();
  445.     if (step_current != 'simplecheckout_customer' && step_current != 'simplecheckout_shipping' && step_current != 'simplecheckout_payment') {
  446.         jQuery('#comment_box').hide();
  447.     } else {
  448.         jQuery('#comment_box').show();
  449.     }
  450. }
  451.  
  452. function simplecheckout_step_init(from) {
  453.     if (simple_steps) {
  454.         simplecheckout_step_hide_steps();
  455.  
  456.         var step_current = simplecheckout_step_get_current();
  457.        
  458.         if (from == 'start') {
  459.             jQuery('#'+step_current).slideDown('slow');
  460.             set_location_hash(step_current);
  461.         } else if (from != 'next_step') {
  462.             jQuery('#'+step_current).show();
  463.             set_location_hash(step_current);
  464.         } else if (from == 'next_step') {
  465.             var simple_errors = jQuery('#simple_errors').val().split(',');
  466.  
  467.             if (jQuery.inArray(step_current, simple_errors) >= 0) {
  468.                 jQuery('#'+step_current).show();
  469.                 set_location_hash(step_current);
  470.             } else {
  471.                 var step_next = jQuery('#'+step_current).nextAll('.simplecheckout-block:not(.simplecheckout-skip)').attr('id');
  472.                 if (step_next && step_next != 'simplecheckout_payment_form') {
  473.                     step_current = step_next;
  474.                     simplecheckout_step_set_current(step_current);
  475.                     jQuery('#'+step_current).slideDown('slow');
  476.                 } else if (step_next == 'simplecheckout_payment_form') {
  477.                     step_current = 'simplecheckout_payment_form';
  478.                     simplecheckout_step_set_current(step_current);
  479.                     if (simple_steps_summary) {
  480.                         jQuery('#simplecheckout_payment_form .simplecheckout-block-heading').after(jQuery('#simple_summary'));
  481.                         jQuery('#simple_summary').show();
  482.                         jQuery('#simplecheckout_payment_form').slideDown('slow');
  483.                         jQuery('#simplecheckout_payment_form .simplecheckout-block-content').css('border','0px').css('padding','0px');
  484.                         if (jQuery('#simplecheckout_payment_form .simplecheckout-block-content :visible:not(form)').length == 0) {
  485.                             jQuery('#simplecheckout_payment_form .simplecheckout-block-content').hide();
  486.                             jQuery('#simplecheckout_payment_form #simple_summary').css('margin-bottom', '0px');
  487.                         }
  488.                         set_button_text_for_last_step();
  489.                     } else {
  490.                         jQuery('#simplecheckout_payment_form').show();
  491.                         hide_payment_form();
  492.                         if (can_submit_payment_form() && !payment_form_visible()) {
  493.                             jQuery('#simplecheckout_payment_form').prev('.simplecheckout-block:not(.simplecheckout-skip)').show();
  494.                             payment_form_submit();
  495.                         } else {
  496.                             jQuery('#simplecheckout_payment_form .simplecheckout-block-content').css('border','0px').css('padding','0px');
  497.                             set_button_text_for_last_step();
  498.                             jQuery('#simplecheckout_payment_form').hide();
  499.                             jQuery('#simplecheckout_payment_form').slideDown('slow');
  500.                         }
  501.                     }
  502.                 } else {
  503.                     simplecheckout_step_set_current(step_current);
  504.                     jQuery('#'+step_current).show();
  505.                 }
  506.             }
  507.         }
  508.         var step_prev = jQuery('#'+step_current).prev('.simplecheckout-block:not(.simplecheckout-skip)').attr('id');
  509.         if (!step_prev) {
  510.             jQuery('#simplecheckout_prev').hide();
  511.         }
  512.         simplecheckout_step_check_agree(step_current);
  513.         simplecheckout_step_create_menu();
  514.         simplecheckout_step_check_comment();
  515.     }
  516. }
  517.  
  518. function simplecheckout_prev() {
  519.     var step_current = simplecheckout_step_get_current();
  520.     simplecheckout_step_show(jQuery('#'+step_current).prev('.simplecheckout-block:not(.simplecheckout-skip)').attr('id'));
  521. }
  522.  
  523. function simplecheckout_next() {
  524.     jQuery('#simple_step_next').val(1);
  525.     var step_current = simplecheckout_step_get_current();
  526.     if (step_current == 'simplecheckout_payment_form') {
  527.         if (can_submit_payment_form()) {
  528.             payment_form_submit();
  529.         }
  530.     } else {
  531.         var step_next = jQuery('#'+step_current).nextAll('.simplecheckout-block:not(.simplecheckout-skip)').attr('id');
  532.         if (!step_next || step_next == 'simplecheckout_payment_form') {
  533.             jQuery('#simple_create_order').val(1);
  534.         }
  535.         simplecheckout_reload('next_step');
  536.     }
  537. }
  538.  
  539. function simplecheckout_reload(from) {
  540.     if (simple_steps && (from == 'shipping_changed' || from == 'payment_changed')) {
  541.         return;
  542.     }
  543.  
  544.     var data = jQuery('#simplecheckout_form').find('input,select,textarea').serialize();
  545.  
  546.     if (!data.length) {
  547.         return;
  548.     }
  549.     set_location_hash(from);
  550.     simple_fix_onchange_and_click = false;
  551.     jQuery.ajax({
  552.         url: 'index.php?'+simple_route+'route=checkout/simplecheckout',
  553.         data: data,
  554.         type: 'POST',
  555.         dataType: 'text',
  556.         beforeSend: function() {
  557.             block_form();
  558.             overlay_simplecheckout();
  559.             overlay_button();
  560.             jQuery('#payment_form_reload').text(jQuery('#saving_changes').text());
  561.         },      
  562.         success: function(data) {
  563.             jQuery('#simplecheckout_form').replaceWith(data);
  564.             simplecheckout_init(from);
  565.             make_tab();
  566.             scroll_to_error();
  567.  
  568.             jQuery('#simplecheckout_payment_form').data('is_confirmed', false);
  569.  
  570.             if ((from == 'create_order' || simple_fix_onchange_and_click) && can_submit_payment_form() && !payment_form_visible()) { //&& simple_asap) {
  571.                 payment_form_submit();
  572.             }
  573.         },
  574.         error: function(xhr, ajaxOptions, thrownError) {
  575.             console.log(thrownError + "\r\n" + xhr.statusText + "\r\n" + xhr.responseText);
  576.             unblock_form();
  577.             overlay_remove();
  578.         }
  579.     });
  580. }
  581.  
  582. function set_places() {
  583.     var fields = [];
  584.  
  585.     jQuery('#simplecheckout_customer tr[place]').each(function() {
  586.         var place = jQuery(this).attr('place');
  587.         if (place == '' || place == 'customer') {
  588.             return;
  589.         }
  590.         fields[place] = typeof fields[place] != 'undefined' ? fields[place] : '';
  591.         fields[place] += '<tr>' + jQuery(this).html() + '</tr>';
  592.         jQuery(this).remove();
  593.     });
  594.  
  595.     for (var place in fields) {
  596.         jQuery('#simplecheckout_' + place + ' .simplecheckout-methods-table:last').after(
  597.             '<table style="width:100%;" class="simplecheckout-customer-fields">' + fields[place] + '</table>'
  598.         );
  599.     }    
  600. }
  601.  
  602. function move_comment() {
  603.     if (jQuery('#simplecheckout_customer #checkout_customer_main_comment').is('textarea')) {
  604.         var target = '';
  605.         if (simple_comment_target == 'bottom' || simple_steps || (jQuery('#simplecheckout_customer:visible').length == 0 && !simple_comment_target)) {
  606.             target = '#simplecheckout_proceed_payment';
  607.             if (!simple_steps && jQuery('#simplecheckout_payment_form').length) {
  608.                 target = '#simplecheckout_payment_form';
  609.             }
  610.         } else if (simple_comment_target && simple_comment_target != 'bottom') {
  611.             target = '#simplecheckout_'+simple_comment_target;
  612.         }
  613.  
  614.         if (target) {
  615.             var comment_box_tpl = '<div id="comment_box" style="width:100%;margin-bottom:15px;clear:both;"><div class="simplecheckout-block-heading">'+jQuery('#checkout_customer_main_comment').parent().prev().html()+'</div>'+jQuery('#checkout_customer_main_comment').parent().html()+'</div>';
  616.             if (target == '#simplecheckout_proceed_payment' || target == '#simplecheckout_payment_form') {
  617.                 jQuery(target).before(comment_box_tpl);
  618.             } else {
  619.                 jQuery(target).after(comment_box_tpl);
  620.             }
  621.             jQuery('#simplecheckout_customer #checkout_customer_main_comment').parents('tr').remove();
  622.             jQuery('#checkout_customer_main_comment').css('width', '99%');
  623.         }
  624.     }
  625. }
  626.  
  627. function simplecheckout_init(from) {
  628.     set_places();
  629.     set_masks();
  630.     set_placeholders();
  631.     set_datepickers();
  632.     set_autocomplete();
  633.     set_popups();
  634.     set_button_text();
  635.     move_confirm_button();
  636.     set_special_hash();
  637.     hide_payment_form();
  638.     set_googleapi();
  639.     move_comment();  
  640.     simplecheckout_step_init(from);
  641.     simplecheckout_selector_init(from);
  642.     set_cart_colspan();
  643. }
  644.  
  645. function set_cart_colspan() {
  646.     jQuery('.simplecheckout-recurring-product').attr('colspan', jQuery('.simplecheckout-cart th:visible').length);
  647. }
  648.  
  649. function simplecheckout_show_selector(block) {
  650.     jQuery('.simple-geo-selector-' + block).show();
  651.     jQuery('#simple_geo_selector_' + block).hide();
  652.  
  653.     jQuery('body').data(block + '_selector_used', true);
  654. }
  655.  
  656. function simplecheckout_selector_init(from) {
  657.     if (jQuery('#simple_geo_selector_customer').length) {
  658.         jQuery('#checkout_customer_main_country_id').attr('reload','checkout_customer_changed');
  659.         jQuery('#checkout_customer_main_zone_id').attr('reload','checkout_customer_changed');
  660.     }
  661.  
  662.     if (jQuery('#simple_geo_selector_address').length) {
  663.         jQuery('#checkout_address_main_country_id').attr('reload','checkout_address_changed');
  664.         jQuery('#checkout_address_main_zone_id').attr('reload','checkout_address_changed');
  665.     }
  666.  
  667.     if (from == 'checkout_customer_changed' || from == 'checkout_address_changed') {
  668.         if (jQuery('body').data('customer_selector_used')) {
  669.             simplecheckout_show_selector('customer');
  670.         }
  671.  
  672.         if (jQuery('body').data('address_selector_used')) {
  673.             simplecheckout_show_selector('address');
  674.         }  
  675.     }
  676. }
  677.  
  678. function simplecheckout_load_block(block) {
  679.     jQuery.ajax({
  680.         url: 'index.php?'+simple_route+'route=checkout/simplecheckout_block',
  681.         data: 'block='+block,
  682.         type: 'GET',
  683.         dataType: 'text',
  684.         success: function(data) {
  685.             var allowed = ['simplecheckout_shipping','simplecheckout_payment','simplecheckout_cart','simplecheckout_customer'];
  686.             if (allowed.join(',').indexOf(block) >= 0) {
  687.                 jQuery('div#'+block).html(data);
  688.             } else {
  689.                 jQuery('div#'+block).replaceWith(data);
  690.             }
  691.            
  692.             if (jQuery('div#'+block+' :visible:not(form)').length == 0) {
  693.                 jQuery('div#'+block).removeClass('simplecheckout-block');
  694.             } else {
  695.                 jQuery('div#'+block).addClass('simplecheckout-block');
  696.             }
  697.         }
  698.     });
  699. }
  700.  
  701. function simplecheckout_login() {
  702.     jQuery.ajax({
  703.         url: 'index.php?'+simple_route+'route=checkout/simplecheckout_customer/login',
  704.         data: jQuery('#simplecheckout_login input'),
  705.         type: 'POST',
  706.         dataType: 'text',
  707.         success: function(data) {
  708.             jQuery('#simplecheckout_login').replaceWith(data);
  709.         }
  710.     });
  711. }
  712.  
  713. function simple_login_open() {
  714.     var parent_position = jQuery('#simple_login_layer').parent().css('position');
  715.     if (jQuery('#simple_login_layer').length == 0 || parent_position == 'fixed' || parent_position == 'relative' || parent_position == 'absolute') {
  716.         jQuery('#simple_login_layer').remove();
  717.         jQuery('#simple_login').remove();
  718.         jQuery('body').append('<div id="simple_login_layer" onclick="simple_login_close();"></div><div id="simple_login"><div id="simple_login_header"><img style="cursor:pointer;" src="'+simple_path+'catalog/view/image/close.png" onclick="simple_login_close();"></div><div id="simple_login_content"></div></div>');
  719.     }
  720.     jQuery('#simple_login').show();
  721.     jQuery('#simple_login_content').load('index.php?'+simple_route+'route=checkout/simplecheckout_customer/login');
  722.     var loginHeight = jQuery(document).height();
  723.     var loginWidth = jQuery(window).width();
  724.     jQuery('#simple_login_layer').css('height', loginHeight);
  725.     var winH = jQuery(window).height();
  726.     var winW = jQuery(window).width();
  727.     jQuery('#simple_login').css('top',  winH/2-jQuery('#simple_login').height()/2);
  728.     jQuery('#simple_login').css('left', winW/2-jQuery('#simple_login').width()/2);
  729.     jQuery('#simple_login_layer').fadeTo(500,0.8);
  730.     return false;
  731. }
  732.  
  733. function simple_login_close() {
  734.     jQuery('#simple_login_layer').fadeOut(500, function() {
  735.         jQuery('#simple_login_layer').hide().css('opacity','1');
  736.     });
  737.     jQuery('#simple_login').fadeOut(500, function() {
  738.         jQuery('#simple_login').hide();
  739.         jQuery('#simple_login_content').empty();
  740.     });
  741. }
  742.  
  743. jQuery(function(){
  744.  
  745.     simplecheckout_init('start');
  746.  
  747.     jQuery('input[reload]:not([autocomplete]):not([googleapi]),select[reload],textarea[reload]').live('change', function(){
  748.         var from = jQuery(this).attr('reload');
  749.         simplecheckout_reload.field = null;
  750.         if (from.indexOf('checkout_') == 0) {
  751.             simplecheckout_reload.field = jQuery(this).attr('id');
  752.         }
  753.         simplecheckout_reload(from);
  754.     });
  755.  
  756.     jQuery('#simplecheckout_form input, #simplecheckout_form textarea').live('keydown', function(){
  757.         if (jQuery(this).parents('#simplecheckout_payment_form').length) {
  758.             return;
  759.         }
  760.         customer_field_changed();
  761.     });
  762.  
  763.     jQuery('#simplecheckout_form input[type=radio]:not([reload]),#simplecheckout_form input[type=checkbox]:not([reload]),#simplecheckout_form select:not([reload])').live('change', function(){
  764.         if (jQuery(this).parents('#simplecheckout_payment_form').length) {
  765.             return;
  766.         }
  767.         customer_field_changed();
  768.     });
  769.  
  770.     jQuery('#agree').live('change', function(){
  771.         var checked = jQuery(this).attr('checked') ? 1 : 0;
  772.         if (!checked) {
  773.             jQuery('.agree-warning').slideDown('fast');
  774.         } else {
  775.             jQuery('.agree-warning').slideUp('fast');
  776.         }
  777.     });
  778.  
  779.     jQuery('#checkout_customer_main_email').live('change',function(){
  780.         jQuery(this).next().remove();
  781.         if (jQuery(this).parent().prev().find('.simplecheckout-required').length && jQuery(this).val()) {
  782.             var register = ~~jQuery('input[name=register]:checked').val();
  783.             jQuery.ajax({
  784.                 url: 'index.php?'+simple_route+'route=checkout/simplecheckout_customer/check_email',
  785.                 data: { email : jQuery(this).val(), register : register },
  786.                 type: 'GET',
  787.                 dataType: 'text',
  788.                 success: function(data) {
  789.                     if (data) {
  790.                         jQuery('#checkout_customer_main_email').after('<span class="simplecheckout-error-text">'+data+'</span>');
  791.                     }
  792.                 }
  793.             });
  794.         }
  795.     });
  796.  
  797.     jQuery('#email_confirm').live('change',function(){
  798.         var confirm = jQuery(this).val().trim();
  799.         var email = jQuery('#checkout_customer_main_email').val().trim();
  800.         if (confirm != email) {
  801.             jQuery('#email_confirm_error').show();
  802.         } else {
  803.             jQuery('#email_confirm_error').hide();
  804.         }
  805.     });
  806.  
  807.     jQuery('table.cart td.remove img,.mini-cart-info td.remove img,table.s_cart_items a.s_button_remove').live('click', function(){
  808.         simplecheckout_reload('header_cart_changed');
  809.     });
  810.  
  811.     jQuery('html,body').keydown(function(event){
  812.         if (event.keyCode == 27) {
  813.             simple_login_close();
  814.         }
  815.     });
  816.  
  817.     /*window.onbeforeunload = function (evt) {
  818.         if (can_submit_payment_form() && !jQuery('#simplecheckout_payment_form').data('is_confirmed')) {
  819.             var message = jQuery('#please_confirm').text();
  820.             if (typeof evt == "undefined") {
  821.                 evt = window.event;
  822.             }
  823.             if (evt) {
  824.                 evt.returnValue = message;
  825.             }
  826.             //jQuery('#please_confirm_box').length == 0 && jQuery('.simple-content').before('<div id="please_confirm_box">'+message+'</div>');
  827.             return message;
  828.         }
  829.     }*/
  830. });
Advertisement
Add Comment
Please, Sign In to add comment