PageSourceSearch

https://www.visitdeni.com/layouts/impartmedia/gadget-styling-simple-item-details/layout.js

js visitdeni.com collected 2026-10-04 22:58:02 UTC 9,071 bytes, 201 lines download raw bytes

1
2// Function to assist with very simple item details gadget implementation
3if (typeof(HandlebarsBE) !== 'undefined') {
4	
5	
6	// handlebars:  {{{roomConfig _data.roomID}}}
7	BE.handlebars.renderRoomConfig = function(roomid) {
8		setTimeout(function() {
9			if (BE.handlebars.itemdetails.data.roomDetails && BE.handlebars.itemdetails.data.roomDetails[roomid]) {
10				var roomconfig = [];
11				if (BE.handlebars.itemdetails.data.roomDetails[roomid].RoomConfig) {
12					roomconfig.push(BE.handlebars.itemdetails.data.roomDetails[roomid].RoomConfig);
13				}
14				if (BE.handlebars.itemdetails.data.roomDetails[roomid].NoPersons) {
15					roomconfig.push(BE.handlebars.itemdetails.data.roomDetails[roomid].NoPersons + ' guests');
16				}
17				if (roomconfig.length > 0) {
18					jQuery('#room-config-'+roomid).html(roomconfig.join('  |  '));
19				} else {
20					jQuery('#room-config-'+roomid).parent().hide();
21				}
22			}
23		}, 200);
24		return '<span id="room-config-'+roomid+'"></span>';
25	};
26	HandlebarsBE.registerHelper('roomConfig', BE.handlebars.renderRoomConfig);
27	
28	
29	// handlebars:  {{{roomDescription _data.roomID}}}
30	BE.handlebars.renderRoomDescription = function(roomid) {
31		setTimeout(function() {
32			if (BE.handlebars.itemdetails.data.roomDetails && BE.handlebars.itemdetails.data.roomDetails[roomid]) {
33				if (BE.handlebars.itemdetails.data.roomDetails[roomid].Description) {
34					var desc = BE.handlebars.itemdetails.data.roomDetails[roomid].Description;
35					desc = BE.handlebars.shortSummaryString_NumberOfLines(desc, 200, 2, 80);
36					jQuery('#room-description-'+roomid).html(desc);
37				} else {
38					jQuery('#room-description-'+roomid).parent().hide();
39				}
40			}
41		}, 200);
42		return '<span id="room-description-'+roomid+'"></span>';
43	};
44	HandlebarsBE.registerHelper('roomDescription', BE.handlebars.renderRoomDescription);
45	
46	
47	// new way of running JS each time the item details gadget renders / re-renders
48	// handlebars:  {{{onItemDetailsGadgetRender}}}
49	BE.handlebars.onItemDetailsGadgetRender = function() {
50		
51		setTimeout(function() {
52			
53			// thumbnail column
54			if (jQuery('.details-gadget td.thumb div').length == 0) {
55				jQuery('.details-gadget thead td.title').attr('colspan', 1);
56				jQuery('.details-gadget tbody td.thumb').hide();
57			}
58			
59			// if many nights
60			var currentCookieObject = $w.json.parse($w.cookie(BE.util.cookieName()));
61			var numNights = 0;
62			if (currentCookieObject && currentCookieObject.period) { numNights = currentCookieObject.period; }
63			if (parseInt(numNights) > 7) {
64				jQuery('#itemGadget').addClass('many-nights').removeClass('not-many-nights');
65			} else {
66				jQuery('#itemGadget').removeClass('many-nights').addClass('not-many-nights');
67			}
68			
69		}, 50);
70	};
71	HandlebarsBE.registerHelper('onItemDetailsGadgetRender', BE.handlebars.onItemDetailsGadgetRender);
72	
73	
74	// this function will allow you to use "collapsed tours" on item details gadget with handlebars, in a new way
75	// handlebars:  {{{groupToursIntoCollapsedRows}}}
76	// for implementation example see wonderreef
77	BE.handlebars.groupToursIntoCollapsedRows = function() {
78		
79		// init
80		var soldOutRows = {};
81		var groupedRows = {};
82		var groupsEnabled = false;
83		
84		// 20231020 : bugfix after recent changes in gadgets
85		jQuery.each(BE.handlebars.itemdetails.data.itemDetails.items, function(key, item) {
86			item.roomID_original = item.roomID;
87			item.roomID = parseInt(item.roomID.split(':')[1]);
88			item._data.roomID_original = item._data.roomID;
89			item._data.roomID = (item._data.roomID ? parseInt(item._data.roomID.split(':')[1]) : item._data.roomID);
90			item._all.NameWithoutTime = item._all.Name;
91		});
92		
93		// activities 2.0 : grouping for dynamic tours works differently: we still want to group items together but we don't want to show the dropdowns, just one normal button
94		if (BE.util.isDefined(BE.handlebars.itemdetails.options) && BE.util.isDefined(BE.handlebars.itemdetails.options.operatorConfig) && BE.util.isDefined(BE.handlebars.itemdetails.options.operatorConfig.isDynamicTours) && (BE.handlebars.itemdetails.options.operatorConfig.isDynamicTours == true)) {
95			jQuery.each(BE.handlebars.itemdetails.data.itemDetails.items, function(key, item) {
96				var groupUniqueKey = item._all.TourMasterTourName;
97				if (groupUniqueKey) {
98					if (item.td_total["a.im-gadgetbutton"] && item.td_total["a.im-gadgetbutton"]["span.book im-gadgetbutton-label"] || item.td_total["a.sold-out im-gadgetbutton"] && item.td_total["a.sold-out im-gadgetbutton"]["span.book im-gadgetbutton-label"]) {
99						if (typeof(groupedRows[groupUniqueKey]) === 'undefined') {
100							groupedRows[groupUniqueKey] = item;
101							groupedRows[groupUniqueKey]._all.NameWithoutTime = item._all.TourMasterTourName;
102						}
103						groupsEnabled = true;
104					}
105					if (item.td_total["a.im-gadgetbutton"]["span.number im-gadgetbutton-amount"] == 'Free') {
106						item.td_total["a.im-gadgetbutton"]["span.number im-gadgetbutton-amount"] = '';
107					}
108				}
109			});
110			jQuery('head').append('<style> .im-gadgetbutton + .item-amount-view-more { display:none; } </style>');
111			if (groupsEnabled) {
112				BE.handlebars.itemdetails.data.itemDetails.items = groupedRows;
113			}
114			return '';
115		}
116		
117		// grouping
118		jQuery.each(BE.handlebars.itemdetails.data.itemDetails.items, function(key, item) {
119			var groupUniqueKey = item._all.TourMasterTourName;
120			if (groupUniqueKey) {
121				if (item && item.td_dates && item.td_dates[0] && item.td_dates[0].td && item.td_dates[0].td.span && (item.td_dates[0].td.span == 'N/A')) {
122					item.td_dates[0].td.span = '';
123				}
124				if (item.td_total["a.im-gadgetbutton"] && item.td_total["a.im-gadgetbutton"]["span.book im-gadgetbutton-label"]) {
125					item.isSoldOut = false;
126					item.label = ''+item.name;
127					if (item._all.AllDay == false) {
128						item.td_total["a.im-gadgetbutton"]["span.book im-gadgetbutton-label"] = (BE.util.isDefined(window.isItemGadgetPolyfillMode) ? BE.gadget.region.text.bookNow.replace(' now', ' Now') : gadgetsFormatAMPM(item._all.TocStartTime));
129						item.label = gadgetsFormatAMPM(item._all.TocStartTime);
130					} else {
131						item.label = 'All Day';
132					}
133					if (typeof(groupedRows[groupUniqueKey]) === 'undefined') {
134						groupedRows[groupUniqueKey] = item;
135						groupedRows[groupUniqueKey]._all.NameWithoutTime = item._all.TourMasterTourName;
136						groupedRows[groupUniqueKey].groupedItems = [];
137					}
138					groupedRows[groupUniqueKey].groupedItems.push(item);
139					groupsEnabled = true;
140				} else if (item.td_total["a.sold-out im-gadgetbutton"] && item.td_total["a.sold-out im-gadgetbutton"]["span.book im-gadgetbutton-label"]) {
141					item.isSoldOut = true;
142					if (typeof(soldOutRows[groupUniqueKey]) === 'undefined') {
143						soldOutRows[groupUniqueKey] = item;
144						soldOutRows[groupUniqueKey]._all.NameWithoutTime = item._all.TourMasterTourName;
145						soldOutRows[groupUniqueKey].groupedItems = [item];
146						soldOutRows[groupUniqueKey].groupedItems[0].next_available = undefined;
147					}
148					if (item.td_dates && item.td_dates[0] && item.td_dates[0].td && item.td_dates[0].td.span) {
149						var this_next_available = undefined;
150						if (BE.util.exists(item._all.Availability) && BE.util.exists(item._all.Availability.NextAvailable)) {
151							this_next_available = item._all.Availability.NextAvailable;
152						}
153						if ((typeof(soldOutRows[groupUniqueKey].groupedItems[0].next_available) === "undefined") || (this_next_available < soldOutRows[groupUniqueKey].groupedItems[0].next_available)) {
154							soldOutRows[groupUniqueKey].groupedItems[0].next_available = this_next_available;
155							soldOutRows[groupUniqueKey].groupedItems[0].td_dates = item.td_dates;
156						}
157					}
158					groupsEnabled = true;
159				}
160			}
161		});
162		
163		// sold out items are a bit special, we don't want individual sold out items within groups but we do want to indicate any sold out groups (#17768)
164		jQuery.each(soldOutRows, function(groupUniqueKey, soldOutRow) {
165			if (typeof(groupedRows[groupUniqueKey]) === 'undefined') {
166				groupedRows[groupUniqueKey] = soldOutRows[groupUniqueKey];
167			}
168		});
169		
170		// override the default item details gadget rows with the grouped rows
171		if (groupsEnabled) {
172			BE.handlebars.itemdetails.data.itemDetails.items = groupedRows;
173		}
174		
175	};
176	HandlebarsBE.registerHelper('groupToursIntoCollapsedRows', BE.handlebars.groupToursIntoCollapsedRows);
177	
178	
179	window.gadgetsFormatAMPM = function(str) {
180	    time = str.split(':');
181	    if (time.length !== 2) return str;
182	    var hours = parseInt(time[0]);
183	    var minutes = parseInt(time[1]);
184	    var ampm = hours >= 12 ? 'pm' : 'am';
185	    hours = hours % 12;
186	    hours = hours ? hours : 12; // the hour '0' should be '12'
187	    minutes = minutes < 10 ? '0' + minutes : minutes;
188	    var strTime = hours + ':' + minutes + ampm;
189	    return strTime;
190	};
191	
192	
193	window.gadgetPolyfillCollapseToursChange = function(obj) {
194		var roomid = parseInt(jQuery(obj).attr('data-roomid'));
195		var tourid = parseInt(jQuery(obj).val());
196		var room = jQuery('#product-'+roomid);
197		room.find('.collapsed-tour-option').hide();
198		room.find('#collapsed-tour-'+tourid).show();
199	};
200	
201}

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.