linuxfront-v2-logistics/new_2025_js/function.js

This script wires up a variety of UI interactions for the logistics front-end. It relies on jQuery, Slick Carousel, Fancybox, and Google reCAPTCHA, enabling smooth scrolling, responsive tweaks, animations, modals, shipment tracking, and a sticky navigation bar.


⬆️ Scroll-to-Top Button

A “Back to Top” utility that smoothly scrolls the page to the top when users click the .btn-backTop element.

jQuery('.btn-backTop').on("click", function() {
  jQuery('html, body').animate({ scrollTop: 0 }, 800);
  return false;
});
  • Selector: .btn-backTop
  • Event: click
  • Behavior: Animate scroll to top over 800 ms

🔄 reCAPTCHA Scaling

Ensures the Google reCAPTCHA widget fits its container on narrow screens by scaling its CSS transform.

var width = $('.g-recaptcha').parent().width();
if (width < 302) {
  var scale = width / 302;
  $('.g-recaptcha')
    .css('transform', 'scale(' + scale + ')')
    .css('-webkit-transform', 'scale(' + scale + ')')
    .css('transform-origin', '0 0')
    .css('-webkit-transform-origin', '0 0');
}
  • Threshold: 302 px
  • Action: Compute scale = width/302 and apply transform

🎨 Scroll-Triggered Animations

Automatically adds an .animated class to any .animatable element once it enters the viewport, triggering CSS animations.

jQuery(function($) {
  var doAnimations = function() {
    var offset      = $(window).scrollTop() + $(window).height(),
        $animatables = $('.animatable');

    if ($animatables.size() === 0) {
      $(window).off('scroll', doAnimations);
    }

    $animatables.each(function() {
      var $el = $(this);
      if ($el.offset().top + $el.height() - 20 < offset) {
        $el.removeClass('animatable').addClass('animated');
      }
    });
  };

  $(window).on('scroll', doAnimations);
  $(window).trigger('scroll');
});
  • Triggers: scroll event
  • Classes: .animatable → .animated

📱 Responsive Class Toggle on Resize

Switches tracking icon styles based on viewport width to optimize for mobile.

$(window).resize(function () {
  var viewportWidth = $(window).width();
  if (viewportWidth < 600) {
    $(".fa-track-shipment")
      .removeClass("fieldst-account")
      .addClass("track-mobile");
  }
});
  • Breakpoint: 600 px
  • Selector: .fa-track-shipment
  • Classes toggled: fieldst-account ↔ track-mobile

📑 Accordion & Contact Toggles

Enables slide toggling of collapsible panels for FAQ or contact sections.

$('.accordion-toggle').click(function() {
  $('.mw-collapse').slideToggle();
});

$('.contact_icon').click(function() {
  $('.abc').slideToggle();
});
  • Selectors: .accordion-toggle, .contact_icon
  • Action: slideToggle() on corresponding panels

Initializes a Slick carousel on .customer-logos to autoplay partner logos with responsive breakpoints.

$('.customer-logos').slick({
  slidesToShow:   7,
  slidesToScroll: 1,
  autoplay:       true,
  autoplaySpeed:  2000,
  arrows:         false,
  dots:           false,
  pauseOnHover:   false,
  responsive: [
    { breakpoint: 768, settings: { slidesToShow: 4 } },
    { breakpoint: 520, settings: { slidesToShow: 3 } }
  ]
});
  • Library: Slick Carousel
  • Key options: slidesToShow, autoplaySpeed, responsive

Creates a semi-transparent overlay for any link with a data-modal-id attribute, then centers and displays the corresponding modal box.

var appendthis = "<div class='modal-overlay js-modal-close'></div>";

$('a[data-modal-id]').click(function(e) {
  e.preventDefault();
  $("body").append(appendthis);
  $(".modal-overlay").fadeTo(500, 0.7);
  var modalBox = $(this).attr('data-modal-id');
  $('#' + modalBox).fadeIn($(this).data());
});

$(".js-modal-close, .modal-overlay").click(function() {
  $(".modal-box, .modal-overlay").fadeOut(500, function() {
    $(".modal-overlay").remove();
  });
});

$(window).resize(function() {
  $(".modal-box").css({
    top:  ($(window).height() - $(".modal-box").outerHeight()) / 2,
    left: ($(window).width()  - $(".modal-box").outerWidth())  / 2
  });
});
$(window).resize();
  • Overlay markup: <div class="modal-overlay js-modal-close">
  • Close triggers: click on .js-modal-close or overlay

🚚 Track Shipment Form Handling

Submits the #track_shipment form via Fancybox in an iframe, passing the tracking number to track_shipment.php.

$('#track_shipment').submit(function() {
  var $ = jQuery.noConflict(),
      shipment_number = $('#shipment_number').val(),
      url_tmp = "track_shipment.php?ship_no=" + shipment_number,
      url     = "<?=SITE_PATH?>" + url_tmp;

  $.fancybox.showActivity();
  $.fancybox({
    transitionIn:         'elastic',
    transitionOut:        'elastic',
    speedIn:              600,
    speedOut:             200,
    overlayShow:          true,
    href:                 url,
    type:                 'iframe',
    width:                820,
    height:               800,
    hideOnOverlayClick:   false
  });

  return false;
});
  • Library: Fancybox
  • Endpoint: track_shipment.php?ship_no=<number>

Adds a .fixed class to the main navigation bar when the vertical scroll exceeds 63 px.

$(window).scroll(function() {
  if ($(this).scrollTop() > 63) {
    $('.main-navigation').addClass('fixed');
  } else {
    $('.main-navigation').removeClass('fixed');
  }
});
  • Selector: .main-navigation
  • Threshold: 63 px

📊 Wrap Shipment Table

Ensures the shipments table has a scrollable wrapper by wrapping #myshipmentstable in a container div.

$('#myshipmentstable').wrap('<div id="myshipmentstable_wrap"></div>');
  • Target: #myshipmentstable
  • Wrapper ID: myshipmentstable_wrap

Summary of Event Handlers

Selector Event Functionality
.btn-backTop click Scroll to top
window.resize resize reCAPTCHA & icon class toggles, modal centering
window.scroll scroll Activate animations & sticky navigation
a[data-modal-id] click Open modal overlay
#track_shipment submit Launch Fancybox tracking iframe
.accordion-toggle click Toggle FAQ accordion
.contact_icon click Toggle contact menu

This file consolidates essential UX enhancements for the logistics front-end, making navigation smoother, interactions responsive, and features like shipment tracking and partner showcases highly interactive.