JavaScript Utilities & UI Interactions in function.js
This document covers the purpose, functionality, and integration of the linuxfront-v2-logistics/js/function.js file. It implements common UI behaviors, responsive tweaks, and third-party plugin initializations to enhance user experience on the Tech Logistics frontend.
🔗 Dependencies
This script relies on several libraries and assets:
- jQuery (v1.x or later) for DOM manipulation and event handling
- Slick Carousel for the partner logos slider
- Fancybox for iframe popups (shipment tracking)
- Google reCaptcha for bot protection on forms
- CSS classes such as
.main-navigation,.animatable, and.modal-boxdefined in PHP templates
| Library | Purpose | Source / Template |
|---|---|---|
| jQuery | Core DOM API | Loaded via inc/template_meta.php |
| Slick Carousel | Carousel slider | Installed via npm / slick.min.js |
| Fancybox | Modal iframe popups | Installed via npm / jquery.fancybox.min.js |
| Google reCaptcha | Spam protection | <script src="https://www.google.com/recaptcha/api.js"></script> |
| Header markup | Sticky navbar container | inc/panels/header-menu.php |
{
"commands": {
"npm": "npm install jquery slick-carousel @fancyapps/fancybox",
"yarn": "yarn add jquery slick-carousel @fancyapps/fancybox",
"pnpm": "pnpm add jquery slick-carousel @fancyapps/fancybox",
"bun": "bun add jquery slick-carousel @fancyapps/fancybox"
}
}
Document Ready Wrapper
This IIFE ensures all code runs only after the DOM is fully loaded, avoiding race conditions.
jQuery(document).ready(function($) {
// All UI behaviors initialized here
});
Scroll-to-Top Button ⬆️
Allows users to quickly return to the top of the page by clicking elements with .btn-backTop.
$('.btn-backTop').on("click", function() {
$('html, body').animate({ scrollTop: 0 }, 800);
return false;
});
Responsive ReCaptcha Scaling 🔒
Automatically scales the Google reCaptcha widget when its container is narrower than 302 px, preserving layout integrity.
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');
}
On-Scroll Animations ✨
Detects .animatable elements entering the viewport on scroll, swaps them to .animated to trigger CSS animations, and then unbinds the handler when done.
(function($) {
var doAnimations = function() {
var offset = $(window).scrollTop() + $(window).height(),
$elems = $('.animatable');
if ($elems.length === 0) $(window).off('scroll', doAnimations);
$elems.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');
})(jQuery);
Mobile Shipment Icon Adjustment 📱
On window resize, swaps classes on .fa-track-shipment for a mobile-friendly style when viewport is under 600 px.
$(window).resize(function () {
if ($(window).width() < 600) {
$(".fa-track-shipment")
.removeClass("fieldst-account")
.addClass("track-mobile");
}
});
Accordion & Contact Toggles ⚙️
Simple slide toggles for FAQ and contact widgets:
$('.accordion-toggle').click(function() {
$('.mw-collapse').slideToggle();
});
$('.contact_icon').click(function() {
$('.abc').slideToggle();
});
Partners Logo Carousel 🎞️
Initializes a Slick slider on .customer-logos to showcase partner logos responsively.
$('.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 } }
]
});
Custom Modal System 🖼️
Creates an overlay and centers modal boxes opened via links with data-modal-id. Handles open/close and dynamic centering.
var appendOverlay = "<div class='modal-overlay js-modal-close'></div>";
$('a[data-modal-id]').click(function(e) {
e.preventDefault();
$('body').append(appendOverlay);
$('.modal-overlay').fadeTo(500, 0.7);
var target = $(this).attr('data-modal-id');
$('#' + target).fadeIn($(this).data());
});
$('.js-modal-close, .modal-overlay').click(function() {
$('.modal-box, .modal-overlay').fadeOut(500, function() {
$('.modal-overlay').remove();
});
});
// Re-center on resize
$(window).resize(function() {
$('.modal-box').css({
top: ($(window).height() - $('.modal-box').outerHeight()) / 2,
left: ($(window).width() - $('.modal-box').outerWidth()) / 2
});
}).resize();
Shipment Tracking Form Popup 🚚
Intercepts the #track_shipment form submission, builds the tracking URL using a SITE_PATH PHP constant, and opens the result in a Fancybox iframe.
$('#track_shipment').submit(function() {
var $ = jQuery.noConflict();
var shipNo = $('#shipment_number').val();
var url = "<?=SITE_PATH?>" + "track_shipment.php?ship_no=" + shipNo;
$.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;
});
Sticky Navigation Bar 📌
Adds a fixed class to the .main-navigation container once the user scrolls past 63 px. This class is defined in inc/panels/header-menu.php.
$(window).scroll(function() {
if ($(this).scrollTop() > 63) {
$('.main-navigation').addClass('fixed');
} else {
$('.main-navigation').removeClass('fixed');
}
});
Shipment Table Wrapper 🗄️
Wraps the #myshipmentstable table inside a <div> to facilitate responsive or scrollable table behavior.
$('#myshipmentstable').wrap('<div id="myshipmentstable_wrap"></div>');
Integration & Related Templates
These behaviors tie into several PHP/HTML templates:
- Navbar Markup:
.main-navigationlives ininc/panels/header-menu.php - ReCaptcha Script: Loaded via
track_shipment_meta.php - Tracking Form Structure: The form with ID
track_shipmentappears intrack_shipment_content.php - Modal Containers:
<div class="modal-box" id="...">used in various page templates with matchingdata-modal-idattributes
This comprehensive documentation outlines every interactive and responsive feature in function.js, along with its dependencies and template integrations.