Created
July 24, 2014 08:11
-
-
Save sbmaxx/27d839e5fa5520d1e3db to your computer and use it in GitHub Desktop.
toolbar.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
if (document.getElementById('toolbar') == null) | |
{ | |
var ORIGINAL_WIDTH = 0; | |
var FIRST_ORIENTATION = false; | |
var StartZoom = false; | |
var FULL_HEIGHT = false; | |
var PRE_HEIGHT_PAGE; | |
var PRE_WIDTH_PAGE; | |
//__IOS7_SPECIFIC BEGIN | |
var updateReferrerIntervalObj = null; | |
var gotUpdateReferrerDone = false; | |
var updateReferrerCounter = 0; | |
//__IOS7_SPECIFIC END | |
(function(jQFrm) | |
{ | |
if (window.XDomainRequest) | |
{ | |
jQFrm.ajaxTransport(function(s) | |
{ | |
if (s.crossDomain && s.async) | |
{ | |
if (s.timeout) | |
{ | |
s.xdrTimeout = s.timeout; | |
delete s.timeout; | |
} | |
var xdr; | |
return { | |
send: function(_, complete) | |
{ | |
function callback(status, statusText, responses, responseHeaders) | |
{ | |
xdr.onload = xdr.onerror = xdr.ontimeout = xdr.onprogress = jQFrm.noop; | |
xdr = undefined; | |
complete(status, statusText, responses, responseHeaders); | |
} | |
xdr = new XDomainRequest(); | |
xdr.open(s.type, s.url); | |
xdr.onload = function() | |
{ | |
callback(200, "OK", { text: xdr.responseText }, "Content-Type: " + xdr.contentType); | |
}; | |
xdr.onerror = function() | |
{ | |
callback(404, "Not Found"); | |
}; | |
xdr.onprogress = function() | |
{ | |
}; | |
if (s.xdrTimeout) | |
{ | |
xdr.ontimeout = function() | |
{ | |
callback(0, "timeout"); | |
}; | |
xdr.timeout = s.xdrTimeout; | |
} | |
xdr.send(( s.hasContent && s.data ) || null); | |
}, | |
abort: function() | |
{ | |
if (xdr) | |
{ | |
xdr.onerror = jQFrm.noop(); | |
xdr.abort(); | |
} | |
} | |
}; | |
} | |
}); | |
} | |
})(jQFrm); | |
jQFrm.noConflict(); | |
var ets_scripts = jQFrm('[name="ets-anchor"]'); | |
jQFrm(window).resize(function() | |
{ | |
resizeIframe(); | |
}); | |
if (ets_scripts.length == 1) | |
{ | |
(function($) | |
{ | |
$(document).ready(function() | |
{ | |
PRE_HEIGHT_PAGE = window.innerHeight; | |
PRE_WIDTH_PAGE = window.innerWidth; | |
//for search application | |
ETS_DOMAIN = 'http://toolbar.beeline.ru'; | |
if (self == top) | |
{ | |
$('html').append('<div id="toolbar" tabindex="-1" style="border-width:0px;outline-width:0px;"></div>'); | |
var currentTime = new Date(); | |
/*var pathname = window.location.href; | |
var screenWidth = screen.width;*/ | |
var ifrm = document.createElement("IFRAME"); | |
ifrm.setAttribute("id", "toolBarPcFrame"); | |
/*ifrm.setAttribute("src", "http://toolbar.beeline.ru/ets/ToolBarPcServlet?screenWidth="+screenWidth+"&url="+pathname);*/ | |
ifrm.setAttribute("src", "http://toolbar.beeline.ru/ets/ToolBarPcServlet"); | |
ifrm.setAttribute("allowtransparency", "true"); | |
ifrm.setAttribute("background-color", "transparent"); | |
ifrm.style.position = "fixed"; | |
ifrm.style.zIndex = 9999999999; | |
/*toolbar has the heightest zIndex of any other layer*/ | |
ifrm.style.width = 0; | |
ifrm.style.height = 0; | |
ifrm.style.margin = 0; | |
ifrm.style.padding = 0; | |
ifrm.style.bottom = 0; | |
ifrm.style.right = 0; | |
ifrm.style.border = "none"; | |
/*1px solid blue*/ | |
ifrm.style.display = "block"; | |
$('#toolbar').append(ifrm); | |
setTimeout(function() | |
{ | |
$('#toolbar').focus(); | |
}, 2000); | |
//__IOS7_SPECIFIC BEGIN | |
var iosVerNum = getIOSVersionNumber(); | |
if (iosVerNum >= 7) | |
{ | |
var updateReferrerMessage = new Array(); | |
updateReferrerMessage[0] = 'mxUpdateReferrer'; | |
updateReferrerMessage[1] = document.location.href; | |
updateReferrerIntervalObj = window.setInterval(function() | |
{ | |
if ($('#toolBarPcFrame').width() == 0 && !gotUpdateReferrerDone && updateReferrerCounter < 300) | |
{ | |
document.getElementById('toolBarPcFrame').contentWindow.postMessage(updateReferrerMessage, 'http://toolbar.beeline.ru'); | |
updateReferrerCounter++; | |
} | |
else | |
{ | |
window.clearInterval(updateReferrerIntervalObj); | |
} | |
}, 200); | |
} | |
//__IOS7_SPECIFIC END | |
} | |
}); | |
$(document).scroll(function() | |
{ | |
if (needsScrollUpdate) | |
{ | |
setTimeout(function() | |
{ | |
$("body").css("height", "+=1").css("height", "-=1"); | |
}, 0); | |
} | |
if (FULL_HEIGHT) | |
{ | |
var he = document.documentElement.clientHeight; | |
if (window.innerHeight > he) | |
{ | |
he = window.innerHeight; | |
} | |
document.getElementById('toolBarPcFrame').style.height = he + 'px'; | |
} | |
//resize for android | |
if (window.innerWidth != PRE_WIDTH_PAGE && window.innerHeight != PRE_HEIGHT_PAGE) | |
{ | |
PRE_WIDTH_PAGE = window.innerWidth; | |
PRE_HEIGHT_PAGE = window.innerHeight; | |
orientation_changed('windowResize'); | |
} | |
}); | |
})(jQFrm); | |
} | |
var needsScrollUpdate = false; | |
var ToolbarHeightHorizontalPercent; | |
var ToolbarHeightVerticallPercent; | |
(function() | |
{ | |
var msgHandler = function(e) | |
{ | |
/* | |
check that the origin is the right one. | |
*/ | |
var ets_frame = document.getElementById('toolBarPcFrame'); | |
if (e.origin == 'http://toolbar.beeline.ru') | |
{ | |
StartZoom = false; | |
var messageArray = new Array(); | |
if (typeof(e.data) != 'object') | |
{ | |
messageArray = e.data.split(','); | |
} | |
else | |
{ | |
for (var i = 0; i < e.data.length; i++) | |
{ | |
messageArray.push(e.data[i]); | |
} | |
} | |
if (e.data instanceof Array || messageArray.length > 1) | |
{ | |
if (messageArray[0] == 'resizeFramePc') | |
{ | |
document.getElementById('toolBarPcFrame').style.width = messageArray[1] + 'px'; | |
document.getElementById('toolBarPcFrame').style.height = messageArray[2] + 'px'; | |
if (messageArray[1] == true) | |
{ | |
document.getElementById('toolBarPcFrame').style.backgroundColor = 'rgba(120, 120, 120, 0.5)'; | |
FULL_HEIGHT = true; | |
} | |
else | |
{ | |
document.getElementById('toolBarPcFrame').style.backgroundColor = ''; | |
FULL_HEIGHT = false; | |
} | |
} | |
if (messageArray[0] == 'resizeFrameMobile') | |
{ | |
// document.getElementById('toolBarPcFrame').style.width = messageArray[1] + 'px'; | |
var appOpenBoxScaleX = window.innerWidth / 640; | |
var NewHeight = 10 + parseInt(document.getElementById('toolBarPcFrame').style.height) + parseInt(messageArray[1]) * appOpenBoxScaleX; | |
document.getElementById('toolBarPcFrame').style.height = NewHeight + 'px'; | |
} | |
if (messageArray[0] == 'stopDrag') | |
{ | |
document.getElementById('toolBarPcFrame').style.top = messageArray[1] + 'px'; | |
document.getElementById('toolBarPcFrame').style.height = '73px'; | |
} | |
if (messageArray[0] == 'stopDragMobile') | |
{ | |
document.getElementById('toolBarPcFrame').style.top = messageArray[1]; | |
document.getElementById('toolBarPcFrame').style.height = messageArray[2] + 'px'; | |
} | |
if (messageArray[0] == 'stopDragTablet') | |
{ | |
document.getElementById('toolBarPcFrame').style.top = messageArray[1]; | |
document.getElementById('toolBarPcFrame').style.height = messageArray[2] + 'px'; | |
} | |
if (messageArray[0] == 'changeHeight') | |
{ | |
if (messageArray[1] == 'fullHeight') | |
{ | |
document.getElementById('toolBarPcFrame').style['-webkit-transition'] = 'background 300ms ease-in 200ms'; | |
document.getElementById('toolBarPcFrame').style.backgroundColor = 'rgba(120, 120, 120, 0.5)'; | |
FULL_HEIGHT = true; | |
if ("pc".toLowerCase() == "iPad".toLowerCase()) | |
{ | |
document.getElementById('toolBarPcFrame').style.height = document.documentElement.clientHeight + 'px'; | |
if (window.innerHeight > document.documentElement.clientHeight) | |
{ | |
document.getElementById('toolBarPcFrame').style.height = window.innerHeight + 'px'; | |
/*if (parseInt(document.defaultView.getComputedStyle(document.documentElement, null).width)> window.innerWidth){ | |
document.getElementById('toolBarPcFrame').style.width = parseInt(document.defaultView.getComputedStyle(document.documentElement, null).width) + 'px'; | |
}*/ | |
} | |
} | |
else | |
{ /* for mobile and pc */ | |
document.getElementById('toolBarPcFrame').style.height = window.innerHeight + 'px'; | |
} | |
} | |
else if (messageArray[1] == 'fullHeightTablet2') | |
{ | |
document.getElementById('toolBarPcFrame').style['-webkit-transition'] = 'background 300ms ease-in 200ms'; | |
document.getElementById('toolBarPcFrame').style.backgroundColor = 'rgba(120, 120, 120, 0.5)'; | |
FULL_HEIGHT = true; | |
document.getElementById('toolBarPcFrame').style.height = document.documentElement.clientHeight + 'px'; | |
if (window.innerHeight > document.documentElement.clientHeight) | |
{ | |
document.getElementById('toolBarPcFrame').style.height = window.innerHeight + 'px'; | |
} | |
document.getElementById('toolBarPcFrame').style.width = document.documentElement.clientWidth + 'px'; | |
if (window.innerWidth > document.documentElement.clientWidth) | |
{ | |
document.getElementById('toolBarPcFrame').style.width = window.innerWidth + 'px'; | |
} | |
document.getElementById('toolBarPcFrame').contentWindow.postMessage('maximizeTabletResponse', 'http://toolbar.beeline.ru'); | |
} | |
else | |
{ | |
document.getElementById('toolBarPcFrame').style.backgroundColor = ''; | |
FULL_HEIGHT = false; | |
document.getElementById('toolBarPcFrame').style.height = messageArray[1]; | |
} | |
} | |
if (messageArray[0] == 'changeBottom') | |
{ | |
document.getElementById('toolBarPcFrame').style.bottom = messageArray[1]; | |
} | |
if (messageArray[0] == 'resizeMobile') | |
{ | |
if (needsScrollUpdate) | |
{ | |
document.getElementById('toolBarPcFrame').style.top = '0'; | |
document.getElementById('toolBarPcFrame').style.bottom = ''; | |
} | |
else | |
{ | |
document.getElementById('toolBarPcFrame').style.top = ''; | |
document.getElementById('toolBarPcFrame').style.bottom = '0'; | |
} | |
document.getElementById('toolBarPcFrame').style.height = messageArray[1] + 'px'; | |
/*Iphone*/ | |
document.getElementById('toolBarPcFrame').style.width = window.innerWidth + 'px'; | |
/*Android*/ | |
if (navigator.userAgent.indexOf("Android") !== -1) | |
{ | |
//document.getElementById('toolBarPcFrame').style.width = document.documentElement.clientWidth + 'px'; | |
document.getElementById('toolBarPcFrame').style.width = GetWidth() + 'px'; | |
} | |
} | |
if (messageArray[0] == 'resizeTablet') | |
{ | |
if (needsScrollUpdate) | |
{ | |
document.getElementById('toolBarPcFrame').style.top = '0'; | |
document.getElementById('toolBarPcFrame').style.bottom = ''; | |
} | |
else | |
{ | |
document.getElementById('toolBarPcFrame').style.top = ''; | |
document.getElementById('toolBarPcFrame').style.bottom = '0'; | |
} | |
document.getElementById('toolBarPcFrame').style.height = messageArray[1] + 'px'; | |
document.getElementById('toolBarPcFrame').style.width = document.documentElement.clientWidth + 'px'; | |
if (window.innerWidth > document.documentElement.clientWidth) | |
{ | |
document.getElementById('toolBarPcFrame').style.width = window.innerWidth + 'px'; | |
/*if (parseInt(document.defaultView.getComputedStyle(document.documentElement, null).width)> window.innerWidth){ | |
document.getElementById('toolBarPcFrame').style.width = parseInt(document.defaultView.getComputedStyle(document.documentElement, null).width) + 'px'; | |
}*/ | |
} | |
} | |
if (messageArray[0] == 'resizeTablet2') | |
{ | |
if (needsScrollUpdate) | |
{ | |
document.getElementById('toolBarPcFrame').style.top = '0'; | |
document.getElementById('toolBarPcFrame').style.bottom = ''; | |
} | |
else | |
{ | |
document.getElementById('toolBarPcFrame').style.top = ''; | |
document.getElementById('toolBarPcFrame').style.bottom = '0'; | |
} | |
document.getElementById('toolBarPcFrame').style.backgroundColor = ''; | |
FULL_HEIGHT = false; | |
document.getElementById('toolBarPcFrame').style.height = messageArray[1] + 'px'; | |
document.getElementById('toolBarPcFrame').style.width = messageArray[2] + 'px'; | |
/* if (window.innerWidth > document.documentElement.clientWidth ){ | |
document.getElementById('toolBarPcFrame').style.width = window.innerWidth+'px'; | |
*//*if (parseInt(document.defaultView.getComputedStyle(document.documentElement, null).width)> window.innerWidth){ | |
document.getElementById('toolBarPcFrame').style.width = parseInt(document.defaultView.getComputedStyle(document.documentElement, null).width) + 'px'; | |
}*//* | |
}*/ | |
} | |
if (messageArray[0] == 'openURL') | |
{ | |
window.open(messageArray[1], messageArray[2]); | |
} | |
if (messageArray[0] == 'needsScrollUpdate') | |
{ | |
if (messageArray[1] == 'true') | |
{ | |
needsScrollUpdate = true; | |
document.getElementById('toolBarPcFrame').style.bottom = ''; | |
document.getElementById('toolBarPcFrame').style.top = '0'; | |
} | |
else | |
{ | |
needsScrollUpdate = false; | |
document.getElementById('toolBarPcFrame').style.top = ''; | |
document.getElementById('toolBarPcFrame').style.bottom = '0'; | |
$("body").css("height", "+=1").css("height", "-=1"); | |
} | |
} | |
if (messageArray[0] == 'ToolbarHeightPercent') | |
{ | |
ToolbarHeightHorizontalPercent = messageArray[1] / 100; | |
ToolbarHeightVerticallPercent = messageArray[2] / 100; | |
} | |
/* if(e.data[0] == 'resizeHeightTablet') | |
{ | |
document.getElementById('toolBarPcFrame').style.height = e.data[1]; | |
}*/ | |
} | |
else if (e.data == 'maximize') | |
{ | |
document.getElementById('toolBarPcFrame').style.top = ''; | |
document.getElementById('toolBarPcFrame').style.height = '73px'; | |
document.getElementById('toolBarPcFrame').style.width = window.innerWidth + 'px'; | |
document.getElementById('toolBarPcFrame').contentWindow.postMessage('maximize', 'http://toolbar.beeline.ru'); | |
} | |
else if (e.data == 'maximizeWidthOnly') | |
{ | |
document.getElementById('toolBarPcFrame').style.top = ''; | |
document.getElementById('toolBarPcFrame').style.width = window.innerWidth + 'px'; | |
document.getElementById('toolBarPcFrame').contentWindow.postMessage('maximize', 'http://toolbar.beeline.ru'); | |
} | |
else if (e.data == 'alignPcBottom') | |
{ | |
document.getElementById('toolBarPcFrame').style.top = ''; | |
document.getElementById('toolBarPcFrame').style.height = '73px'; | |
} | |
else if (e.data == 'alignTabletBottom') | |
{ | |
document.getElementById('toolBarPcFrame').style.top = ''; | |
document.getElementById('toolBarPcFrame').style.height = window.innerWidth + 'px'; | |
} | |
else if (e.data == 'resize') | |
{ | |
document.getElementById('toolBarPcFrame').style.width = window.innerWidth + 'px'; | |
} | |
else if (e.data == 'startDrag') | |
{ | |
document.getElementById('toolBarPcFrame').style.top = '0'; | |
document.getElementById('toolBarPcFrame').style.height = window.innerHeight + 'px'; | |
document.getElementById('toolBarPcFrame').style.width = '88px'; | |
} | |
else if (e.data == 'startDragMobile') | |
{ | |
document.getElementById('toolBarPcFrame').style.top = '0'; | |
document.getElementById('toolBarPcFrame').style.height = window.innerHeight + 'px'; | |
} | |
else if (e.data == 'startDragTablet') | |
{ | |
document.getElementById('toolBarPcFrame').style.top = '0'; | |
document.getElementById('toolBarPcFrame').style.height = window.innerHeight + 'px'; | |
} | |
else if (e.data == 'parentWidth') | |
{ | |
var parentWidth = new Array(); | |
parentWidth[0] = 'parentWidth'; | |
parentWidth[1] = window.innerWidth; | |
ORIGINAL_WIDTH = window.innerWidth; | |
var ToolbarHeightPercent; | |
switch (window.orientation) | |
{ | |
case -90: | |
case 90: | |
ToolbarHeightPercent = ToolbarHeightHorizontalPercent; | |
break; | |
default: | |
ToolbarHeightPercent = ToolbarHeightVerticallPercent; | |
if (isLandscape()) | |
{ | |
ToolbarHeightPercent = ToolbarHeightHorizontalPercent; | |
} | |
break; | |
} | |
parentWidth[2] = ToolbarHeightPercent; | |
parentWidth[3] = 'ResizeToolbar'; | |
document.getElementById('toolBarPcFrame').contentWindow.postMessage(parentWidth, 'http://toolbar.beeline.ru'); | |
} | |
else if (e.data == 'parentHeight') | |
{ | |
var parentHeight = new Array(); | |
parentHeight[0] = 'parentHeight'; | |
parentHeight[1] = window.innerHeight; | |
var ToolbarAppBoxHeightPercent; | |
switch (window.orientation) | |
{ | |
case -90: | |
case 90: | |
ToolbarAppBoxHeightPercent = 0.95; | |
break; | |
default: | |
ToolbarAppBoxHeightPercent = 0.8; | |
if (isLandscape()) | |
{ | |
ToolbarAppBoxHeightPercent = 0.95; | |
} | |
break; | |
} | |
parentHeight[2] = ToolbarAppBoxHeightPercent; | |
document.getElementById('toolBarPcFrame').contentWindow.postMessage(parentHeight, 'http://toolbar.beeline.ru'); | |
FIRST_ORIENTATION = true; | |
} | |
else if (e.data == 'parentWidthTablet') | |
{ | |
var parentWidth = new Array(); | |
parentWidth[0] = 'parentWidth'; | |
var viewportInfo = getVisualViewportInfo(); | |
parentWidth[1] =viewportInfo.width; | |
/* if (parseInt(document.defaultView.getComputedStyle(document.documentElement, null).width) > parentWidth[1] ){ | |
parentWidth[1] = parseInt(document.defaultView.getComputedStyle(document.documentElement, null).width); | |
}*/ | |
var ToolbarHeightPercent; | |
var landscapeTablet = true; | |
switch (window.orientation) | |
{ | |
case -90: | |
case 90: | |
ToolbarHeightPercent = ToolbarHeightHorizontalPercent; | |
landscapeTablet = true; | |
break; | |
default: | |
ToolbarHeightPercent = ToolbarHeightVerticallPercent; | |
landscapeTablet = false; | |
if (isLandscape()) | |
{ | |
ToolbarHeightPercent = ToolbarHeightHorizontalPercent; | |
} | |
break; | |
} | |
if ("pc".toLowerCase() == "iPad".toLowerCase()) | |
{ | |
parentWidth[2] = landscapeTablet; | |
} | |
else | |
{ | |
parentWidth[2] = ToolbarHeightPercent; | |
} | |
document.getElementById('toolBarPcFrame').contentWindow.postMessage(parentWidth, 'http://toolbar.beeline.ru'); | |
} | |
else if (e.data == 'parentHeightTablet') | |
{ | |
var parentHeight = new Array(); | |
parentHeight[0] = 'parentHeight'; | |
parentHeight[1] = document.documentElement.clientHeight; | |
var ToolbarAppBoxHeightPercent; | |
switch (window.orientation) | |
{ | |
case -90: | |
case 90: | |
ToolbarAppBoxHeightPercent = 0.95; | |
break; | |
default: | |
ToolbarAppBoxHeightPercent = 0.8; | |
if (isLandscape()) | |
{ | |
ToolbarAppBoxHeightPercent = 0.95; | |
} | |
break; | |
} | |
parentHeight[2] = ToolbarAppBoxHeightPercent; | |
document.getElementById('toolBarPcFrame').contentWindow.postMessage(parentHeight, 'http://toolbar.beeline.ru'); | |
} | |
else if (e.data == 'fixBottomMobile') | |
{ | |
document.getElementById('toolBarPcFrame').style.position = "static"; | |
//change the height of the iframe | |
document.getElementById('toolBarPcFrame').height = document.documentElement.clientHeight; | |
document.getElementById('toolBarPcFrame').style.display = ""; | |
document.getElementById('toolBarPcFrame').style.position = "fixed"; | |
} | |
else if (e.data == 'fixBottom')/* for tablet*/ | |
{ | |
window.scrollBy(0, 1); | |
window.scrollBy(0, -1); | |
document.getElementById('toolBarPcFrame').style.display = ""; | |
} | |
else if (e.data == 'clearTop') | |
{ | |
document.getElementById('toolBarPcFrame').style.top = ''; | |
} | |
else if (e.data == 'reloadFrame') | |
{ | |
document.getElementById('toolBarPcFrame').style.backgroundColor = ''; | |
FULL_HEIGHT = false; | |
document.getElementById('toolBarPcFrame').src = document.getElementById('toolBarPcFrame').src; | |
} | |
else if (e.data == 'reloadFrameMobile') | |
{ | |
//Note: It is also used for tablet MX. | |
var iosVerNum = getIOSVersionNumber(); | |
if (iosVerNum >= 7) | |
{ | |
document.location.reload(); | |
FULL_HEIGHT = false; | |
} | |
else | |
{ | |
document.getElementById('toolBarPcFrame').style.backgroundColor = ''; | |
FULL_HEIGHT = false; | |
document.getElementById('toolBarPcFrame').style.display = "none"; | |
document.getElementById('toolBarPcFrame').src = document.getElementById('toolBarPcFrame').src; | |
} | |
} | |
else if (e.data == 'closeFrame') | |
{ | |
document.getElementById('toolBarPcFrame').style.width = '0'; | |
document.getElementById('toolBarPcFrame').style.height = '0'; | |
document.getElementById('toolBarPcFrame').src = 'about:blank'; | |
} | |
else if (e.data == 'ClearBackGroundPc') | |
{ | |
document.getElementById('toolBarPcFrame').style.backgroundColor = ''; | |
FULL_HEIGHT = false; | |
} | |
else if (e.data == 'mxUpdateReferrerDone') | |
{//__IOS7_SPECIFIC | |
gotUpdateReferrerDone = true; | |
} | |
else if (e.data == 'getPageContentRequest') | |
{ | |
var getPageContentResponse = new Array(); | |
getPageContentResponse[0] = 'getPageContentResponse'; | |
getPageContentResponse[1] = document.documentElement.outerHTML; | |
document.getElementById('toolBarPcFrame').contentWindow.postMessage(getPageContentResponse, 'http://toolbar.beeline.ru'); | |
} | |
else | |
{ | |
document.getElementById('toolBarPcFrame').style.width = e.data; | |
} | |
} | |
else | |
{ | |
//alert(e.origin); | |
throw new Error('Origin domain is not allowed.'); | |
} | |
} | |
// listen for the message event | |
window.addEventListener('message', msgHandler, false); | |
})(); | |
// window.onresize = resizeIframe; | |
function GetWidth() | |
{ | |
var x = 0; | |
if(self.innerWidth) | |
{ | |
x = self.innerWidth; | |
} | |
else if(document.documentElement && document.documentElement.clientWidth) | |
{ | |
x = document.documentElement.clientWidth; | |
} | |
else if(document.body) | |
{ | |
x = document.body.clientWidth; | |
} | |
return x; | |
} | |
function GetHeight() | |
{ | |
var y = 0; | |
if(self.innerHeight) | |
{ | |
y = self.innerHeight; | |
} | |
else if(document.documentElement && document.documentElement.clientHeight) | |
{ | |
y = document.documentElement.clientHeight; | |
} | |
else if(document.body) | |
{ | |
y = document.body.clientHeight; | |
} | |
return y; | |
} | |
function resizeIframe() | |
{ | |
/* | |
document.getElementById('toolBarPcFrame').contentWindow.postMessage('resize','http://toolbar.beeline.ru'); | |
document.getElementById('toolBarPcFrame').contentWindow.postMessage('resizeHeightTablet','http://toolbar.beeline.ru'); | |
*/ | |
if (isMobile()) | |
{ | |
ORIGINAL_WIDTH = 0; | |
if (StartZoom) | |
{ | |
orientation_changed('WindowResize'); | |
StartZoom = false; | |
} | |
//setTimeout('orientation_changed()', 300); | |
} | |
else | |
{ | |
document.getElementById('toolBarPcFrame').contentWindow.postMessage('resize', 'http://toolbar.beeline.ru'); | |
} | |
} | |
/* | |
window.onorientationchange = function() | |
{ | |
var parentWidth = new Array(); | |
parentWidth[0] = 'parentWidth'; | |
parentWidth[1] = window.innerWidth; | |
document.getElementById('toolBarPcFrame').contentWindow.postMessage(parentWidth,'http://toolbar.beeline.ru'); | |
}; | |
*/ | |
/*! Reloads on every visit in mobile safari */ | |
window.onpageshow = function(evt) | |
{ | |
var iosVerNum = getIOSVersionNumber(); | |
if (iosVerNum >= 7) | |
{ | |
//__IOS7_SPECIFIC BEGIN | |
var updateReferrerMessage = new Array(); | |
updateReferrerMessage[0] = 'mxUpdateReferrer'; | |
updateReferrerMessage[1] = document.location.href; | |
updateReferrerIntervalObj = window.setInterval(function() | |
{ | |
if ($('#toolBarPcFrame').width() == 0 && !gotUpdateReferrerDone && updateReferrerCounter < 300) | |
{ | |
document.getElementById('toolBarPcFrame').contentWindow.postMessage(updateReferrerMessage, 'http://toolbar.beeline.ru'); | |
updateReferrerCounter++; | |
} | |
else | |
{ | |
window.clearInterval(updateReferrerIntervalObj); | |
} | |
}, 200); | |
} //__IOS7_SPECIFIC END | |
else | |
{ | |
var firstTimeFlag = true; | |
if (evt.persisted) | |
{ | |
//document.body.style.display = "none"; | |
//location.reload(); | |
//document.getElementById('toolBarPcFrame').contentWindow.location.reload(); | |
document.getElementById('toolBarPcFrame').style.display = "none"; | |
document.getElementById('toolBarPcFrame').src = document.getElementById('toolBarPcFrame').src; | |
firstTimeFlag = false; | |
} | |
if (ORIGINAL_WIDTH == 320 && firstTimeFlag && isMobile()) | |
{ | |
setTimeout('onresize()', 500); | |
} | |
} | |
//etsAppMain functions (search application) | |
if (HideSearchAppIphone) | |
{ | |
HideSearchAppIphone(); | |
} | |
//window.scrollBy(0, 1); | |
//window.scrollBy(0, -1); | |
}; | |
window.onorientationchange = function() | |
{ | |
// Deals with the situation where the keyboard is opened, and the screen is being rotated. | |
// When the screen is being rotated and the keyboard is opened, the window's width and height | |
// haven't updated yet to the new width and height values of the screen after the rotation, to deal with | |
// this issue, a small timeout is needed for these values to get updated. | |
if (isMobile()) | |
{ | |
setTimeout('orientation_changed("WindowOrientation")', 300); | |
} | |
//etsAppMain functions (search application) | |
if (InitParamForScroll) | |
{ | |
InitParamForScroll(); | |
} | |
if (ToggleToolBarFromSearch) | |
{ | |
orientation_changed_etsAppsMain(); | |
ToggleToolBarFromSearch(); | |
} | |
}; | |
window.onload = function() | |
{ | |
//etsAppMain functions (search application) | |
if (InitParamForScroll) | |
{ | |
InitParamForScroll(); | |
} | |
}; | |
function isLandscape() | |
{ | |
var width = screen.width; | |
var height = screen.height; | |
var landscape = width > height; | |
return landscape; | |
} | |
function orientation_changed(actionId) | |
{ | |
var ToolbarHeightPercent; | |
var ToolbarAppBoxHeightPercent; | |
var landscapeTablet = true; | |
switch (window.orientation) | |
{ | |
case -90: | |
case 90: | |
ToolbarHeightPercent = ToolbarHeightHorizontalPercent; | |
ToolbarAppBoxHeightPercent = 0.95; | |
landscapeTablet = true; | |
break; | |
default: | |
ToolbarHeightPercent = ToolbarHeightVerticallPercent; | |
ToolbarAppBoxHeightPercent = 0.8; | |
landscapeTablet = false; | |
if (isLandscape()) | |
{ | |
ToolbarHeightPercent = ToolbarHeightHorizontalPercent; | |
ToolbarAppBoxHeightPercent = 0.8; | |
} | |
break; | |
} | |
// Getting the parent width and toolbar's height percent | |
var parentWidth = new Array(); | |
parentWidth[0] = 'parentWidth'; | |
if ("pc".toLowerCase() == "iPad".toLowerCase()) | |
{ | |
var viewportInfo = getVisualViewportInfo(); | |
parentWidth[1] = viewportInfo.width; | |
} | |
else | |
{ | |
parentWidth[1] = window.innerWidth; | |
} | |
if ("pc".toLowerCase() == "iPad".toLowerCase()) | |
{ | |
parentWidth[2] = landscapeTablet; | |
} | |
else | |
{ | |
parentWidth[2] = ToolbarHeightPercent; | |
} | |
parentWidth[3] = actionId; | |
document.getElementById('toolBarPcFrame').contentWindow.postMessage(parentWidth, 'http://toolbar.beeline.ru'); | |
// Getting the parent width and toolbar's percentage for the app box height | |
var parentHeight = new Array(); | |
parentHeight[0] = 'parentHeight'; | |
if ("pc".toLowerCase() == "iPad".toLowerCase()) | |
{ | |
parentHeight[1] = document.documentElement.clientHeight; | |
if (window.innerHeight > parentHeight[1]) | |
{ | |
parentHeight[1] = window.innerHeight; | |
} | |
} | |
else | |
{ | |
parentHeight[1] = document.documentElement.clientHeight; | |
if (window.innerHeight > parentHeight[1]) | |
{ | |
parentHeight[1] = window.innerHeight; | |
} | |
} | |
parentHeight[2] = ToolbarAppBoxHeightPercent; | |
if (navigator.userAgent.indexOf("Android") !== -1 && landscapeTablet) | |
{ | |
document.getElementById('toolBarPcFrame').style.top = ''; | |
document.getElementById('toolBarPcFrame').style.bottom = '0px'; | |
} | |
document.getElementById('toolBarPcFrame').contentWindow.postMessage(parentHeight, 'http://toolbar.beeline.ru'); | |
} | |
var startX, startY, endX, endY; | |
//only for mobile. it causes keyboard problem for tablet in some sites | |
if (isMobile()) | |
{ | |
document.addEventListener("touchstart", function(e) | |
{ | |
/*startX = e.touches[0].pageX; | |
startY = e.touches[0].pageY; | |
e.preventDefault();*///Stops the default behavior | |
}, false); | |
document.addEventListener("touchend", function(e) | |
{ | |
/*endX = e.touches[0].pageX; | |
endY = e.touches[0].pageY; | |
e.preventDefault();*///Stops the default behavior | |
StartZoom = true; | |
}, false); | |
} | |
} | |
function getIOSVersionNumber() | |
{ | |
try | |
{ | |
if (navigator.userAgent.indexOf("OS ") !== -1) | |
{ | |
var strStartingWithOS = navigator.userAgent.substring(navigator.userAgent.indexOf("OS ")); //OS x_y_z | |
var indexOfEndOfNum = strStartingWithOS.indexOf("_"); | |
var iosNumStr = strStartingWithOS.substring(2, indexOfEndOfNum); | |
} | |
else | |
{ | |
return -1; | |
} | |
return parseInt(iosNumStr); | |
} | |
catch(e) | |
{ | |
return -1; | |
} | |
} | |
function isIt(theDevice) | |
{ | |
return (theDevice != null && navigator.userAgent.toLowerCase().indexOf(theDevice.toLowerCase()) !== -1); | |
} | |
//not pc (tablet,mobile) | |
function isMobile(){ | |
return isIt("Mobile"); | |
} | |
function isIPhone() | |
{ | |
return isIt("iPhone"); | |
} | |
function isIPad() | |
{ | |
return isIt("iPad"); | |
} | |
function getBodyZoomLevel () { | |
var bodyStyle = window.getComputedStyle(document.body); | |
var bodyZoom = 1; | |
if (bodyStyle && bodyStyle.zoom) { | |
bodyZoom = bodyStyle.zoom; | |
if (isNumberPercentageBased(bodyZoom)) { | |
bodyZoom = parseFloat(bodyZoom) / 100; | |
} else if (!isNaN(parseFloat(bodyZoom))) { | |
bodyZoom = parseFloat(bodyZoom); | |
} | |
} | |
return bodyZoom; | |
}; | |
function isNumberPercentageBased(number) { | |
if (typeof number === "undefined" ) return false; | |
if (!isNaN(parseInt(number)) && (number.length >= 1) && number.substring(number.length - 1) === "%") { | |
return true; | |
} else { | |
return false; | |
} | |
} | |
function getVisualViewportInfo () { | |
// Most of the time body zoom level doesn't exist and returns 1. | |
// We need to take into consideration web pages that put a zoom level on the body | |
var bodyZoomLevel = getBodyZoomLevel(); | |
return { | |
width:window.innerWidth / bodyZoomLevel, | |
height:window.innerHeight / bodyZoomLevel | |
}; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment