Save time by giving your drivers the ability to submit fuel receipts, search for fuel locations and more with the Penske Driver app, available for Apple or Android.
See and manage your fleet data in real-time, in one place, whether you're on a computer, tablet or phone. Quickly prioritize urgent tasks and identify key performance indicators and trends.
There is no Penske location in search area. Please retry your search.
Pick-Up Locations Not Found
No pick-up locations found in selected area. Please retry your search using an alternate city or ZIP code.
Drop-Off Locations Not Found
No drop-off locations found in selected area. Please retry your search using an alternate city or ZIP code.
No Locations Found
No pick-up or drop-off locations in selected area. Please retry your search using alternate cities or ZIP codes.
System Error, Please Call
Sorry, our site is currently experiencing issues. Please call us at
1-844-847-9577
, or try again later.
No 22' Trucks Available
There is no immediate availability for the truck size you have selected. Would you like to view other available truck sizes or change your dates?
No Trucks Available
There is no immediate availability in your area on the pick-up date you selected. Please call us at
1-844-847-9577
to discuss options..
Locations Not Found
Sorry, we can't find any results in your search area. Please retry your search using an alternate location.
Something Went Wrong
Please try again. If the problem continues, restart your reservation or call
1-844-847-9577
.
Change Time or Call
Online reservations must be made at least 3 hours before pickup in your location’s time zone and must have a minimum duration of 24 hours. To continue, select a new pickup date or call
1-844-906-3404
.
Change Time or Call
Online reservations must be made at least 24 hours before pickup in your location’s time zone and must have a minimum duration of 24 hours. To continue, select a new pickup date or call
1-844-906-3404
.
Change Time or Call
Online reservations must be made at least 48 hours before pickup in your location’s time zone and must have a minimum duration of 24 hours. To continue, select a new pickup date or call
1-844-906-3404
.
Return to Pickup
Location?
It looks like you’ll be staying within 25 miles of your pickup location. Returning your truck to the same location may offer you a lower cost. Would you like to return your truck to the pickup location or keep the selected drop-off spot?
What's the Difference?
Location Options
Different Location(Drop-off at different location)
Same Location(Drop-off at same location)
Return Truck To
Different Location
Same Location
Truck Offers
12', 16', 22', 26' Truck
Cargo Van, 12', 16', 26' Truck
Rental Quote
Pay on a per-trip basis
Pay for the miles/days used
Trip Type
Long Distance, Interstate
Short Distance, Same City
Distance to Destination
Over 25 miles
Within 25 miles
Drop-off Date
Distance determines
drop-off date
Same day to up to 9 days
Mileage
Unlimited Mileage
Pay per mileage used
Additional Days
Up to 3 days: $100 eachUp to three additional days at $100 per day
Our fuel-efficient small box trucks and rental vans can supplement your last-mile fleet during seasonal surges and go the distance for all your delivery needs. If you need a box truck rental with a liftgate or without, we have the right truck for your business available today. Our light-duty fleet consists of box truck sizes from 12 to 18 feet.
Every light-duty box truck rental comes equipped with:
Automatic transmission
Air conditioning
AM/FM radio; AUX or USB input
Power steering and anti-lock brakes
Dual-faced mirrors for better vision
Questions?
Our team is here to help you with all of your commercial rental needs. Call us at 1-844-906-3404 or visit a nearby Penske location.
The specifications listed above are based on Penske's most commonly rented fleet. They are not the exact measurements of all vehicles rented by Penske. Specifications will vary by make, model and year. MPG can vary based on load, terrain and driving factors.
Our fuel-efficient small box trucks and rental vans can supplement your last-mile fleet during seasonal surges and go the distance for all your delivery needs. If you need a box truck rental with a liftgate or without, we have the right truck for your business available today. Our light-duty fleet consists of box truck sizes from 12 to 18 feet.
Every light-duty box truck rental comes equipped with:
Automatic transmission
Air conditioning
AM/FM radio; AUX or USB input
Power steering and anti-lock brakes
Dual-faced mirrors for better vision
Questions?
Our team is here to help you with all of your commercial rental needs. Call us at 1-844-906-3404 or visit a nearby Penske location.
The specifications listed above are based on Penske's most commonly rented fleet. They are not the exact measurements of all vehicles rented by Penske. Specifications will vary by make, model and year. MPG can vary based on load, terrain and driving factors.
20% New Customer Discount20% New Customer Discount
Get 20% off your first business rental for up to 30 days. Call
1-844-906-3404
and mention new customer discount promotion.
Light-duty vehicles at Penske include trucks and vans with a gross vehicle weight (GVW) of up to 17,500 lbs. and a payload capacity of up to 7,200 lbs. This includes cargo vans and box trucks.
Q:
What types of trucks are used for delivery?
A:
For your light-duty delivery needs, like last mile services, seasonal surges and other small business needs, Penske offers box trucks, cargo vans and refrigerated trucks for rent.
Q:
Which truck is best for delivery?
A:
All of our light-duty box truck rentals can work well for your delivery needs. Things to keep in mind before choosing a truck include the weight and amount of product that needs to be transported and any travel constraints you may have, such as narrow city streets or on-street parking.
Q:
What are the different size box trucks?
A:
Penske offers several light-duty box trucks for rent including 12 ft. and 16 ft. box trucks, and 16 ft. and 18 ft. cabover trucks.
Q:
What is the smallest box truck?
A:
The 12 ft. box truck is our smallest box truck and is used by customers looking for 78 sq. ft. of floor space and 450 cu. ft. of loading space for deliveries.
Q:
What is the difference between light-, medium- and heavy-duty trucks?
A:
The U.S. organizes vehicles by class based on their gross vehicle weight rating (GVWR), or maximum operating weight of the vehicle. These classes then fall into one of three divisions – light-duty, medium-duty or heavy-duty vehicles. Currently, Class 1-3 trucks are light-duty, Class 4-6 trucks are medium-duty, and Class 7-8 are considered heavy-duty.
Q:
How much space does a delivery truck need?
A:
The space needed for a delivery truck will vary depending on the needs of the business. Penske offers a variety of vehicle sizes within our light-duty division, including options offering anywhere from 260 cu. ft. to 950 cu. ft. of loading space.
Q:
What can you haul in a box truck?
A:
A box truck is great for hauling anything you need to transport, including less-than-truckload (LTL) freight such as parcel delivery, furniture hauling and food delivery. Box trucks are also used to deliver printed newspapers, haul appliances, transport weekly deliveries to retail stores or manage last-mile or seasonal surges.
Q:
What is the most reliable light-duty truck?
A:
Every vehicle at Penske is reliable due in part to our rigorous and routine preventive maintenance schedules. To ensure your vehicle is running efficiently, Dynamic PM®, our unique data-driven service, delivers the right preventive maintenance, at the right time, for each vehicle. In the unlikely event of a breakdown, one call to the Penske 24/7 Roadside Assistance team is all you need, no matter where you are, to get back on the road as soon as possible.
Q:
What box truck gets the best fuel mileage?
A:
The cargo van, high-roof cargo van, 12 ft. box truck, 16 ft. box truck and 16 ft. cabover truck all get 12 mpg. The 18 ft. cabover truck gets 13 mpg. Our light-duty electric cargo van can travel up to 108 miles between charges.
});
});
window.REBELMOUSE_ACTIVE_TASKS_QUEUE.push(function(){
const canadaDropoffIcon = document.querySelector(
".rental-widget-form i.canadian-dropoff-element"
);
const canadaDropoffAlert = document.querySelector(
".rental-widget-form .canadian-dropoff"
);
function onOutsideClick(event) {
if (
event.type !== "mouseleave" &&
(
event.target == canadaDropoffIcon ||
event.target == canadaDropoffAlert ||
event.target.closest(".rental-widget-form .canadian-dropoff")
)
) {
return;
}
canadaDropoffAlert.classList.add("hidden");
document.removeEventListener("click", onOutsideClick, { passive: true });
canadaDropoffIcon.removeEventListener("mouseleave", onOutsideClick);
}
function onDropoffIconClick() {
canadaDropoffAlert.classList.remove("hidden");
document.addEventListener("click", onOutsideClick, { passive: true });
canadaDropoffIcon.addEventListener("mouseleave", onOutsideClick);
}
canadaDropoffIcon.addEventListener("click", onDropoffIconClick, {
passive: true,
});
//Change placeholder value for inputs in Topbar
// Function to update the placeholder based on screen size
function updateTopbarValues() {
let widget_TB = document.querySelector('.top-promo .rental-widget-container');
if (widget_TB) {
let pickup_date_TB = document.querySelector('.top-promo .pickup-date-time .dates-fieldset input');
let dropoff_date_TB = document.querySelector('.top-promo .dropoff-date-time .dates-fieldset input');
let pickup_time_head_TB = document.querySelector('.top-promo .pickup-time-select .heading');
let dropoff_time_head_TB = document.querySelector('.top-promo .dropoff-time-select .heading');
let pickup_time_val_TB = document.querySelector('.top-promo .quote_pickup_time_select span');
let dropoff_time_val_TB = document.querySelector('.top-promo .quote_dropoff_time_select span');
if (window.innerWidth < 768) {
pickup_date_TB.placeholder = "Date";
dropoff_date_TB.placeholder = "Date";
pickup_time_head_TB.innerHTML = "Time";
dropoff_time_head_TB.innerHTML = "Time";
if(!pickup_time_val_TB.classList.contains('date-time-val')) {
pickup_time_val_TB.innerHTML = "Time";
}
if(!dropoff_time_val_TB.classList.contains('date-time-val')) {
dropoff_time_val_TB.innerHTML = "Time";
}
} else {
pickup_date_TB.placeholder = "Pick-Up Date";
dropoff_date_TB.placeholder = "Drop-Off Date";
pickup_time_head_TB.innerHTML = "Pick-Up Time";
dropoff_time_head_TB.innerHTML = "Drop-Off Time";
if(!pickup_time_val_TB.classList.contains('date-time-val')) {
pickup_time_val_TB.innerHTML = "Pick-Up Time";
}
if(!dropoff_time_val_TB.classList.contains('date-time-val')) {
dropoff_time_val_TB.innerHTML = "Drop-Off Time";
}
}
}
}
// Initial call to set placeholder based on the screen size
//updateTopbarValues();
// Event listener for resizing the window
//window.addEventListener('resize', updateTopbarValues);
});
window.REBELMOUSE_ACTIVE_TASKS_QUEUE.push(function(){
function fixTextWidow(element) {
let wordArray = element.textContent.split(" ");
const filteredArray = wordArray.filter(function(element) {
return element.trim() !== "";
});
if (filteredArray.length > 1) {
filteredArray[filteredArray.length - 2] += " " + filteredArray[filteredArray.length - 1];
filteredArray.pop();
element.innerHTML = filteredArray.join(" ");
}
}
/*REBELMOUSE_STDLIB.createElementChangeListener(".post-header h1 .widget__headline-text", function(element){
fixTextWidow(element);
})*/
REBELMOUSE_STDLIB.createElementChangeListener(".widget__headline .widget__headline-text", function(element){
fixTextWidow(element);
})
REBELMOUSE_STDLIB.createElementChangeListener(".rm-breadcrumb__item:last-of-type .rm-breadcrumb__link", function(element){
fixTextWidow(element);
})
REBELMOUSE_STDLIB.createElementChangeListener(".current-post .body-description h2", function(element){
let spanElement = element.querySelector("span");
let supElem = element.querySelector("sup");
if (spanElement == null && supElem == null) {
fixTextWidow(element);
}
})
REBELMOUSE_STDLIB.createElementChangeListener(".current-post .body-description h3", function(element){
let spanElement = element.querySelector("span");
let supElem = element.querySelector("sup");
if (!element.classList.contains('h3-img') && spanElement == null && supElem == null) {
fixTextWidow(element);
}
})
REBELMOUSE_STDLIB.createElementChangeListener(".current-post .body-description h4", function(element){
fixTextWidow(element);
})
REBELMOUSE_STDLIB.createElementChangeListener(".current-post .body-description .acc-header", function(element){
fixTextWidow(element);
})
REBELMOUSE_STDLIB.createElementChangeListener(".callouts-wrapper .widget__subheadline-text p", function(element){
fixTextWidow(element);
})
REBELMOUSE_STDLIB.createElementChangeListener(".callouts-wrapper .custom-field-callout-title", function(element){
fixTextWidow(element);
})
REBELMOUSE_STDLIB.createElementChangeListener(".sidebar-post .widget__subheadline-text p", function(element){
fixTextWidow(element);
})
REBELMOUSE_STDLIB.createElementChangeListener(".section-header h1.title", function(element){
fixTextWidow(element);
})
REBELMOUSE_STDLIB.createElementChangeListener(".truck-info h2.text-element", function(element){
fixTextWidow(element);
})
REBELMOUSE_STDLIB.createElementChangeListener(".container.trucks h1", function(element){
fixTextWidow(element);
})
REBELMOUSE_STDLIB.createElementChangeListener(".subtitle .text-element", function(element){
fixTextWidow(element);
})
// REVERT WIDOWS ON INDUSTRY ARTICLES COMMERCIAL HOMEPAGE CALLOUTS
function removeNonBreakingSpace(element) {
element.innerHTML = element.innerHTML.replace(/ /g, " ");
}
REBELMOUSE_STDLIB.createElementChangeListener(".industry-articles .widget__headline .widget__headline-text", function(element) {
removeNonBreakingSpace(element);
});
REBELMOUSE_STDLIB.createElementChangeListener(".tag-beverage-manufacturing-industry .widget__headline .widget__headline-text", function(element) {
removeNonBreakingSpace(element);
});
REBELMOUSE_STDLIB.createElementChangeListener(".tag-healthcare-industry .widget__headline .widget__headline-text", function(element) {
removeNonBreakingSpace(element);
});
REBELMOUSE_STDLIB.createElementChangeListener(".no-break", function(element) {
removeNonBreakingSpace(element);
});
});
window.REBELMOUSE_ACTIVE_TASKS_QUEUE.push(function(){
function removeEmptyParagraphBeforeDiv() {
// Select all divs with the class "rebellt-item"
document.querySelectorAll('div.rebellt-item').forEach(function(div) {
// Check if the previous sibling is a
element
var prevElem = div.previousElementSibling;
if (prevElem && prevElem.tagName.toLowerCase() === 'p') {
// Check if the
element is empty or contains only or whitespace
if (prevElem.innerHTML.trim() === '' || prevElem.innerHTML.trim() === ' ') {
prevElem.remove(); // Remove the empty
element
}
}
});
}
// Call the function to remove empty
elements before .rebellt-item divs
removeEmptyParagraphBeforeDiv();
});
window.REBELMOUSE_ACTIVE_TASKS_QUEUE.push(function(){
//function about single click and double click to open dropdown and redirects in topbar
let navbarLinks = document.querySelectorAll(".right-side .navbar .item .text-element a");
function doubleClick () {
if (window.innerWidth >= 768 && window.innerWidth <= 1199) {
document.querySelector(".topbar-wrapper").classList.add("touch-nav");
REBELMOUSE_STDLIB.createElementChangeListener(".right-side .navbar .item .text-element a", function(el){
let doubleClicked = false;
el.addEventListener("click", (e)=>{
e.preventDefault();
let dropdownDiv = document.querySelectorAll(".right-side .navbar .item .dropdown");
dropdownDiv.forEach((item) => {
item.classList.remove("tablet-dropdown")
})
setTimeout(() => {
let parent = el.parentNode.parentNode;
let dropdown = parent.querySelector(".dropdown");
if (dropdown) {
dropdown.classList.add("tablet-dropdown")
}
},500)
// if doubleclicked is true then redirect to link
if (doubleClicked) {
window.location.href = el.href
}
doubleClicked = true;
setTimeout(() => {
doubleClicked = false;
}, 300);
})
})
document.querySelector("body").addEventListener("click", (e)=>{
let dropdownLinks = document.querySelectorAll(".right-side .navbar .item a");
let isTrue = []
dropdownLinks.forEach((item) => {
if (e.target != item) {
isTrue.push(false)
} else {
isTrue.push(true);
}
})
if (!isTrue.includes(true)) {
document.querySelectorAll(".right-side .navbar .item .dropdown").forEach((item => {
item.classList.remove("tablet-dropdown")
}))
}
//console.log(isTrue);
})
} else {
document.querySelector(".topbar-wrapper").classList.remove("touch-nav")
}
}
doubleClick();
//Open Dropdowns menu with clicks for screen >= 768 && screen <= 1199
window.addEventListener("resize", (event) => {
doubleClick();
});
let scrollPosition = 0; // Store the current scroll position
function disableScroll() {
document.body.style.overflow = 'hidden';
}
function enableScroll() {
document.body.style.overflow = 'unset';
}
REBELMOUSE_STDLIB.createElementChangeListener(".hamburger-wrapper", function(el){
let menuIcon = el.querySelector(".hamburger");
let hamburgerWrapper = el.querySelector('.dark-overlay');
let loginBtn = el.querySelector('.login-icon');
let langBtn = el.querySelector('.language-icon');
let closeBtn = el.querySelector('.close-icon');
let hamLogBlock = el.querySelector('.ham-login-block');
let hamLangBlock = el.querySelector('.ham-lang-block');
let hamSearchBlock = el.querySelector('.ham-search-block');
let searchBtn = el.querySelector('.search-icon');
let searchWidget = el.querySelector('.search-container');
let searchClose = searchWidget.querySelector('.close');
menuIcon.addEventListener('click', () => {
hamburgerWrapper.classList.toggle('hidden');
if(hamburgerWrapper.classList.contains('hidden')) {
enableScroll();
} else {
disableScroll();
}
});
closeBtn.addEventListener('click', () => {
hamburgerWrapper.classList.toggle('hidden');
enableScroll();
});
loginBtn.addEventListener('click', ()=>{
hamLogBlock.classList.toggle("hidden");
hamLangBlock.classList.add('hidden');
hamSearchBlock.classList.add('hidden');
loginBtn.querySelector('.account-bold').classList.toggle("hidden");
loginBtn.querySelector('.account').classList.toggle("hidden");
langBtn.querySelector('.lang').classList.remove("hidden");
langBtn.querySelector('.lang-bold').classList.add("hidden");
searchBtn.querySelector('svg').classList.remove("ham-search-bold");
langBtn.querySelector('.navbar-line').classList.add('hidden');
searchBtn.querySelector('.navbar-line')?.classList?.add('hidden');
loginBtn.querySelector('.navbar-line').classList.toggle('hidden');
})
langBtn.addEventListener('click', ()=>{
hamLogBlock.classList.add("hidden");
hamSearchBlock.classList.add('hidden');
hamLangBlock.classList.toggle('hidden');
loginBtn.querySelector('.account-bold').classList.add("hidden");
loginBtn.querySelector('.account').classList.remove("hidden");
searchBtn.querySelector('svg').classList.remove("ham-search-bold");
langBtn.querySelector('.lang').classList.toggle("hidden");
langBtn.querySelector('.lang-bold').classList.toggle("hidden");
langBtn.querySelector('.navbar-line').classList.toggle('hidden');
searchBtn.querySelector('.navbar-line')?.classList?.add('hidden');
loginBtn.querySelector('.navbar-line').classList.add('hidden');
})
searchBtn.addEventListener('click', () => {
//searchWidget.classList.toggle('hidden');
hamLogBlock.classList.add("hidden");
hamSearchBlock.classList.toggle('hidden');
hamLangBlock.classList.add('hidden');
langBtn.querySelector('.lang').classList.remove("hidden");
loginBtn.querySelector('.account').classList.remove("hidden");
loginBtn.querySelector('.account-bold').classList.add("hidden");
langBtn.querySelector('.lang-bold').classList.add("hidden");
searchBtn.querySelector('.navbar-line')?.classList?.toggle('hidden')
langBtn.querySelector('.navbar-line').classList.add('hidden');
loginBtn.querySelector('.navbar-line').classList.add('hidden');
});
searchBtn.querySelector('svg').classList.add("ham-search-bold");
searchClose.addEventListener('click', () => {
searchWidget.classList.toggle('hidden');
})
})
REBELMOUSE_STDLIB.createElementChangeListener(".ham-links-block .item", function(el){
//console.log(el);
//let right = el.querySelector('.angle-right');
//let left = el.querySelector('.angle-left');
el.addEventListener('click', (e) => {
let text = el.querySelector(".text-element").textContent.toLowerCase();
console.log(text);
let dropdown = el.querySelector('.dropdown');
let header = el.querySelector('.ham-header');
if (e.target == header) {
dropdown.classList.remove('open');
//document.querySelector(".ham-main-links").classList.remove("upd-height");
document.querySelector(".ham-main-links").style.height = `auto`;
} else {
if (dropdown) {
console.log("here here")
dropdown.classList.add('open');
let div_height = dropdown.getBoundingClientRect().height;
console.log(dropdown.getBoundingClientRect().height);
document.querySelector(".ham-main-links").style.height = `${div_height}px`;
/*if (text == "plan your move" || text == "need help?") {
document.querySelector(".ham-main-links").classList.add("upd-height");
}*/
}
}
})
})
REBELMOUSE_STDLIB.createElementChangeListener(".nav-icons .search-icon", function(el){
el.addEventListener('click', (event) => {
let parentNode = el.parentNode;
el.style.outline = "none";
if(el.classList.contains("key-focus")){ el.classList.remove("key-focus")}
let icon = el.querySelector(".search-icon");
el.classList.toggle('select');
let searchBox = document.querySelector('.nav-icons .dropdown.search');
let line = document.querySelector('.nav-search .navbar-line');
if (el.classList.contains('select')) {
searchBox.setAttribute('style', 'display:grid !important');
line.setAttribute('style', 'display:block !important');
} else {
searchBox.setAttribute('style', 'display:none !important');
line.setAttribute('style', 'display:none !important');
}
})
})
//close search desktop dropdown when user click outside of search container
window.addEventListener("click", function(event) {
let iconbtn = document.querySelector(".nav-search .search-icon");
let inputWrapper = document.querySelector(".nav-search #search--definition");
let dropdown = document.querySelector(".nav-search .dropdown.search");
if (event.target == iconbtn || event.target.parentNode == inputWrapper || event.target == dropdown) {
//console.log("same");
} else {
document.querySelector(".nav-icons .search-icon").classList.remove('select');
document.querySelector('.nav-icons .dropdown.search').setAttribute('style', 'display:none !important');
document.querySelector('.nav-search .navbar-line').setAttribute('style', 'display:none !important');
}
//console.log(event.target.parentNode);
});
});
window.REBELMOUSE_ACTIVE_TASKS_QUEUE.push(function(){
window.addEventListener("keydown", (e) => {
if(e.key === "Tab"){
REBELMOUSE_STDLIB.createElementChangeListener(".topbar-wrapper .nav-icons svg", function(el){
let item = el.parentNode;
//detec if focus is by tab keyboard
//el.addEventListener("keydown", (e) => {
el.classList.add("key-focus");
//});
el.addEventListener("focusin", (e) => {
//show dropdown
let dropdown = item.querySelector('.dropdown');
if (dropdown) {
//remove keyshow class
document.querySelectorAll(".navbar .dropdown.key-show").forEach((item) => {
item.classList.remove("key-show");
})
dropdown.classList.add("key-show");
}
el.addEventListener("focusout", (e) => {
item.classList.remove("key-focus");
})
})
})
}
//remove focus from default nav.menu-global links
REBELMOUSE_STDLIB.createElementChangeListener(".menu-global a", function(el){
el.tabIndex = '-1';
})
document.querySelector(".top-promo").tabIndex = '0';
REBELMOUSE_STDLIB.createElementChangeListener(".topbar-wrapper .navbar .text-element a", function(el){
//console.log(el);
el.addEventListener("focusin", () => {
let item = el.parentNode.parentNode;
let dropdown = item.querySelector('.dropdown');
if (dropdown) {
//remove keyshow class
document.querySelectorAll(".navbar .dropdown.key-show").forEach((item) => {
item.classList.remove("key-show");
})
dropdown.classList.add("key-show");
}
})
})
REBELMOUSE_STDLIB.createElementChangeListener(".topbar-wrapper", function(el){
el.addEventListener("mouseover", ()=>{
document.querySelectorAll(".navbar .item ").forEach((item)=>{
if(item.querySelector(".dropdown")){
item.querySelector(".dropdown").classList.remove("key-show")
}
})
})
})
REBELMOUSE_STDLIB.createElementChangeListener(".nav-lang a:last-child", function(el){
//console.log(el);
el.addEventListener("focusin", () => {
el.addEventListener("keydown", (e) => {
if(e.key === "Tab"){
e.preventDefault();
//alert("Tab Key Pressed");
el.parentNode.classList.remove("key-show");
document.querySelector(".top-promo").classList.remove("hidden");
document.querySelector(".top-promo").tabIndex = '0';
}
});
})
})
REBELMOUSE_STDLIB.createElementChangeListener(".promo-desktop .all-promo-link", function(el){
el.addEventListener("focusin", () => {
document.querySelector(".all-promotions").style.display = "block";
let lastChild = document.querySelector(".all-promotions .promo-cont:last-child .order-btn");
lastChild.addEventListener("focusin", () => {
lastChild.addEventListener("focusout", () => {
document.querySelector(".all-promotions").style.display = "none";
document.querySelector(".promo-desktop .promo-btn").focus();
})
})
})
})
})
// Remove accessibility to link images when images have text redirecting to the same link
REBELMOUSE_STDLIB.createElementChangeListener("a img", function(el){
let parent = el.parentNode;
if (parent.tagName === 'A') {
parent.setAttribute("tabIndex", "-1");
}
})
// COMMERCIAL WIDGET KEYBOARD ACCESSIBILITY
REBELMOUSE_STDLIB.createElementChangeListener(".booking-container form", function(el){
el.addEventListener('keydown', function(event) {
if (event.key === 'Enter') {
event.preventDefault();
}
});
})
REBELMOUSE_STDLIB.createElementChangeListener(".returnto-input-container input", function(el){
el.addEventListener("keydown", (event)=>{
if(event.key === "Enter") {
el.click();
}
})
})
REBELMOUSE_STDLIB.createElementChangeListener(".booking-container .quote-submit-button button", function(el){
el.addEventListener('keydown', function(event) {
if (event.key === 'Enter') {
el.click();
}
});
})
//remove tabindex of calkendar input
function removeCalendarTabInd(el, section) {
el.addEventListener("focus", () => {
if (document.querySelector(`.${section} .pickup-date-time commercial-date-selector`)) {
document.querySelector(`.${section} .pickup-date-time commercial-date-selector .cr-date-picker__input`).setAttribute("tabindex", "-1");
document.querySelector(`.${section} .dropoff-date-time commercial-date-selector .cr-date-picker__input`).setAttribute("tabindex", "-1");
}
})
}
REBELMOUSE_STDLIB.createElementChangeListener(".home-rental .pickup-container input", function(el){
removeCalendarTabInd(el, "home-rental");
})
REBELMOUSE_STDLIB.createElementChangeListener(".top-promo .pickup-container input", function(el){
removeCalendarTabInd(el, "top-promo");
})
REBELMOUSE_STDLIB.createElementChangeListener(".sidebar .pickup-container input", function(el){
removeCalendarTabInd(el, "sidebar");
})
function keybLocItem(el, section) {
el.setAttribute("tabindex", "0");
el.addEventListener("keydown", (event) => {
if(event.key === 'Enter') {
el.click();
el.parentNode.parentNode.classList.add("hidden");
document.querySelector(`.${section} .pickup-date-time .cr-date-picker__input`).focus();
}
})
}
REBELMOUSE_STDLIB.createElementChangeListener(".home-rental .dropdown-loc .location-item", function(el){
keybLocItem(el, "home-rental")
})
REBELMOUSE_STDLIB.createElementChangeListener(".top-promo .dropdown-loc .location-item", function(el){
keybLocItem(el, "top-promo")
})
REBELMOUSE_STDLIB.createElementChangeListener(".sidebar .dropdown-loc .location-item", function(el){
keybLocItem(el, "sidebar")
})
function keylastLocItem(el, section) {
el.addEventListener('keydown', function(event) {
if (event.key === 'Tab' && event.shiftKey) {
console.log('Shift + Tab was pressed');
} else if (event.key === 'Tab') {
el.parentNode.parentNode.classList.add("hidden");
let commercialCalendar = document.querySelector(`.${section} .pickup-date-time .cr-date-picker__input`);
if(commercialCalendar) {
commercialCalendar.focus();
}
}
});
}
REBELMOUSE_STDLIB.createElementChangeListener(".home-rental .dropdown-loc .location-item:nth-of-type(5)", function(el){
keylastLocItem(el, "home-rental")
})
REBELMOUSE_STDLIB.createElementChangeListener(".top-promo .dropdown-loc .location-item:nth-of-type(5)", function(el){
keylastLocItem(el, "top-promo")
})
REBELMOUSE_STDLIB.createElementChangeListener(".sidebar .dropdown-loc .location-item:nth-of-type(5)", function(el){
keylastLocItem(el, "sidebar")
})
function keyCurrLoc(el, section, inputType) {
el.setAttribute("tabindex", "0");
el.addEventListener("focus", () => {
setTimeout(()=>{
el.parentNode.classList.remove("hidden");
document.querySelector(`.${section} .${inputType} .gmap-loc`).style.display = 'block';
el.addEventListener("keydown", (event) => {
if(event.key === 'Enter') {
el.click();
el.parentNode.classList.add("hidden");
document.querySelector(`.${section} .pickup-date-time .cr-date-picker__input`).focus();
}
if(event.key === 'Tab') {
console.log("is running here in tab")
}
})
},500)
})
}
REBELMOUSE_STDLIB.createElementChangeListener(".home-rental .pickup-container .dropdown-loc .current-loc", function(el){
keyCurrLoc(el, "home-rental", "pickup-container");
})
REBELMOUSE_STDLIB.createElementChangeListener(".top-promo .pickup-container .dropdown-loc .current-loc", function(el){
keyCurrLoc(el, "top-promo", "pickup-container");
})
REBELMOUSE_STDLIB.createElementChangeListener(".sibar .pickup-container .dropdown-loc .current-loc", function(el){
keyCurrLoc(el, "sidebar", "pickup-container");
})
REBELMOUSE_STDLIB.createElementChangeListener(".home-rental .dropoff-container .dropdown-loc .current-loc", function(el){
keyCurrLoc(el, "home-rental", "dropoff-container");
})
REBELMOUSE_STDLIB.createElementChangeListener(".top-promo .dropoff-container .dropdown-loc .current-loc", function(el){
keyCurrLoc(el, "top-promo", "dropoff-container");
})
REBELMOUSE_STDLIB.createElementChangeListener(".sibar .dropoff-container .dropdown-loc .current-loc", function(el){
keyCurrLoc(el, "sidebar", "dropoff-container");
})
let typeTimeSelector, typeSection, widgetSection;
function keycalendarfocus(el, section, calendarSec) {
el.addEventListener("focus", () => {
el.click();
setTimeout(()=> {
//document.querySelector(`.${section} .${calendarSec} .cr-date-range-picker__close-button`).focus();
document.querySelector(`.${section} .dropdown-loc`).classList.add("hidden");
let calendarCells = document.querySelectorAll(`.${section} .${calendarSec} commercial-date-selector .cr-date-range-picker__month-cell`);
calendarCells.forEach((calCell) => {
if (!calCell.classList.contains('cr-date-range-picker__month-cell--disabled') &&
!calCell.classList.contains('cr-date-range-picker__month-cell--empty')) {
calCell.setAttribute("tabindex", "0");
}
calCell.addEventListener("keydown", (event) => {
if (event.key === 'Enter') {
calCell.click();
document.querySelector(`.${section} .${calendarSec} commercial-date-selector .cr-date-range-picker__button`).focus();
setTimeout(()=>{
let timeSelector = document.querySelector(`.${section} .${calendarSec} .quote_pickup_time_select`) || document.querySelector(`.${section} .${calendarSec} .quote_dropoff_time_select`);
typeTimeSelector = timeSelector.className;
typeSection = timeSelector.getAttribute("data-section");
widgetSection = section;
timeSelector.click();
},1000)
}
})
})
},500)
})
}
REBELMOUSE_STDLIB.createElementChangeListener(".home-rental .pickup-date-time commercial-date-selector .cr-date-picker input", function (el) {
keycalendarfocus(el, "home-rental", "pickup-date-time");
})
REBELMOUSE_STDLIB.createElementChangeListener(".home-rental .dropoff-date-time commercial-date-selector .cr-date-picker input", function (el) {
keycalendarfocus(el, "home-rental", "dropoff-date-time");
})
REBELMOUSE_STDLIB.createElementChangeListener(".top-promo .pickup-date-time commercial-date-selector .cr-date-picker input", function (el) {
keycalendarfocus(el, "top-promo", "pickup-date-time");
})
REBELMOUSE_STDLIB.createElementChangeListener(".top-promo .dropoff-date-time commercial-date-selector .cr-date-picker input", function (el) {
keycalendarfocus(el, "top-promo", "dropoff-date-time");
})
REBELMOUSE_STDLIB.createElementChangeListener(".sidebar .pickup-date-time commercial-date-selector .cr-date-picker input", function (el) {
keycalendarfocus(el, "sidebar", "pickup-date-time");
})
REBELMOUSE_STDLIB.createElementChangeListener(".sidebar .dropoff-date-time commercial-date-selector .cr-date-picker input", function (el) {
keycalendarfocus(el, "sidebar", "dropoff-date-time");
})
//close calendar popup by keyboard accessibility
REBELMOUSE_STDLIB.createElementChangeListener("commercial-date-selector .cr-date-range-picker__close-button", function (el) {
el.setAttribute("tabindex", "0");
el.addEventListener("keydown", (event) => {
if (event.key === 'Enter') {
el.click();
}
})
})
function keyTimeVal(el, section, typeTime) {
el.addEventListener("keydown", (event) => {
if(event.key === 'Enter') {
el.click();
let widgetError = document.querySelector(".widget-overlay-error");
if (widgetError.classList.contains("hidden") && typeTime === "quote_widget_pickup-time") {
document.querySelector(`.${section} .dropoff-date-time .cr-date-picker__input`).focus();
} else {
document.querySelector(".widget-overlay-error").focus();
}
}
})
}
REBELMOUSE_STDLIB.createElementChangeListener(".home-rental .date-time-select .quote_widget_pickup-time .time-val", function(el){
keyTimeVal(el, "home-rental", "quote_widget_pickup-time")
})
REBELMOUSE_STDLIB.createElementChangeListener(".home-rental .date-time-select .quote_widget_dropoff-time .time-val", function(el){
keyTimeVal(el, "home-rental", "quote_widget_dropoff-time")
})
REBELMOUSE_STDLIB.createElementChangeListener(".top-promo .date-time-select .quote_widget_pickup-time .time-val", function(el){
keyTimeVal(el, "top-promo", "quote_widget_pickup-time")
})
REBELMOUSE_STDLIB.createElementChangeListener(".top-promo .date-time-select .quote_widget_dropoff-time .time-val", function(el){
keyTimeVal(el, "top-promo", "quote_widget_dropoff-time")
})
REBELMOUSE_STDLIB.createElementChangeListener(".sidebar .date-time-select .quote_widget_pickup-time .time-val", function(el){
keyTimeVal(el, "sidebar", "quote_widget_pickup-time")
})
REBELMOUSE_STDLIB.createElementChangeListener(".sidebar .date-time-select .quote_widget_dropoff-time .time-val", function(el){
keyTimeVal(el, "sidebar", "quote_widget_dropoff-time")
})
REBELMOUSE_STDLIB.createElementChangeListener(".widget-error .error-close", function(el){
el.addEventListener("keydown", (event) => {
if(event.key === 'Enter') {
el.click();
//console.log(document.querySelector(`.${typeSection} .${typeTimeSelector}`));
setTimeout(()=>{document.querySelector(`.${typeSection} .${typeTimeSelector}`).click();},500)
}
})
})
REBELMOUSE_STDLIB.createElementChangeListener(".widget-popup-info .close", function(close){
close.addEventListener("click", () => {
close.parentNode.parentNode.classList.add("hidden");
document.querySelector(".widget-overlay-error").classList.add("hidden");
})
})
let lastInteractionType = null;
// Detect keyboard interactions at the document level
document.addEventListener("keydown", (event) => {
lastInteractionType = 'keyboard';
});
// Detect mouse interactions at the document level
document.addEventListener("mousedown", (event) => {
lastInteractionType = 'mouse';
});
REBELMOUSE_STDLIB.createElementChangeListener(".booking-container .quote_truck_size_select", function(el){
el.setAttribute("tabindex", "0");
// Handle focus event
el.addEventListener("focus", (event) => {
if (lastInteractionType === 'keyboard') {
el.parentNode.querySelector(".truck-options").classList.remove("hidden");
console.log("Keyboard interaction detected, key:", event.key);
} else if (lastInteractionType === 'mouse') {
console.log("Mouse click detected, no need to show options.");
}
lastInteractionType = null;
});
})
REBELMOUSE_STDLIB.createElementChangeListener(".booking-container .truck-sizes-options", function(el){
el.setAttribute("tabindex", "0");
})
REBELMOUSE_STDLIB.createElementChangeListener(".booking-container .compare-option", function(el){
el.setAttribute("tabindex", "0");
el.addEventListener('keydown', function(event) {
if (event.key === 'Tab' && event.shiftKey) {
console.log('Shift + Tab was pressed');
} else if (event.key === 'Tab') {
el.parentNode.parentNode.classList.add("hidden");
}
});
})
// Detect when user has scroll at the end of the what's difference popup to clear linear gradient
let isScrolling;
const scrollContainer = document.querySelector('.popup-scroll-content');
scrollContainer.addEventListener('scroll', function() {
window.clearTimeout(isScrolling);
isScrolling = setTimeout(function() {
const scrollTop = scrollContainer.scrollTop;
const scrollHeight = scrollContainer.scrollHeight;
const offsetHeight = scrollContainer.offsetHeight;
if (scrollTop + offsetHeight >= scrollHeight) {
console.log('User has scrolled to the end of .popup-info-content.');
// scrolling reaches the end
document.querySelector('.popup-info-content').classList.add("remove-gradient");
} else {
console.log('User has not scrolled to the end of .popup-info-content.');
// scrolling stops but hasn't reached the end
document.querySelector('.popup-info-content').classList.remove("remove-gradient")
}
}, 200);
}, false);
});
window.REBELMOUSE_ACTIVE_TASKS_QUEUE.push(function(){
window.REBELMOUSE_STDLIB.loadExternalScript("https://rm.gopenske.com/ptr/assets/maint/maintenance.js", function() {
});
});
window.REBELMOUSE_ACTIVE_TASKS_QUEUE.push(function(){
window.getCookie = function getCookie(name) {
let matches = document.cookie.match(new RegExp(
"(?:^|; )" + name.replace(/([\.$?*|{}\(\)\[\]\\\/\+^])/g, '\\$1') + "=([^;]*)"
));
return matches ? decodeURIComponent(matches[1]) : undefined;
}
var isMaintenance = window.getCookie('isMaintenance');
if('Y' == isMaintenance){
document.querySelectorAll(".booking-container").forEach(function (item) {
item.remove();
document.querySelector("body").classList.add("maintenance-y");
});
}
function closeWidgetError(el) {
el.classList.add("hidden");
if (document.querySelector(".widget-overlay-error")) {
document.querySelector(".widget-overlay-error").classList.add("hidden");
}
}
//Close Widget Errors
REBELMOUSE_STDLIB.createElementChangeListener(".widget-error", function(el){
let close_btn = el.querySelector(".error-close");
let blue_btn = el.querySelector(".blue-full-btn");
if (close_btn) {
close_btn.addEventListener("click", ()=>{
closeWidgetError(el);
})
}
if (blue_btn) {
blue_btn.addEventListener("click", ()=>{
closeWidgetError(el);
})
}
})
});
window.REBELMOUSE_ACTIVE_TASKS_QUEUE.push(function(){
// Function to get URL parameters
function getUrlParameter(name) {
name = name.replace(/[\[]/, '\\[').replace(/[\]]/, '\\]');
var regex = new RegExp('[\\?&]' + name + '=([^]*)');
var results = regex.exec(location.search);
return results === null ? '' : decodeURIComponent(results[1].replace(/\+/g, ' '));
}
// Function to hide content based on the "userway" parameter
function hideContentBasedOnUserway() {
var userwayParam = getUrlParameter('userway');
if (userwayParam === 'off') {
// Hide the content you want to hide
document.getElementById('userway-override').style.display = 'none';
}
}
// Call the function when the page loads
hideContentBasedOnUserway();
});
window.REBELMOUSE_ACTIVE_TASKS_QUEUE.push(function(){
document.querySelector(".widget-overlay-error").addEventListener("click", (event) => {
if(event.target.classList.contains("widget-overlay-error")) {
document.querySelectorAll(".widget-error").forEach((widget) => {
if (!widget.classList.contains("hidden")) {
widget.classList.add("hidden");
}
})
// Add "hidden" class to the clicked element
document.querySelector(".widget-overlay-error").classList.add("hidden");
}
})
});
window.REBELMOUSE_ACTIVE_TASKS_QUEUE.push(function(){
document.addEventListener('contextmenu', function(event) {
if (event.target.matches('img, .display-block.image-element, .section-header-full-img, .header-image, svg, .hero-home-texts, .truck-category-headline, .truck-promo, .truck-promo .promo-card-left-container, .truck-category-header')) {
event.preventDefault();
}
});
});
window.REBELMOUSE_ACTIVE_TASKS_QUEUE.push(function(){
function getUrlParameter(name) {
const urlParams = new URLSearchParams(window.location.search);
return urlParams.get(name);
}
function setCookie(name, value, days, path) {
const expires = new Date(Date.now() + days * 24 * 60 * 60 * 1000).toUTCString();
//document.cookie = `${name}=${value}; expires=${expires}; path=${path}; domain=pensketruckrental.com`;
document.cookie = `${name}=${value}; expires=${expires}; path=${path}`;
}
function deleteCookie(name) {
document.cookie = `${name}=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=/;`;
}
(function() {
const clickref = getUrlParameter('clickref');
const partnercode = getUrlParameter('partnercode');
if(clickref && clickref != null) {
setCookie('it_ptr_click_ref_id', clickref, 7, '/');
if(partnercode && partnercode != null) {
setCookie('it_ptr_partner_code', partnercode, 7, '/');
}
deleteCookie('penskelinkid');
deleteCookie('urlRef');
}
})();
});
window.REBELMOUSE_ACTIVE_TASKS_QUEUE.push(function(){
(function(d){var s = d.createElement("script");s.setAttribute("data-account", "NRnEL6ljSb");s.setAttribute("src", "https://cdn.userway.org/widget.js");(d.body || d.head).appendChild(s);})(document)
});
window.REBELMOUSE_ACTIVE_TASKS_QUEUE.push(function(){
REBELMOUSE_STDLIB.createElementChangeListener(".rebellt-question", function(el){
let headline = el.querySelector('h3[data-role="headline"]');
if (headline) {
headline.addEventListener("click", function(item){
el.classList.toggle("show-description");
})
}
})
REBELMOUSE_STDLIB.createElementChangeListener(".accordion-assembler", function(el){
let headline = el.querySelector('h3[data-role="headline"]');
if (headline) {
headline.addEventListener("click", function(item){
el.classList.toggle("show-description");
})
}
})
});
window.REBELMOUSE_ACTIVE_TASKS_QUEUE.push(function(){
REBELMOUSE_STDLIB.createElementChangeListener(".rebellt-question", function(el){
let headline = el.querySelector('h3[data-role="headline"]');
if (headline) {
headline.addEventListener("click", function(item){
el.classList.toggle("show-description");
})
}
})
REBELMOUSE_STDLIB.createElementChangeListener(".accordion-assembler", function(el){
let headline = el.querySelector('h3[data-role="headline"]');
if (headline) {
headline.addEventListener("click", function(item){
el.classList.toggle("show-description");
})
}
})
// new accordion logic
var accordion = document.getElementsByClassName("accordion-item");
for (var i = 0; i < accordion.length; i++) {
accordion[i].addEventListener("click", function() {
this.classList.toggle("accordion-item-active");
var accordionContent = this.nextElementSibling;
if (accordionContent.style.display === "flex") {
accordionContent.style.display = "none";
} else {
accordionContent.style.display = "flex";
}
});
}
});
window.REBELMOUSE_ACTIVE_TASKS_QUEUE.push(function(){
const urlPath = window.location.pathname.split("/").filter(segment => segment !== "");
let lastSegment = urlPath[urlPath.length-1];
let sectionID = {
"cargo-vans" : 2158440270,
"light-duty-trucks" : 2158440268,
"medium-duty-trucks" : 2158440269,
"heavy-duty-trucks" : 2158440271,
"refrigerated-trucks" : 2158440272,
"flatbed-trucks": 2158440273,
"semi-trailers" : 2158440274
};
const graphqlEndpoint = "/core/graphql";
let postTrucks = [];
let currentIndex = 0;
let amountOfTrucks = 0;
const truckSpecsContainer = document.querySelector('.truck-category-specs');
const tracksSpecsContainers = document.querySelectorAll('.tracks-specs');
const promoCustomerDiscount = document.querySelector('.new-customer-discount');
const promoTruckContainers = document.querySelectorAll('.post-promo .truck-promo');
let sitePostData = [];
promoTruckContainers.forEach((promo) => {
// Clone the "truck-specs-container" element
const clonedPromoCustDisc = promoCustomerDiscount.cloneNode(true);
// Insert the cloned element into the "tracks-specs" container
promo.appendChild(clonedPromoCustDisc);
});
function makeRequest(data, callback, errorCallback) {
fetch(graphqlEndpoint, {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify(data),
})
.then(response => {
if (!response.ok) {
throw new Error(`HTTP error! Status: ${response.status}`);
}
return response.json();
})
.then(responseData => {
callback(responseData);
responseData.data.postsV2.forEach((item, index) => {
let truckSpecsData = JSON.parse(item.siteSpecificData)
if (truckSpecsData.spec_table_row_1) {
sitePostData.push(item)
}
})
truckSpecs(sitePostData);
})
.catch(error => {
console.error("GraphQL request failed:", error);
errorCallback(error);
});
}
function getGQL(id) {
return { query: `{postsV2(filters:{regularSections:{any: [{id: ${id}}]}, statuses:{any: [PUBLISHED]}}, slice:{offset: 0, limit: 10, order: MANUAL, allowDuplicates: true}){ id image{crops(sizes: ["original"]){href}} pages{web{href}} title subtitle publishedAt primaryTags{slug title} primarySections{slug} siteSpecificData}}`, variables: null, operationName: null };
}
function handlePostsV2From() {
return function onGQLResponse(response) {
//console.log(response);
};
}
function fetchAllPostsV2(id) {
var query = getGQL(id);
makeRequest(query, handlePostsV2From(), function onError(error) {
// Handle errors gracefully here
console.error('GraphQL request failed:', error);
});
}
function fillSpecs(specDiv, item, roarData) {
console.log(item)
specDiv.querySelector(".spec-title").innerHTML = item.title;
specDiv.querySelector(".spec-title").href = item.pages.web.href;
specDiv.querySelector(".spec_details a").href = item.pages.web.href;
specDiv.querySelector(".full-specs").href = item.pages.web.href;
if (Object.keys(roarData).length > 0) {
if(roarData.spec_truck_image) {
specDiv.querySelector(".spec-img").setAttribute('data-img-name', `${item.title}`)
specDiv.querySelector(".spec-img").innerHTML = `${roarData.spec_truck_image.media_html}`;
}
specDiv.querySelector(".spec_table_row_1 .truck-content").innerHTML = `${roarData.spec_table_row_1}`;
specDiv.querySelector(".spec_table_row_2 .truck-content").innerHTML = `${roarData.spec_table_row_2}`;
specDiv.querySelector(".spec_table_row_3 .truck-content").innerHTML = `${roarData.spec_table_row_3}`;
specDiv.querySelector(".spec_table_row_4 .truck-content").innerHTML = `${roarData.spec_table_row_4}`;
specDiv.querySelector(".spec_table_row_5 .truck-content").innerHTML = `${roarData.spec_table_row_5}`;
}
}
function truckSpecs(truck) {
let specDivs = document.querySelectorAll(".slider-container .specs-truck");
let specDivTablet = document.querySelectorAll(".spec-truck-768 .specs-truck");
postTrucks = truck;
amountOfTrucks = truck.length;
// Filled specs-truck in slider-container
truck.forEach((item, index) => {
let specDiv = specDivs[index];
let roarData = JSON.parse(item.siteSpecificData);
fillSpecs(specDiv, item, roarData);
})
// Filled Initial specs-truck in spec-truck-768
specDivTablet.forEach((item, index) => {
let div = item;
let roarData = JSON.parse(truck[index].siteSpecificData);
fillSpecs(div, truck[index], roarData);
})
// append track-specs inside post body
tracksSpecsContainers.forEach((tracksSpecs) => {
const clonedTruckSpecsContainer = truckSpecsContainer.cloneNode(true);
tracksSpecs.appendChild(clonedTruckSpecsContainer);
tracksSpecs.classList.add(`truck-columns-${truck.length}`);
});
let prevButton = document.querySelector('.truck-category-post-intro .prevButton');
let nextButton = document.querySelector('.truck-category-post-intro .nextButton');
showSlide(currentIndex, amountOfTrucks);
buttonListeners(prevButton, nextButton);
addCarouselDots(truck);
changeTruck(truck);
setDivsEqualHeight();
}
// Check if the last path segment exists as a key in the mapping object
if (sectionID.hasOwnProperty(lastSegment)) {
const value = sectionID[lastSegment];
// Initial call
fetchAllPostsV2(value);
} else {
console.log("No value found for the URL path segment:", lastSegment);
}
function updateTruckInfo(data, value, dropdown, item, index) {
value.innerHTML = `${item.textContent}`;
dropdown.classList.add("hidden");
value.classList.remove("rotate");
let contraryIndex = index == 0 ? 1 : 0;
let specDivTablet = document.querySelectorAll(".truck-category-post-accordion .spec-truck-768 .specs-truck");
let specDiv = specDivTablet[index];
let roarData = JSON.parse(data[item.getAttribute("data-index")].siteSpecificData);
let tableSelectors = document.querySelectorAll(".truck-category-post-accordion .slider-selector .truck-selector");
dropdown.querySelectorAll(".trucks-selector-options span").forEach((span) => {
span.classList.remove("selected")
})
item.classList.add("selected");
// hide option in other selector
tableSelectors[contraryIndex].querySelectorAll(".trucks-selector-options span").forEach((span) => {
span.classList.remove("hidden")
})
document.querySelector(`.truck-category-post-accordion .truck-selector.selector-${contraryIndex} .trucks-selector-options span[data-index="${item.getAttribute("data-index")}"]`).classList.add("hidden");
fillSpecs(specDiv, data[item.getAttribute("data-index")], roarData);
}
function changeTruck(data) {
let selectors = document.querySelectorAll(".truck-category-post-accordion .truck-selector");
selectors.forEach((item, index) => {
let value = item.querySelector(".truck-selector-value");
let dropdown = item.querySelector(".trucks-selector-options");
if (data[index]) value.innerHTML = `${data[index].title}`;
// insert truck options
data.forEach((itemData, indexdata) => {
let span = document.createElement("span");
span.setAttribute("data-index", indexdata);
if (itemData && data[index]) {
span.innerHTML = `${itemData.title}`;
if(itemData.title == data[index].title) {
span.classList.add("selected");
}
span.addEventListener("click", () => {
updateTruckInfo(data, value, dropdown, span, index);
});
dropdown.appendChild(span);
}
});
value.addEventListener("click", () => {
dropdown.classList.toggle("hidden");
value.classList.toggle('rotate');
})
});
setTimeout(() => {
let spanSelected = document.querySelectorAll(".truck-category-post-accordion .trucks-selector-options span.selected");
spanSelected.forEach((item,index) => {
let i = index == 0 ? 1 : 0;
let spanIndex = item.getAttribute("data-index");
document.querySelector(`.truck-category-post-accordion .truck-selector.selector-${i} .trucks-selector-options span[data-index="${spanIndex}"]`).classList.add("hidden");
})
},1000)
}
function addCarouselDots(filteredData) {
let dotsContainer = document.querySelector(".truck-category-post-intro .carousel-dots");
filteredData.forEach((item, index) => {
let dot = document.createElement("div");
dot.classList.add("dot");
dot.setAttribute("current-index", index);
if(index == currentIndex) {
dot.classList.add("dot-selected");
}
dotsContainer.appendChild(dot);
dot.addEventListener("click", () => {
let dots = dotsContainer.querySelectorAll(".dot");
currentSlide = index;
showSlide(currentSlide, amountOfTrucks);
dots.forEach((item) => {
item.classList.remove("dot-selected");
})
dot.classList.add("dot-selected");
let prevButton = document.querySelector('.truck-category-post-intro .prevButton');
let nextButton = document.querySelector('.truck-category-post-intro .nextButton');
if (currentIndex == 0) {
handlePrevArrow(prevButton, currentIndex, amountOfTrucks, nextButton);
} else if ((currentIndex + 1) == amountOfTrucks) {
prevButton.querySelector(".arrow-left.gray-110").classList.add("hidden");
prevButton.querySelector(".arrow-left.reflex-blue-100").classList.remove("hidden");
nextButton.querySelector(".arrow-right.gray-110").classList.remove("hidden");
nextButton.querySelector(".arrow-right.reflex-blue-100").classList.add("hidden");
} else {
prevButton.querySelector(".arrow-left.gray-110").classList.add("hidden");
prevButton.querySelector(".arrow-left.reflex-blue-100").classList.remove("hidden");
nextButton.querySelector(".arrow-right.gray-110").classList.add("hidden");
nextButton.querySelector(".arrow-right.reflex-blue-100").classList.remove("hidden");
}
});
})
}
function handlePrevArrow(prevButton, currentIndex, amountOfTrucks, nextButton) {
if (currentIndex == 0 ) {
prevButton.querySelector(".arrow-left.gray-110").classList.remove("hidden");
prevButton.querySelector(".arrow-left.reflex-blue-100").classList.add("hidden");
nextButton.querySelector(".arrow-right.gray-110").classList.add("hidden");
nextButton.querySelector(".arrow-right.reflex-blue-100").classList.remove("hidden");
} else if (currentIndex > 0 && currentIndex < (amountOfTrucks - 1)) {
prevButton.querySelector(".arrow-left.gray-110").classList.add("hidden");
prevButton.querySelector(".arrow-left.reflex-blue-100").classList.remove("hidden");
nextButton.querySelector(".arrow-right.gray-110").classList.add("hidden");
nextButton.querySelector(".arrow-right.reflex-blue-100").classList.remove("hidden");
}
}
function handleNextArrow(prevButton, currentIndex, amountOfTrucks, nextButton) {
if(amountOfTrucks == 2) {
if (currentIndex == 1) {
prevButton.querySelector(".arrow-left.gray-110").classList.add("hidden");
prevButton.querySelector(".arrow-left.reflex-blue-100").classList.remove("hidden");
nextButton.querySelector(".arrow-right.gray-110").classList.remove("hidden");
nextButton.querySelector(".arrow-right.reflex-blue-100").classList.add("hidden");
}
} else {
if (currentIndex > 0 && currentIndex < (amountOfTrucks - 1)) {
prevButton.querySelector(".arrow-left.gray-110").classList.add("hidden");
prevButton.querySelector(".arrow-left.reflex-blue-100").classList.remove("hidden");
} else if (currentIndex == (amountOfTrucks - 1)) {
nextButton.querySelector(".arrow-right.gray-110").classList.remove("hidden");
nextButton.querySelector(".arrow-right.reflex-blue-100").classList.add("hidden");
}
}
}
// Function to show a specific slide and hide others
function showSlide(index, amountOfTrucks) {
let specsTrucks = document.querySelectorAll('.truck-category-post-intro .slider-container .specs-truck');
if (index < 0 || index >= amountOfTrucks) return;
currentIndex = index;
// Hide all specs-truck elements
specsTrucks.forEach((truck) => {
truck.classList.add('hidden');
});
// Show the active slide
specsTrucks[currentIndex].classList.remove('hidden');
}
function buttonListeners(prevButton, nextButton) {
// Event listeners for navigation buttons
prevButton.addEventListener('click', () => {
showSlide(currentIndex - 1, amountOfTrucks);
updateDotSelected(currentIndex);
handlePrevArrow(prevButton, currentIndex, amountOfTrucks, nextButton)
});
nextButton.addEventListener('click', () => {
showSlide(currentIndex + 1, amountOfTrucks);
updateDotSelected(currentIndex);
handleNextArrow(prevButton, currentIndex, amountOfTrucks, nextButton)
});
}
function updateDotSelected(index) {
let dotsContainer = document.querySelector(".truck-category-post-intro .carousel-dots");
let dots = dotsContainer.querySelectorAll(".dot");
dots.forEach((item) => {
if (item.getAttribute("current-index") == index) {
item.classList.add("dot-selected");
} else {
item.classList.remove("dot-selected");
}
})
}
function setHeight(selector, padding) {
const divs = document.querySelectorAll(selector);
let width = screen.width;
// Reset the height to auto to calculate the new height based on content
divs.forEach(div => {
div.style.height = 'auto';
});
// Find the maximum height
let maxHeight = 0;
divs.forEach(div => {
const divHeight = div.clientHeight;
maxHeight = Math.max(maxHeight, divHeight);
});
// Set all divs to the maximum height
if (padding) {
if (width >= 1024) {
maxHeight = maxHeight - 20;
} else {
maxHeight = maxHeight - 20;
}
}
divs.forEach(div => {
div.style.height = `${maxHeight}px`;
});
}
// Function to set divs to equal height
function setDivsEqualHeight() {
setHeight('.truck-category-post-accordion .spec-title-wrap', false);
setHeight('.truck-category-post-accordion .spec_table_row_1', true);
setHeight('.truck-category-post-accordion .spec_table_row_2', true);
setHeight('.truck-category-post-accordion .spec_table_row_3', true);
setHeight('.truck-category-post-accordion .spec_table_row_4', true);
setHeight('.truck-category-post-accordion .spec_table_row_5', true);
}
// Run the function on page load and window resize
window.addEventListener('resize', setDivsEqualHeight);
// Add alt value to img
REBELMOUSE_STDLIB.createElementChangeListener(".spec-img.spec_truck_image", function(el){
let altVal = el.getAttribute("data-img-name");
let img = el.querySelector("img");
if(img) {
img.alt = altVal
}
})
});
window.REBELMOUSE_ACTIVE_TASKS_QUEUE.push(function(){
window.onclick = function(e){
let element = document.querySelector('.language-selector');
if (element) {
let elemChild = element.querySelector('span');
if(e.target != element && e.target != elemChild) {
element.classList.remove('show-dropdown');
}
}
}
REBELMOUSE_STDLIB.createElementChangeListener(".tabs.dropdown", function(el){
el.addEventListener("click", function(){
el.classList.toggle('show-dropdown')
})
})
});