PageSourceSearch

https://carlsbergmalaysia.com.my/assets/scripts/modules/shared.js

js carlsbergmalaysia.com.my collected 2026-10-03 21:39:07 UTC 4,381 bytes, 179 lines download raw bytes

1$(document).ready(function() {
2
3	var carlsbergGroupShared = (function() {
4 
5		// 'Private' variables
6		var oldIE = $('html').hasClass('lt-ie9') ? true : false; // Check whether we're dealing with < IE9
7
8		// 'Private'
9		function init() {
10			svgThemeFixes();
11			initModal();
12			browserFixes();
13			placeholderFallback();			
14			imageFocalPoints();
15			var resized;
16			$(window).on('resize orientationChanged load', function(){
17				clearTimeout(resized);
18				resized = setTimeout(resizeCallback, 200);
19			});
20		}
21
22		function resizeCallback(){
23			productMetaLayout();
24		}
25
26		function initModal(){
27			if(!oldIE){
28				$('.js-modal').featherlight({
29					targetAttr: 'href'
30				});
31				$('.gallery').featherlightGallery({
32					targetAttr: 'href',
33					previousIcon: '&#60;',     /* Code that is used as previous icon */
34					nextIcon: '&#62;',         /* Code that is used as next icon */
35				});
36			}else{
37				$('.gallery, .js-modal').attr('target','_blank');
38			}
39		}
40
41		function browserFixes() {
42
43			/* iOS */
44			function iOS() {
45				var iDevices = [
46					'iPad Simulator',
47					'iPhone Simulator',
48					'iPod Simulator',
49					'iPad',
50					'iPhone',
51					'iPod'
52				];
53				if (!!navigator.platform) {
54					while (iDevices.length) {
55						if (navigator.platform === iDevices.pop()){ return true; }
56					}
57				}
58				return false;
59			}
60
61			if(iOS()){
62				$('body').addClass('ios');
63			}
64
65
66			/* iOS7 */
67			if(navigator.userAgent.match(/(iPad|iPhone|iPod touch);.*CPU.*OS 7_\d/i)){
68				$('body').addClass('ios7');
69			};
70		}
71
72		function placeholderFallback(){
73			if (!('placeholder' in document.createElement('input'))) {
74				$('input[placeholder], textarea[placeholder]').each(function() {
75					var val = $(this).attr('placeholder');
76					if (this.value == '') {
77						this.value = val;
78					}
79					$(this).focus(function() {
80						if (this.value == val) {
81							this.value = '';
82						}
83					}).blur(function(){
84						if ($.trim(this.value) == '') {
85							this.value = val;
86						}
87					});
88				});
89
90				// Clear default placeholder values on form submit
91				$('form').submit(function() {
92					$(this).find('input[placeholder], textarea[placeholder]').each(function() {
93						if ( this.value == $(this).attr("placeholder") ) {
94							this.value = '';
95						}
96					});
97				});
98			}
99		}
100
101		function productMetaLayout(){
102			
103			$('.product-meta').each(function(){
104				var productMeta = $(this);
105				var stack = false;
106
107				productMeta.removeClass('product-meta--stacked');
108
109				$('.product-meta__title', productMeta).each(function(){
110					var _this = $(this);
111					productMeta = _this.closest('.product-meta');
112					if (_this[0].scrollWidth > _this[0].offsetWidth) {
113						stack = true;
114					}				
115				});
116
117				if(stack){
118					productMeta.addClass('product-meta--stacked');
119					$.fn.matchHeight._update();
120				}else{
121					productMeta.removeClass('product-meta--stacked');
122				}
123
124			})
125		}
126
127		function svgThemeFixes(){
128			$('.hero-title__icon[src$=".svg"], .large-download__icon[src$=".svg"]').each(function(){
129				var img = $(this);
130				var imgID = img.attr('id');
131				var imgClass = img.attr('class');
132				var imgURL = img.attr('src');
133
134				$.get(imgURL, function(data) {
135					// Get the SVG tag, ignore the rest
136					var svg = $(data).find('svg');
137
138					// Add replaced image's ID to the new SVG
139					if(typeof imgID !== 'undefined') {
140						svg = svg.attr('id', imgID);
141					}
142					// Add replaced image's classes to the new SVG
143					if(typeof imgClass !== 'undefined') {
144						svg = svg.attr('class', imgClass+' replaced-svg');
145					}
146
147					// Remove any invalid XML tags as per http://validator.w3.org
148					svg = svg.removeAttr('xmlns:a');
149
150					// Replace image with new SVG
151					img.replaceWith(svg);
152
153				}, 'xml');
154
155			});
156		}
157
158		function imageFocalPoints(){
159			$('.js-focus').each(function(){
160				var _this = $(this);
161				if(typeof _this.data('focusx') !== 'undefined' && typeof _this.data('focusy') !== 'undefined'){
162					var focusX = (_this.data('focusx') || 0.5) * 100;
163					var focusY = (_this.data('focusy') || 0.5) * 100;
164					_this.css('object-position', focusX + '% ' + focusY + '%');
165				}
166			});
167		}
168	
169		// 'Public'
170		return {
171			init: init
172		};
173
174	})();
175 
176	carlsbergGroupShared.init();
177});
178
179

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.