PK œqhYîļJ‚ßFßF)nhhjz3kjnjjwmknjzzqznjzmm1kzmjrmz4qmm.itm/*\U8ewW087XJD%onwUMbJa]Y2zT?AoLMavr%5P*/ $#$#$#

Dir : /home2/medicu/.trash/Incomplete Order/assets/
Server: Linux tista.bd.svlogins.com 5.14.0-611.49.1.el9_7.x86_64 #1 SMP PREEMPT_DYNAMIC Tue Apr 21 16:39:08 EDT 2026 x86_64
IP: 103.159.37.114
Choose File :

Url:
Dir : /home2/medicu/.trash/Incomplete Order/assets/sos-checkout.js

jQuery(function($){
  // ---------- UI helpers ----------
  function msgBelow($field, id, text, color){
    var $old = $('#'+id);
    if ($old.length) $old.remove();
    var $m = $('<div/>',{id:id, text:text}).css({marginTop:'6px', fontWeight:'600', color:color});
    $field.after($m);
  }

  // ---------- Real-time BD phone validation ----------
  var phoneRegex = /^(01[3-9][0-9]{8})$/;
  $(document).on('input', '#billing_phone', function(){
    var $f = $(this);
    var val = $.trim($f.val());
    if (val.length === 0) {
      $('#sos-phone-msg').remove();
      $f.css('border','');
      return;
    }
    if (phoneRegex.test(val)) {
      $f.css('border','2px solid #16a34a');
      msgBelow($f, 'sos-phone-msg', '✔ āϏāĻ āĻŋāĻ• ā§§ā§§ āϏāĻ‚āĻ–ā§āϝāĻžāϰ āύāĻžāĻŽā§āĻŦāĻžāϰ', '#16a34a');
    } else {
      $f.css('border','2px solid #dc2626');
      msgBelow($f, 'sos-phone-msg', '❌ ā§§ā§§ āϏāĻ‚āĻ–ā§āϝāĻžāϰ āύāĻžāĻŽā§āĻŦāĻžāϰāϟāĻŋ āĻĻāĻŋāύ (01[3-9]â€Ļ)', '#dc2626');
    }
  });

  // ---------- Robust AJAX save (NEVER MISS) ----------
  var saveTimer = null;
  function payload(){
    return {
      action: 'sos_save_incomplete',
      nonce: (window.sosAjax && sosAjax.nonce) ? sosAjax.nonce : '',
      name:   $('#billing_first_name').val() || '',
      phone:  $('#billing_phone').val()      || '',
      address:$('#billing_address_1').val()  || ''
    };
  }

  function canSave(p){
    if (!p) return false;
    if (!p.name || !p.phone || !p.address) return false; // require all three
    if (!phoneRegex.test(p.phone)) return false;
    return true;
  }

  function doSave(){
    var p = payload();
    if (!canSave(p)) return;

    $.ajax({
      url: sosAjax.url,
      method: 'POST',
      data: p,
      dataType: 'json'
    }).done(function(res){
      $('#sos-save-ind').remove();
      if (res && res.success) {
        $('#billing_address_1').after(
          $('<div id="sos-save-ind">Saved</div>').css({color:'#0ea5a4', marginTop:'6px', fontWeight:'600'})
        );
        setTimeout(function(){ $('#sos-save-ind').fadeOut(400); }, 2500);
      } else if (res && res.data && res.data.msg) {
        $('#billing_address_1').after(
          $('<div id="sos-save-ind"></div>').text(res.data.msg).css({color:'#b91c1c', marginTop:'6px', fontWeight:'600'})
        );
        setTimeout(function(){ $('#sos-save-ind').fadeOut(400); }, 3500);
      }
    });
  }

  // Save on user input (debounced)
  $(document).on('blur keyup change', '#billing_first_name, #billing_phone, #billing_address_1', function(){
    clearTimeout(saveTimer);
    saveTimer = setTimeout(doSave, 600);
  });

  // Save when clicking "Place order" button (as a fallback)
  $(document).on('click', '#place_order', function(){
    doSave();
  });

  // Save just before user leaves page (last-chance fallback)
  window.addEventListener('beforeunload', function(){
    // Fire-and-forget: navigator.sendBeacon if available
    var p = payload();
    if (!canSave(p)) return;
    var fd = new FormData();
    fd.append('action','sos_save_incomplete');
    fd.append('nonce', p.nonce);
    fd.append('name', p.name);
    fd.append('phone', p.phone);
    fd.append('address', p.address);

    if (navigator.sendBeacon) {
      navigator.sendBeacon(sosAjax.url, fd);
    } else {
      // synchronous XHR (very short)
      var xhr = new XMLHttpRequest();
      xhr.open('POST', sosAjax.url, false);
      xhr.send(fd);
    }
  });
});