(function () {
// Localize jQuery variable
var jQuery;
/******** Load jQuery if not present *********/
if (window.jQuery === undefined || window.jQuery.fn.jquery !== '3.2.1') {
var script_tag = document.createElement('script');
script_tag.setAttribute("type", "text/javascript");
script_tag.setAttribute("src",
"https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js");
if (script_tag.readyState) {
script_tag.onreadystatechange = function () { // For old versions of IE
if (this.readyState == 'complete' || this.readyState == 'loaded') {
scriptLoadHandler();
}
};
} else {
script_tag.onload = scriptLoadHandler;
}
// Try to find the head, otherwise default to the documentElement
(document.getElementsByTagName("head")[0] || document.documentElement).appendChild(script_tag);
} else {
// The jQuery version on the window is the one we want to use
jQuery = window.jQuery;
main();
}
/******** Called once jQuery has loaded ******/
function scriptLoadHandler() {
// Restore $ and window.jQuery to prev,store the new jQuery in local variable
jQuery = window.jQuery.noConflict(true);
// Call our main function
main();
}
/******* Data functions *******/
function formatAMPM(date, format) {
if (format === '12') {
var hours = date.getUTCHours();
var minutes = date.getUTCMinutes();
var ampm = hours >= 12 ? 'pm' : 'am';
hours = hours % 12;
hours = hours ? hours : 12; // the hour '0' should be '12'
minutes = minutes < 10 ? '0' + minutes : minutes;
var strTime = hours + ':' + minutes + ' ' + ampm;
} else if (format === '24') {
var hours = date.getUTCHours();
var minutes = date.getUTCMinutes();
minutes = minutes < 10 ? '0' + minutes : minutes;
var strTime = hours + ':' + minutes;
}
return strTime;
}
function base64_decode(str) {
if (window.atob) // Internet Explorer 10 and above
return decodeURIComponent(escape(window.atob(str)));
else { // Cross-Browser Method (compressed) // Create Base64 Object
var Base64 = { _keyStr: "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=", encode: function (e) { var t = ""; var n, r, i, s, o, u, a; var f = 0; e = Base64._utf8_encode(e); while (f < e.length) { n = e.charCodeAt(f++); r = e.charCodeAt(f++); i = e.charCodeAt(f++); s = n >> 2; o = (n & 3) << 4 | r >> 4; u = (r & 15) << 2 | i >> 6; a = i & 63; if (isNaN(r)) { u = a = 64 } else if (isNaN(i)) { a = 64 } t = t + this._keyStr.charAt(s) + this._keyStr.charAt(o) + this._keyStr.charAt(u) + this._keyStr.charAt(a) } return t }, decode: function (e) { var t = ""; var n, r, i; var s, o, u, a; var f = 0; e = e.replace(/[^A-Za-z0-9\+\/\=]/g, ""); while (f < e.length) { s = this._keyStr.indexOf(e.charAt(f++)); o = this._keyStr.indexOf(e.charAt(f++)); u = this._keyStr.indexOf(e.charAt(f++)); a = this._keyStr.indexOf(e.charAt(f++)); n = s << 2 | o >> 4; r = (o & 15) << 4 | u >> 2; i = (u & 3) << 6 | a; t = t + String.fromCharCode(n); if (u != 64) { t = t + String.fromCharCode(r) } if (a != 64) { t = t + String.fromCharCode(i) } } t = Base64._utf8_decode(t); return t }, _utf8_encode: function (e) { e = e.replace(/\r\n/g, "\n"); var t = ""; for (var n = 0; n < e.length; n++) { var r = e.charCodeAt(n); if (r < 128) { t += String.fromCharCode(r) } else if (r > 127 && r < 2048) { t += String.fromCharCode(r >> 6 | 192); t += String.fromCharCode(r & 63 | 128) } else { t += String.fromCharCode(r >> 12 | 224); t += String.fromCharCode(r >> 6 & 63 | 128); t += String.fromCharCode(r & 63 | 128) } } return t }, _utf8_decode: function (e) { var t = ""; var n = 0; var r = c1 = c2 = 0; while (n < e.length) { r = e.charCodeAt(n); if (r < 128) { t += String.fromCharCode(r); n++ } else if (r > 191 && r < 224) { c2 = e.charCodeAt(n + 1); t += String.fromCharCode((r & 31) << 6 | c2 & 63); n += 2 } else { c2 = e.charCodeAt(n + 1); c3 = e.charCodeAt(n + 2); t += String.fromCharCode((r & 15) << 12 | (c2 & 63) << 6 | c3 & 63); n += 3 } } return t } }
// Encode the String
return decodeURIComponent(escape(Base64.decode(str)));
}
}
function ytEscapeHtml(text) {
return text
.replace(/&/g, "&")
.replace(/'/g, "'");
}
/******** Our main function ********/
function main() {
jQuery(document).ready(function ($) {
var yturl = "https://www.yogatrail.com/";
var yturl_cdn = "https://www.yogatrail.com/";
if (window.location.hostname == "lyogatrail-widget.buzzwoo.de") {
yturl = "https://lyogatrail.buzzwoo.de/";
yturl_cdn = "https://lyogatrail.buzzwoo.de/";
}
var $ytw_container = $('#ytw-container');
var config_id = $ytw_container.attr('data-config');
var data_fbid = $ytw_container.attr('data-fbid');
var data_appid = $ytw_container.attr('data-appid');
var data_nid = $ytw_container.attr('data-nid');
var data_platform = $ytw_container.attr('data-platform');
// overwrite config values?
var data_overwrite_colors = typeof $ytw_container.attr('data-overwrite_colors') !== typeof undefined ? encodeURIComponent($ytw_container.attr('data-overwrite_colors')) : "";
var data_overwrite_font = typeof $ytw_container.attr('data-overwrite_colors') !== typeof undefined ? $ytw_container.attr('data-overwrite_font') : "";
// if nid exists it overwrites the config id
if (typeof data_nid !== typeof undefined) {
config_id = 0;
}
else {
data_nid = 0;
}
if (typeof data_fbid !== typeof undefined && data_fbid !== false && data_fbid !== "" && data_fbid !== "null") {
var parent_url = "https://www.facebook.com/" + data_fbid + "/app/" + data_appid;
}
else {
var parent_url = (window.location != window.parent.location) ? document.referrer : document.location.href;
}
if (typeof api_test_path !== typeof undefined) {
var jsonp_url = api_test_path + "schedule-widget/" + config_id + "?callback=callback&v=2" + "&parent_url=" + parent_url + "&bookable=1&nid=" + data_nid + "&platform=" + data_platform + "&overwrite_colors=" + data_overwrite_colors + "&overwrite_font=" + data_overwrite_font;
}
else {
var jsonp_url = yturl_cdn + "api/schedule-widget/" + config_id + "?callback=callback&v=2" + "&parent_url=" + parent_url + "&bookable=1&nid=" + data_nid + "&platform=" + data_platform + "&overwrite_colors=" + data_overwrite_colors + "&overwrite_font=" + data_overwrite_font;
}
// var json_data;
$.ajax({
type: 'GET',
url: jsonp_url,
cache: false,
crossDomain: true,
xhrFields: {
withCredentials: false
},
success: function (data, status, xhr) {
var ytw = data.config_data;
var output = '';
var arr_instr = {};
var arr_venue = {};
var arr_classes = {};
var grd_of = 'ytw-grd-1-' + ytw.num_cols;
var font_css = '';
$("head").append("");
switch (ytw.font) {
case 'inherit':
font_css += "#ytw-container * { font-family: Arial; }";
break;
case 'open-sans':
font_css += "@import url(https://fonts.googleapis.com/css?family=Open+Sans);";
font_css += "#ytw-container * { font-family: 'Open Sans', sans-serif; }";
break;
case 'droid-sans':
font_css += "@import url(https://fonts.googleapis.com/css?family=Droid+Sans);"
font_css += "#ytw-container * { font-family: 'Droid Sans', sans-serif; }";
break;
case 'arial':
font_css += "#ytw-container * { font-family: Arial, Helvetica, sans-serif; }";
break;
case 'tahoma':
font_css += "#ytw-container * { font-family: Tahoma, Geneva, sans-serif; }";
break;
case 'verdana':
font_css += "#ytw-container * { font-family: Verdana, Geneva, sans-serif; }";
break;
}
$("#yogatrail_fonts").text(font_css);
if (ytw.title_show) {
$ytw_container.append('
' + ytw.title + '
');
}
if (ytw.filter_toggle) {
var filter_html = '';
for (var filter in ytw.filters) {
filter_html += '';
}
filter_html += '
';
$ytw_container.append(filter_html);
}
$ytw_container.append('');
$("#ytw-filters").hide();
$ytw_container.append(''); // TODO: use cdn/get proper link for loading image, or use base64
$(".ytw-loader").show();
/******* Load CSS *******/
// Hack for dev.
var css_link = $("", {
rel: "stylesheet",
id: "yogatrail_base_css",
type: "text/css",
href: ytw.base_path + "style.min.css?v=1.0"
});
css_link.appendTo('head');
/******* Add custom color picker CSS *******/
if (ytw.toggle_colors) {
$("head").append("");
// setup colour css to be added above custom css (header_bg, header_text, row_text, row_bg_odd, row_bg_even)
var color_css = '';
color_css += '/* User selected custom colours */' + "\n";
color_css += '#ytw-wrapper .ytw-headings { background-color: #' + ytw.colors.header_bg + " !important; } \n";
color_css += '#ytw-wrapper .ytw-headings { color: #' + ytw.colors.header_text + " !important; } \n";
color_css += '#ytw-wrapper .ytw-class-wrapper { color: #' + ytw.colors.row_text + " !important; } \n";
color_css += '#ytw-wrapper .ytw-class-wrapper a:link, #ytw-wrapper .ytw-class-wrapper a:visited { color: #' + ytw.colors.row_links + " !important; } \n";
color_css += '#ytw-wrapper .ytw-class-wrapper.odd { background-color: #' + ytw.colors.row_bg_odd + " !important; } \n";
color_css += '#ytw-wrapper .ytw-class-wrapper.even { background-color: #' + ytw.colors.row_bg_even + " !important; } \n";
color_css += '#ytw-wrapper .ytw-class-wrapper.odd:hover { background-color: #' + ytw.colors.row_bg_hover + " !important; } \n";
color_css += '#ytw-wrapper .ytw-class-wrapper.even:hover { background-color: #' + ytw.colors.row_bg_hover + " !important; } \n";
color_css += '#ytw-wrapper .signup-body .ytw-button { background-color: #' + ytw.colors.signup_button_bg + " !important; } \n";
color_css += '#ytw-wrapper .signup-body .ytw-button { color: #' + ytw.colors.signup_button_text + " !important; } \n";
$("#yogatrail_custom_colors").text(color_css);
}
if (ytw.css) {
$("head").append("");
var cust_css = '/* Manually inserted user CSS */' + "\n" + ytw.css;
$("#yogatrail_custom_colors").text(cust_css);
}
var dayloop = data.results.length;
/******* no results *******/
if (dayloop == 0) {
output += 'There are currently no classes available for this Yoga Provider. Please visit ';
if (ytw.timeframe !== 'all') {
dayloop = (dayloop <= ytw.timeframe ? dayloop : ytw.timeframe);
}
for (var i = 0; i < dayloop; i++) {
var day = data.results[i];
output += '';
output += '
';
output += '
';
output += '';
// only show this column for teachers
if (ytw.columns.hasOwnProperty('venue') && ytw.profile_type == "teacher") {
output += '';
}
// only show this column for places
if (ytw.columns.hasOwnProperty('instructor') && ytw.profile_type != "teacher") {
output += '';
}
if (ytw.columns.hasOwnProperty('signup')) {
output += '';
}
output += '
'; // doesnt close day div
for (var j = 0; j < day.results.length; j++) {
var class_info = day.results[j];
var row_class = (j % 2 == 0) ? 'odd' : 'even'; // move this to zebra all rows, not specific
var class_class = class_info.name.replace(/\s+/g, '-').toLowerCase();
//convert seconds to miliseconds
var stime = class_info.date_timestamp_start + '000';
var etime = class_info.date_timestamp_end + '000';
var sts = new Date(Number(stime));
var ets = new Date(Number(etime));
var teacher_nid = 0;
sts = formatAMPM(sts, ytw.time1224);
ets = formatAMPM(ets, ytw.time1224);
// build filter objects & arrays
if (class_info.hasOwnProperty("teachers") && typeof class_info.teachers[0] !== 'undefined') {
arr_instr[class_info.teachers[0].entity_ID] = class_info.teachers[0].name;
teacher_nid = class_info.teachers[0].entity_ID;
}
else {
class_info['teachers'] = [{ entity_ID: 0 }];
class_info['teachers'] = [{ name: '' }];
}
if (class_info.hasOwnProperty("venues") && typeof class_info.venues[0] !== 'undefined') {
arr_venue[class_info.venues[0].entity_ID] = class_info.venues[0].name;
}
else {
class_info['venues'] = [{ entity_ID: 0 }];
class_info['venues'] = [{ name: '' }];
}
arr_classes[class_class] = class_info.name;
// Build class wrapper
var class_info_classes = ['ytw-class-wrapper', 'ytw-section', 'ytw-group', class_class, class_info.teachers[0].entity_ID, class_info.venues[0].entity_ID, row_class, class_info.class_status].join(' ');
if (ytw.pro.backlinks && teacher_nid > 0) {
output += '
';
}
else {
output += '';
}
}
output += '
';
}
output += '';
/******* prepare filters (if enabled) *******/
if (ytw.filter_toggle === 1) {
if (ytw.filters.hasOwnProperty('classes')) {
$('#ytw-filters #classes').append($('