PageSourceSearch

https://discotech.me/static/widget.js

js discotech.me collected 2026-09-24 09:17:16 UTC 6,851 bytes, 206 lines download raw bytes

1((function() {
2
3    // localize discotech object
4    let discotech = {
5	"stylesheet": "/static/style.css",
6	"base_url": "https://api.discotech.me/v2/"
7    };
8
9    discotech.formatDate = function(str){
10	let date = new Date(str);
11	return date.getMonth() + "/" + date.getDate() + "/" + date.getFullYear();
12    };
13
14    // Localize jQuery variable
15    let jQuery;
16
17    /******** Load jQuery if not present *********/
18    if (window.jQuery === undefined || window.jQuery.fn.jquery !== "3.1.1") {
19	let jquery_tag = document.createElement("script");
20	jquery_tag.setAttribute("type","text/javascript");
21	jquery_tag.setAttribute("src",
22				"https://code.jquery.com/jquery-3.1.1.min.js");
23	jquery_tag.setAttribute("integrity",
24				"sha256-hVVnYaiADRTO2PzUGmuLJr8BLUSjGIZsDYGmIJLv2b8=");
25	jquery_tag.setAttribute("crossorigin",
26				"anonymous");
27
28	if (jquery_tag.readyState) {
29	    jquery_tag.onreadystatechange = function () { // For old versions of IE
30		if (this.readyState === "complete" || this.readyState === "loaded") {
31		    scriptLoadHandler();
32		}
33	    };
34	} else {
35	    jquery_tag.onload = scriptLoadHandler;
36	}
37
38	// Try to find the head, otherwise default to the documentElement
39	(document.getElementsByTagName("head")[0] ||
40	 document.documentElement).appendChild(jquery_tag);
41    } else {
42	// The jQuery version on the window is the one we want to use
43	jQuery = window.jQuery;
44	load_handlebars();
45    }
46
47    /******** Called once jQuery has loaded ******/
48    function scriptLoadHandler() {
49	// Restore $ and window.jQuery to their previous values and store the
50	// new jQuery in our local jQuery variable
51	jQuery = window.jQuery.noConflict(true);
52	// Call our main function
53	load_handlebars();
54    }
55
56    let Handlebars;
57
58    function load_handlebars() {
59	if(window.Handlebars === undefined) {
60	    let handlebars_tag = document.createElement("script");
61	    handlebars_tag.setAttribute("type", "text/javascript");
62	    handlebars_tag.setAttribute("src",
63					"https://cdn.jsdelivr.net/npm/handlebars@latest/dist/handlebars.js");
64	    handlebars_tag.setAttribute("crossorigin",
65					"anonymous");
66
67	    if (handlebars_tag.readyState) {
68		handlebars_tag.onreadystatechange = function () { // For old versions of IE
69		    if (this.readyState === "complete" || this.readyState === "loaded") {
70			handlebarsLoadHandler();
71		    }
72		};
73	    } else {
74		console.log("else", jQuery);
75		handlebars_tag.onload = handlebarsLoadHandler;
76	    }
77	    (document.getElementsByTagName("head")[0] ||
78	     document.documentElement).appendChild(handlebars_tag);
79	} else {
80	    console.log("existed" + jQuery);
81	    Handlebars = window.Handlebars;
82	    main();
83	}
84    }
85
86    function handlebarsLoadHandler() {
87	Handlebars = window.Handlebars.noConflict(true);
88	console.log("handler" + jQuery);
89	main();
90    }
91
92    function formatDate(text) {
93	let dt = new Date(text);
94	let year = Intl.DateTimeFormat('en-US', {year: 'numeric'}).format(dt);
95	let month = Intl.DateTimeFormat('en-US', {month: 'short'}).format(dt);
96	let day = Intl.DateTimeFormat('en-US', {day: 'numeric'}).format(dt);
97	return month + ". " + day + ", " + year;
98    }
99
100    function loadWidget($) {
101	/******* Load HTML-template ******/
102	let events_widget = $("#discotech-events-widget");
103	let params = {'expand': 'venue.city'};
104
105	let max_count = 10;
106	if(events_widget.data('max_count')) {
107	    max_count = parseInt(events_widget.data('max_count'));
108	}
109
110	let api_url;
111	if(events_widget.data('venue_id')) {
112	    api_url = discotech.base_url + "venues/" + events_widget.data('venue_id') + "/events";
113	} else if(events_widget.data('venue_ids')) {
114	    api_url = discotech.base_url + "events";
115	    params.venue_ids = events_widget.data('venue_ids');
116	} else if(events_widget.data('city_id')) {
117	    api_url = discotech.base_url + "cities/" + events_widget.data('city_id') + "/events";
118	} else {
119	    api_url = discotech.base_url + "events";
120	    let pathArray = window.location.pathname.split('/');
121	    params.city_slug = pathArray[1];
122	    params.venue_slug = pathArray[2];
123	}
124
125	$.getJSON(api_url, params, function(data){
126	    if(data.data.length === 0) {
127		if(events_widget.length === 1){
128		    events_widget.hide();
129		}
130		return false;
131	    }
132
133	    if(events_widget.length === 0) {
134		let last_child_element = $("div.entry-content-wrapper").children().last();
135		while (last_child_element.is("form") || last_child_element.is(":empty")) {
136		    last_child_element = last_child_element.prev();
137		}
138		events_widget = $("<div id='discotech-events-widget'></div>");
139		last_child_element.after(events_widget);
140	    }
141
142	    let template = Handlebars.compile("<ul id='discotech-events-container'>{{#each events as |event|}}{{> event_partial }}{{/each}}</ul>");
143	    let widgetHTML = $(template({'events': data.data.slice(0,max_count)}));
144
145	    /* fill the widget with server generated html */
146	    events_widget.html(widgetHTML);
147
148	    /* replace errored imgs with the venue logo */
149	    $("img").on("error", function(e){
150		let venue_logo = $(this).data('venueLogo');
151		$(this).attr("src", venue_logo);
152	    });
153
154	    /* add structured data for google searches */
155	    if(data.structured_data){
156		$("head").append("<script type='application/ld+json'>" +
157				 JSON.stringify(data.structured_data) + "</script>");
158	    }
159
160	});
161    }
162
163    /******** Our main function ********/
164    function main() {
165
166	jQuery(document).ready(function($) {
167
168	    // Check if we"re on the correct page
169	    let url = window.location;
170	    if($('div#discotech-events-widget').length < 1){
171
172		if(url.pathname.split("/").length < 4) {
173		    return false;
174		}
175
176		if($("h3:contains('Location')").length < 1) {
177		    return false;
178		}
179
180		if($("ul.nested_nav li a[href='"+url.href+"']").length < 1) {
181		    return false;
182		}
183	    }
184
185	    /******* Load CSS *******/
186	    let css_link = $("<link>", {
187		rel: "stylesheet",
188		type: "text/css",
189		href: discotech.stylesheet
190	    });
191	    css_link.appendTo("head");
192
193	    /******* Register Handlebars helper and partial *******/
194	    Handlebars.registerHelper('format_date', formatDate);
195
196	    let partial_template = "<li class='wrapper'> <div class='mid-wrapper'> <div class='mid'> <span class='event-info date'>{{format_date start}}</span> <span class='event-info name'> <a href='{{url}}'><span class='headline'>{{name}}</span> at <b class='venue'>{{venue.name}}</b></a> </span> <span class='event-info location'>{{venue.city.name}}, {{venue.city.state}}</span> </div></div><a class='left' href='{{url}}'> <img class='flyer' src='{{image_url}}' alt='Image of flyer for the event{{name}}' href='{{url}}' data-venue-logo='{{venue.logo}}'> </a> <a class='right buy-btn' href='{{url}}'>Book Now</a></li>";
197	    Handlebars.registerPartial('event_partial', partial_template);
198
199	    loadWidget($);
200
201	    if(!url.href.includes("bottle-service")) {
202		$("form.avia_ajax_form").remove();
203	    }
204	});
205    }
206})());

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.