var MyTitleWidth=0;
var MyTitleHeight=0;
var scaleFill = 0;
if( navigator.userAgent.match(/iPhone/i)
|| navigator.userAgent.match(/iPad/i)
|| navigator.userAgent.match(/iPod/i)
|| !/Mobile/i.test(navigator.userAgent)) {
var viewPortTag=document.createElement('meta');
viewPortTag.id="viewport";
viewPortTag.name = "viewport";
viewPortTag.content = "width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0";
document.getElementsByTagName('head')[0].appendChild(viewPortTag);
}
var xStart, yStart = 0;
var doubleTouchStartTimestamp = 0;
document.addEventListener('touchstart',function(e) {
if( navigator.userAgent.match(/iPhone/i)
|| navigator.userAgent.match(/iPad/i)
|| navigator.userAgent.match(/iPod/i) ) {
xStart = e.touches[0].screenX;
yStart = e.touches[0].screenY;
var now = +(new Date());
if (doubleTouchStartTimestamp + 500 > now) {
event.preventDefault();
}
doubleTouchStartTimestamp = now;
}
});
document.addEventListener('touchmove',function(e) {
if( navigator.userAgent.match(/iPhone/i)
|| navigator.userAgent.match(/iPad/i)
|| navigator.userAgent.match(/iPod/i)) {
var xMovement = Math.abs(e.touches[0].screenX - xStart);
var yMovement = Math.abs(e.touches[0].screenY - yStart);
if((yMovement * 3) > xMovement) {
e.preventDefault();
}
}
});
function sleep(milliseconds) {
var start = new Date().getTime();
for (var i = 0; i < 1e7; i++) {
if ((new Date().getTime() - start) > milliseconds){
break;
}
}
}
window.top.addEventListener("orientationchange", function() {
if( navigator.userAgent.match(/Android/i)) {
document.activeElement.blur();
sleep(2000);
}
ReFlow();
//windows.location.reload();
//window.location.href=window.location.href;
//window.location.reload(true);
}, false);
function ReFlow() {
findWH();
if (pageLayer){
var dv = document.getElementById("pageDIV");
if(MyTitleWidth==0){
MyTitleWidth=parseInt(dv.clientWidth);
MyTitleHeight=parseInt(dv.clientHeight);
}
//if (scaleFill == 0) {
var scale1 = winW/MyTitleWidth;
var scale2 = winH/MyTitleHeight;
scaleFill = Math.min( scale1,scale2);
//}
pageLayer.moveTo((winW-(scaleFill*MyTitleWidth))/2, 0);
pageLayer.hasMoved = true;
pageLayer.newX = (winW-(scaleFill*MyTitleWidth))/2;
pageLayer.newY = 0;
var transX = -parseInt((MyTitleWidth-(scaleFill*MyTitleWidth))/2);
var transY = -parseInt((MyTitleHeight-(scaleFill*MyTitleHeight))/2);
var sty = "translate("+transX+"px, "+transY+"px) scale(" + scaleFill + ")";;
dv.style.transform = sty;
dv.style.MozTransform = sty;
dv.style.msTransform = sty;
dv.style.OTransform = sty;
dv.style.webkitTransform = sty;
dv.style.overflow = "hidden";
}
}
function findWH(){
if( navigator.userAgent.match(/Android/i)
|| navigator.userAgent.match(/iPhone/i)
|| navigator.userAgent.match(/iPad/i)
|| navigator.userAgent.match(/iPod/i)
){
winW = window.top.innerWidth-1;
winH = window.top.innerHeight-1;
//winH = document.height;
//winW = document.width;
} else {
winW = Math.max(document.documentElement.clientWidth, window.innerWidth || 0) - 1;
winH = Math.max(document.documentElement.clientHeight, window.innerHeight || 0) - 1;
}
if (winW < 640) winW = 640;
if (winH < 480) winH = 480;
}
function DragItemWithin( x,y ) {
x -= pageLayer.x;
y -= pageLayer.y;
if( x >= (this.lyr.objLyr.x*scaleFill) &&
y >= (this.lyr.objLyr.y*scaleFill) &&
x <= ((this.lyr.objLyr.x + this.lyr.objLyr.w)*scaleFill) &&
y <= ((this.lyr.objLyr.y + this.lyr.objLyr.h)*scaleFill) )
return true;
else
return false;
}
if(typeof dragMgr !== 'undefined'){
dragMgr.mouseDown = function(x,y,e) {
for (var i=this.arrDragItems.length-1;i>=0;i--)
{
var dItem = this.arrDragItems[i]
if (dItem.checkWithinItem(x,y))
{
var targ;
if (!e) var e = window.event;
if (e.target) targ = e.target;
else if (e.srcElement) targ = e.srcElement;
while( targ &&
( !targ.id || targ.id.indexOf( dItem.name ) == -1 ) &&
( !targ.name || targ.name.indexOf( dItem.name ) == -1 ) )
{
targ = targ.parentNode
}
if( !targ )
return false;
if( targ.disabled )
return false;
this.item = dItem
this.offX = (x/scaleFill)-this.item.lyr.objLyr.x;
this.offY = (y/scaleFill)-this.item.lyr.objLyr.y;
if( this.item.lyr.dropObj )
{
this.item.lyr.dropObj.dragItem = null
this.item.lyr.dropObj = null
this.onDragDrop() // Clear
}
this.active = true
break
}
}
if (!this.active) return false
else return true
}
dragMgr.mouseMove = function(x,y) {
if (!this.active) return false
else
{
this.item.lyr.objLyr.moveTo((x/scaleFill)-this.offX,(y/scaleFill)-this.offY);
return true
}
}
}