console.log(window);
// For cross-compatibility
if (!Array.prototype.forEach){
Array.prototype.forEach = function(fun /*, thisArg */){
"use strict";
if (this === void 0 || this === null || typeof fun !== "function") throw new TypeError();
var
t = Object(this),
len = t.length >>> 0,
thisArg = arguments.length >= 2 ? arguments[1] : void 0;
for (var i = 0; i < len; i++)
if (i in t)
fun.call(thisArg, t[i], i, t);
};
}
// *********************************** CLIENT FORM LOADER *****************************************
!(function() {
var domain = 'ext.ihbooking.ru';
var parentPageDomain = document.location.hostname;
console.log("parentPageDomain: ", document.location.hostname);
var host = ('https:' == document.location.protocol ? 'https://' : 'http://') + domain;
console.log("host: ", host);
//
var addScript = function(url) {
var script = document.createElement('script');
script.type = "text/javascript";
script.async = true;
script.src = url;
var s = (document.getElementsByTagName("head")[0] || document.documentElement);
s.appendChild(script);
//
return script;
};
var loader = addScript(host + '/js/deploy/ih.min.js');
if (!this.ymaps) {
var yandexMaps = addScript('//api-maps.yandex.ru/2.1/?load=package.full&lang=ru-ru');
}
//var yandexMaps = addScript('//api-maps.yandex.ru/2.1/?load=package.full&lang=ru-ru');
// var yandexMaps = addScript('/js/yandex.maps/api.yamaps-2.1.2-ru.js');
//addScript(host + '/js/yandex.maps/multi-geocoder.js');
addScript(host + '/js/swiper/swiper.min.js');
addScript(host + '/js/libs/accounting.min.js');
function retry(callback) {
window.setTimeout(function() {
loaded(callback);
}, 0);
}
//
function loaded(callback) {
var wjq = window.jQuery;
if (!wjq) return retry(callback);
//
if (wjq.__ihinstanceready__ === undefined) return retry(callback);
//
callback(wjq);
}
//
loaded(function($) {
var ih = $.noConflict(true);
ih("head").append("");
ih("head").append("");
// Global custom jquery reference
// Used by:
// 1. fancybox thumbs - js/fancybox/source/helpers/jquery.fancybox-thumbs.js, line 57 updated
window.ihbooking = ih;
//
ih(function() {
var getUniqueId = function(prefix) {
return (prefix ? prefix + '-' : 'id-') + Math.random().toString(36).substr(2, 16);
};
var ihbookingContainer = ih('#ihbooking-content');
// CSS
var css = ih('', {
rel: 'stylesheet',
type: 'text/css',
href: host + "/js/deploy/ih.min.css"
});
css.appendTo('head');
var css = ih('', {
rel: 'stylesheet',
type: 'text/css',
href: host + "/css/ihbooking.css"
});
css.appendTo('head');
// MAP CONTAINER
var mapContainer = ih('
', {
id: 'inline-map',
style: 'width: 600px; height: 400px; display: none;'
});
ihbookingContainer.append(mapContainer);
//PARENT WINDOW CONTROLLER (via postMessages)
function addListner(host){
//KHR: this script allows your site to receive messages from iFrame element
window.addEventListener('message', function(event) {
// IMPORTANT: check the origin (iframe document URL) of the data!
if (~event.origin.indexOf(host)) {
var receivedData = event.data;
var scrollerTopSetting = $('#'+IFRAME_ID).offset() ? $('#'+IFRAME_ID).offset().top - 10 : 0;
if (receivedData.funcName == '_doScrollTop'){
//console.log("_doScrollTop");
//scroller factory settings
$('html,body').animate({ scrollTop: scrollerTopSetting }, 'fast');
}else if (receivedData.funcName == '_doScrollToMap'){
//console.log("_doScrollMap");
$("body,html").animate({scrollTop: receivedData.offsetTop + scrollerTopSetting}, "fast");
}
else if (receivedData.funcName == '_doTest'){
alert("This is alert of parent window invoked from iframe with host: " + host);
}
else if (receivedData.funcName == '_doAppendToUrl'){
var newSearch = "";
if (location.search.length > 0){
console.log(location.search);
var locSearch = location.search.replace('?','');
var pairs = locSearch.split("&");
var newPairs = [];
var replaceFlag = false;
for (var i = 0; i < pairs.length; i++){
var tmpKey = pairs[i].split("=")[0];
var tmpVal = pairs[i].split("=")[1];
//escape this param when needed
if (tmpKey === receivedData.appendingKey && receivedData.appendingVal === ""){
replaceFlag = true;
continue;
}
if (tmpKey === receivedData.appendingKey){
tmpVal = receivedData.appendingVal;
replaceFlag = true;
}
newPairs.push(tmpKey + "=" + tmpVal);
}
var newLocSearch = newPairs.join("&");
if (!replaceFlag && receivedData.appendingVal.length > 0)
newLocSearch += "&" + receivedData.appendingKey + "=" + receivedData.appendingVal;
newSearch = "?" + newLocSearch;
}
else
{
if (receivedData.appendingVal.length > 0)
newSearch = "?" + receivedData.appendingKey + "=" + receivedData.appendingVal;
}
if (newSearch === "?") newSearch = "";
var resultUrl = location.protocol + '//' + location.host + location.pathname + newSearch;
console.log(resultUrl);
window.history.replaceState(null, null, resultUrl);
}
else if (receivedData.funcName == '_doReachYandexGoal'){
//console.log("ya reachGoal id=" + receivedData.targetId + " was called with postmsg");
for (var wProp in window) {
if (wProp.indexOf('yaCounter') !== -1){
var cnt = window[wProp];
if (cnt && typeof cnt.reachGoal === 'function'){
//console.log("cnt exists: ", wProp, cnt);
try{
cnt.reachGoal(receivedData.targetId, function(e){
//console.log('reach goal callback: ', e);
});
}catch(ex)
{
console.warn('reach goal exception: ', ex);
}
}else{
console.log("ya meter '" + wProp + "' was not found");
}
}
}
}
} else {
// The data hasn't been sent from iframe, do not use it
return;
}
});
}
addListner(host);
//BLOCK BELOW ALLOWS YOU TO NAVIGATE TO SIGN IN PAGES INSIDE IFRAME USING PARENT PAGE
//URL PARAMS. I.E. url ...ru/index.html?cabinet=agent -> forces iframe to start with
//auth_agent.html page.
//get param returner
$.urlParam = function(name, path){
var results = new RegExp('[\?&]' + name + '=([^]*)').exec(path ? path : window.location.href);
if (results && results.length > 1)
return results[1];
else
return null;
};
var iframeSrcCabinetParam = null;
var iframeSrcCabinetCred = null;
var cabinetName = $.urlParam('cabinet');
switch (cabinetName)
{
case "client" : {
//user email
var clientAuthData = {
userEmail: $.urlParam('ue'),
letNumber: $.urlParam('ln')
};
if (clientAuthData.userEmail && clientAuthData.letNumber) {
iframeSrcCabinetCred = "&ue=" + clientAuthData.userEmail + "&ln=" + clientAuthData.letNumber;
}
}
case "agent" :
case "object" : {
//remove parameter from location
var l = window.location.href.split("?cabinet")[0];
window.history.pushState("", "", l);
iframeSrcCabinetParam = cabinetName;
break;
}
}
// определяет в каком режиме грузится ли форма в виде виджета
// по параметру &step=widget
var isWidgetMode = false;
var iframeSrcStepParam = $.urlParam('step',"");
if (iframeSrcStepParam === 'widget')
isWidgetMode = true;
var userUrlParams = window.location.search.substr(1);
userUrlParams = userUrlParams ? '&' + userUrlParams : "";
console.log('userUrlParams', userUrlParams);
// MAIN IFRAME
var IFRAME_ID = 'ihbooking-iframe-uuid';
//var IFRAME_ID = getUniqueId('ihbooking-iframe');
var frameSrc = host + "/#/?key=129d9abda5498b5f823062a54e6ce68b&parentdomain=" + parentPageDomain + userUrlParams;
if (iframeSrcCabinetParam)
{
frameSrc = host + "/#/?key=129d9abda5498b5f823062a54e6ce68b&parentdomain=" + parentPageDomain + "" + userUrlParams;
var targReg = /step=[^&]*/i;
var foundRes = frameSrc.match(targReg);
if (foundRes && targReg.length > 0) {
frameSrc = frameSrc.replace(targReg, 'step='+ iframeSrcCabinetParam);
} else {
frameSrc += "&step=" + iframeSrcCabinetParam;
}
if (iframeSrcCabinetCred) {
frameSrc += iframeSrcCabinetCred;
}
}
var frm = ih("