(function($) {
"use strict";
/*
* This checks for
* - existing jQuery (add it if not),
* - the use of $ outside of jQuery
* and registers 'ebFrontEnd' as jQuery plugin for easy implementation of the booking engine.
*
* This Version adds the booking engine as section and not as an iFrame (as in prev. versions)!
*
* Author:
*/
(function integrateBookingEngine(sign) {
var dollarSignUsed = typeof sign == 'undefined' ? false : sign;
if (typeof jQuery != 'undefined') {
// jQuery is defined and we are ready to go
// this means some other JS is already using $ as a global, so we have to put jQuery in noConflict mode
if (dollarSignUsed) $.noConflict(); // Get Booking Engine from server and register it as jQuery function
(function ($) {
"use strict"; // var currentStep = -1; // used to implement scrolling to top the top after going to the next step
function FrontendFrame(el, opts) {
var that,
randID = "",
possible = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"; // Get parent to render the booking-engine into
this.$el = $(el); // Set server from where to get the booking-engine
this.server = '//www.easy-booking.at';
this.dev = "www.easy-booking.at" !== "www." + "easy-booking" + ".at"; // check if it's the dev environment
// set the defaults and merge with given options
this.defaults = {
customerId: 331,
localeId: 2,
frameId: "ebFrontEndPlugin",
frameClass: "ebFrontEndPlugin",
frameWidth: "auto",
frameHeight: "auto",
// "auto" will cause the plugin to autoresize itself in a given interval, otherwise will use the given plugin height
serialNo: "2729-3350-3485",
conversionReservation: "",
conversionEnquiry: "",
source: "",
backgroundColor: "",
showAvailability: false,
fontColor: "",
headingColor: "",
hideFilters: "off",
resizeInterval: 500,
// resize interval in milliseconds
disableScroll: false,
scrollOffset: 0,
gaAutolinkDomains: "",
adultOnly: false,
gtmDL: "dataLayer",
cppVersion: "V 0.0",
cppValidityDate: "1900/01/01",
cppName: "Privacy Policy (Custom)",
cppUrl: "",
minimumStay: 3,
cateringFeaturesText: "",
collapsedExtras: false,
ignoreIframeUrl: false,
rdrToHome: false,
disableAutoTranslate: false
};
opts['mainWrapper'] = el.id;
this.opts = $.extend(this.defaults, opts); // Check some of the given parameters and parse them accordingly
this.opts.customerId = isNaN(this.opts.customerId) ? -1 : parseInt(this.opts.customerId);
this.opts.localeId = isNaN(this.opts.localeId) ? -1 : parseInt(this.opts.localeId);
this.opts.resizeInterval = isNaN(this.opts.resizeInterval) ? 500 : parseInt(this.opts.resizeInterval);
this.opts.scrollOffset = isNaN(this.opts.scrollOffset) ? 0 : parseInt(this.opts.scrollOffset); // generate random key to identify messages sent from/to booking-engine (mainly used for iFrame integration)
this.opts.randKey = Math.random().toString(36).substring(7); // append random string to frameID
for (var i = 0; i < 5; i++) {
randID += possible.charAt(Math.floor(Math.random() * possible.length));
}
this.opts.frameId += randID;
if (this.opts.disableAutoTranslate) {
this.$el.attr('translate', 'no');
}
if (this.dev) {
this.init();
} else {
that = this; // Do multidb host check!
$.ajax({
url: this.server + '/bookingengine2/mdb.php?c=' + this.opts.customerId + '&l=' + this.opts.localeId,
dataType: 'json',
success: function success(data) {
if (!that.dev && data.apiHost && '//' + data.apiHost !== that.server) {
that.server = '//' + data.apiHost;
}
that.init();
console.debug('XHR --> MDB', '\n\tUrl:', this.url, '\n\tResponse:', data);
},
error: function error() {
that.init();
console.debug('XHR --> MDB Error', '\n\tUrl:', this.url, '\n\tError fetching MDB Host. Using default server (', that.server, ')');
}
});
}
}
FrontendFrame.prototype.init = function () {
var that = this; // check serial Number
var apiUrl = this.server + '/easybooking/index.php/apiHotel/';
var apiCall = "checkSerialNo/";
var apiParams = this.opts.customerId + "/0/" + this.opts.serialNo;
$.ajax({
url: apiUrl + apiCall + apiParams,
dataType: "json",
success: function success(r) {
if (r.valid === true) {
// serial is valid --> continue
that.initSuccess();
} else {
that.serialNoError("invalid");
}
console.debug('XHR --> API', '\n\tUrl:', this.url, '\n\tResponse:', r);
},
error: function error(r) {
that.serialNoError("server");
console.debug('XHR --> API Error', '\n\tUrl:', this.url, '\n\tResponse:', r);
}
});
};
FrontendFrame.prototype.initSuccess = function () {
// var addedSection = false;
var that = this;
var opts = this.opts; //GV added this
//If the content is hosted on www.uberclue.com then we know it is content in facebook via HyperTab and FB blocks the command : top.location
//So no params are possible here..
var parametersStr = "";
if (document.domain !== "www.uberclue.com") {
parametersStr = window.location.search.substr(1);
}
var parametersArray = decodeURIComponent(parametersStr).split("&");
var parameters = {}; // if we have params in the url, parse them into the iframe url
if (parametersArray.length > 0) {
this.params = {};
for (var i = 0; i < parametersArray.length; i++) {
var parameterParts = parametersArray[i].split("=");
parameters[parameterParts[0]] = parameterParts[1];
}
this.fetchUrlParameters(parameters);
}
var widgetUrl = this.server + '/bookingengine2/';
if (!this.opts.encapsulated) {
widgetUrl += '?directIntegration';
} else {
var srcParam = [];
if (opts.source.length > 0) {
srcParam.push("source=" + opts.source);
}
if (opts.backgroundColor.length > 0) {
srcParam.push("backgroundColor=" + opts.backgroundColor.replace("#", "%23"));
}
if (opts.fontColor.length > 0) {
srcParam.push("fontColor=" + opts.fontColor.replace("#", "%23"));
}
if (opts.headingColor.length > 0) {
srcParam.push("headingColor=" + opts.headingColor.replace("#", "%23"));
}
if (opts.hideFilters === "on") {
srcParam.push("hideFilters=on");
}
if (opts.showAvailability === false) {
srcParam.push("showAvailability=false");
}
if (opts.adultOnly) {
srcParam.push("adultOnly=on");
}
if (opts.cppUrl.length > 0) {
srcParam.push('cppu=' + encodeURI(opts.cppUrl));
srcParam.push('cppv=' + encodeURI(opts.cppVersion));
srcParam.push('cppd=' + encodeURI(opts.cppValidityDate));
srcParam.push('cppn=' + encodeURI(opts.cppName));
}
if (opts.cateringFeaturesText.length > 0) {
srcParam.push('scoFeat=' + encodeURI(opts.cateringFeaturesText));
}
if (opts.collapsedExtras === true) {
srcParam.push("collapsedExtras=true");
}
if (opts.disableScroll == true) {
srcParam.pop('disableScroll=true');
}
if (opts.ignoreIframeUrl) {
srcParam.push('ignoreIframeUrl=true');
}
if (opts.rdrToHome) {
srcParam.push('rdrToHome=true');
}
widgetUrl += '?embedded';
if (srcParam.length > 0) {
widgetUrl += '&' + srcParam.join('&');
}
if (this.opts.encapsulated && window.ebbeWidget.params) {
widgetUrl += '&' + this.getIframeUrlParameters();
}
widgetUrl += '#/' + opts.customerId + '/' + opts.localeId;
}
that.addSection(widgetUrl);
if (window.addEventListener) {
window.addEventListener("message", function (e) {
that.receiveMessage(e);
}, false);
} else {
// some versions of IE only have attachEvent instead of addEventListener
window.attachEvent("message", function (e) {
that.receiveMessage(e);
});
}
};
FrontendFrame.prototype.addSection = function (frameUrl) {
var encapsulated = !!this.opts.encapsulated;
var that = this;
var $frame = $(encapsulated ? '