1/** 2 * Box Slider Initializer 3 * Uses data attributes on .owl-carousel to configure Owl Carousel. 4 */ 5$(document).ready(function () { 6 $('.owl-carousel[data-box-slider="true"]').each(function () { 7 var $el = $(this); 8 var data = $el.data(); 9 var parseValue = function (val) { 10 if (val === 'true' || val === true) return true; 11 if (val === 'false' || val === false) return false; 12 if (!isNaN(val) && val !== '' && typeof val !== 'boolean') return parseFloat(val); 13 if (typeof val === 'string') { 14 var trimmed = val.trim(); 15 if (trimmed.startsWith('{') || trimmed.startsWith('[')) { 16 try { return JSON.parse(trimmed); } catch (e) { return {}; } 17 } 18 } 19 return val; 20 }; 21 22 var config = { 23 loop: parseValue(data.owlLoop), 24 items: parseValue(data.owlItems) || 1, 25 margin: parseValue(data.owlMargin) || 30, 26 center: parseValue(data.owlCenter), 27 nav: parseValue(data.owlNav), 28 dots: parseValue(data.owlDots), 29 autoplay: parseValue(data.owlAutoplay), 30 autoplaySpeed: parseValue(data.owlAutoplaySpeed) || 1000, 31 autoplayHoverPause: true, 32 navText: ['<span>â¹</span>', '<span>âº</span>'], 33 responsive: { 34 0: { 35 items: parseValue(data.owlItemsMobile) || 1, 36 nav: parseValue(data.owlNavMobile), 37 margin: parseValue(data.owlMarginMobile) || 30 38 }, 39 768: { 40 items: parseValue(data.owlItemsTablet) || 2, 41 nav: parseValue(data.owlNavTablet), 42 margin: parseValue(data.owlMarginTablet) || 30 43 }, 44 992: { 45 items: parseValue(data.owlItemsTabletBig) || 2, 46 nav: parseValue(data.owlNavTabletBig), 47 margin: parseValue(data.owlMarginTabletBig) || 30 48 }, 49 1200: { 50 items: parseValue(data.owlItemsDesktop) || 3, 51 nav: parseValue(data.owlNavDesktop), 52 margin: parseValue(data.owlMarginDesktop) || 30 53 } 54 } 55 }; 56 57 // 1. Handle JSON data-owl-responsive (Object or Array of Objects) 58 if (data.owlResponsive) { 59 var respData = parseValue(data.owlResponsive); 60 if (Array.isArray(respData)) { 61 respData.forEach(function (item) { 62 if (item.breakpoint !== undefined) { 63 config.responsive[item.breakpoint] = item.settings || {}; 64 } 65 }); 66 } else if (respData && typeof respData === 'object') { 67 $.extend(config.responsive, respData); 68 } 69 } 70 71 // 2. Handle individual attributes: data-owl-resp-0-items="1.2" 72 $.each(this.attributes, function () { 73 if (this.name.indexOf('data-owl-resp-') === 0) { 74 var parts = this.name.split('-'); 75 if (parts.length >= 5) { 76 var breakpoint = parseInt(parts[3]); 77 var option = parts.slice(4).join('-'); 78 // camelCase: auto-width -> autoWidth 79 option = option.replace(/-([a-z])/g, function (g) { return g[1].toUpperCase(); }); 80 81 var value = parseValue(this.value); 82 if (!config.responsive[breakpoint]) { 83 config.responsive[breakpoint] = {}; 84 } 85 config.responsive[breakpoint][option] = value; 86 } 87 } 88 }); 89 // Initialize only if not already initialized 90 if (!$el.hasClass('owl-loaded')) { 91 $el.owlCarousel(config); 92 } 93 }); 94});
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.