var LiveGap =(typeof LiveGap =="undefined") ? {} : LiveGap;
LiveGap.System=(typeof LiveGap.System =="undefined") ? {Id:"LiveGap OS"} : LiveGap.System;
LiveGap.System.Version='0.0.0.1';
LiveGap.System.Domain='editor.livegap.com';
LiveGap.System.Http='https';
//------------------------System Log
// Define The log object.
function Gap_Log(MyObject,MyEvent,Description)
{
this.MyObject=MyObject;
this.MyEvent=MyEvent;
this.Description=Description;
this.Element="Log";
this.CalTime=function () {return new Date()};
this.Time=this.CalTime();
this.CalLife=function ()
{
//try{y=this.Time.getTime()-(LiveGap.Log[0].Time.getTime())}
//catch(err){y=0}
y=0
return y
};
this.Life=this.CalLife();
}
//Update The log File
function Gap_log_Update()
{ TheLogfile= "";
GLNumber = ((Number($("span#GapLogNumber").text())));
for (i in LiveGap.Log)
{ if (i>=GLNumber)
{
TheLogfile+=GapConvertTime(LiveGap.Log[i].Life)+" "+LiveGap.Log[i].MyObject+" - "+LiveGap.Log[i].MyObject.Id+":"+LiveGap.Log[i].MyEvent+"
"
$("span#GapLogNumber").text(Number(i)+1);
}
}
$("div#GAPLog").append(TheLogfile);
}
function GapConvertTime(MilliSecondTime)
{
Millisecond =(MilliSecondTime)%1000;
TotalinSecond=(MilliSecondTime-Millisecond)/1000;
Seconds=(TotalinSecond)%60;
Totalinminute=(TotalinSecond-Seconds)/60;
Minutes=(Totalinminute)%60;
TotalinHour=(Totalinminute-Minutes)/60;
Hour=(TotalinHour)%24;
//for dislay 00 before number less than 10 or 100
DMillisecond=""
if(Millisecond<10){DMillisecond+="0"};
if(Millisecond<100){DMillisecond+="0"};
DMillisecond+=Millisecond;
DSeconds=""
if(Seconds<10){DSeconds+="0"};
DSeconds+=Seconds;
DMinutes=""
if(Minutes<10){DMinutes+="0"};
DMinutes+=Minutes;
DHour=""
if(Hour<10){DHour+="0"};
DHour+=Hour;
All=DHour+":"+DMinutes+":"+DSeconds+":"+DMillisecond;
return All;
}
// Create the log File
function Gap_log_Create()
{
if(GAP_CheckFiles())
{
$(document.body).append("0
");
Gap_log_Update()
$("div#GAPLog").dialog({autoOpen: false,title: 'Log File',width: 500,height: 300})
//Create the Shortcut Keyboard for the LOG
/*
$(document).keypress(function(e){
if (e.which == 126 || e.keyCode == 126 || window.event.keyCode == 126)
{$("div#GAPLog").dialog( "open" ).show('drop') };
});
*/
//----------------------------------------
}
}
//Start The Log System Or Reloaded
if(typeof LiveGap.Log !="undefined")
{
LiveGap.Log.push(new Gap_Log(LiveGap.System,"Reload","LiveGap is reloaded again"));
Gap_log_Update();
};
if(typeof LiveGap.Log =="undefined")
{
LiveGap.Log=[new Gap_Log(LiveGap.System,"Start","LiveGap is Starting")]
};
//------------------------files
// Define The file object.
function Gap_Files(URL,Type,Id,Group)
{
this.Id=Id;
this.URL=URL;
this.Type=Type;
this.Element="File";
this.Group=Group;
this.Isloaded=(typeof this.Isloaded =="undefined") ? false : true;
this.IsAdded=(typeof this.IsAdded =="undefined") ? false : true;
this.AddFile=GapAddFile;
this.GAP_OnLoad=GAP_Events;
}
function Gap_GroupOfFiles(Id)
{
this.Id=Id;
this.Element="GroupOfFile";
this.Files=new Array();
for (Gap_File in LiveGap.Files) {
if(LiveGap.Files[Gap_File].Group==Id ){this.Files.push(LiveGap.Files[Gap_File])}
}
this.AddFiles=GapAddGroupOfFile;
}
//----- Add The File to The Page
function GapAddFile()
{
if(!this.IsAdded)
{
this.IsAdded=true;
var GL_Object=this;
var headID = document.getElementsByTagName("head")[0];
LiveGap.Log.push(new Gap_Log(this,"Loading","------" ));
// For Not duplicate
if (this.Type=="Script" )
{
var newScript = document.createElement("script");
newScript.type = "text/javascript";
newScript.src =this.URL;
headID.appendChild(newScript);
newScript.onreadystatechange= function () {if ((this.readyState === "loaded" || this.readyState === "complete") && GL_Object.Isloaded==false) {GL_Object.Isloaded=true;GL_Object.GAP_OnLoad("Complete")}};
newScript.onload= function(){if (GL_Object.Isloaded==false){GL_Object.Isloaded=true;GL_Object.GAP_OnLoad("Complete")};
}}
if (this.Type=="CSS")
{
var cssNode = document.createElement("link");
cssNode.type = "text/css";
cssNode.rel = "stylesheet";
cssNode.href = this.URL;
cssNode.media = "screen";
headID.appendChild(cssNode);
var Html = document.getElementsByTagName('html')[0];
var CssImg = document.createElement('img');
CssImg.style.display="none";
CssImg.onerror = function(){GL_Object.Isloaded=true;GL_Object.GAP_OnLoad("Complete");document.body.removeChild(CssImg);}
CssImg.src = GL_Object.URL;
document.body.appendChild(CssImg);
}
if (this.Type=="Images")
{
var Html = document.getElementsByTagName('html')[0];
var Gap_Img = document.createElement('img');
Gap_Img.src = GL_Object.URL;
Gap_Img.style.display="none";
Gap_Img.onload = function(){GL_Object.Isloaded=true;GL_Object.GAP_OnLoad("Complete");document.body.removeChild(Gap_Img);}
document.body.appendChild(Gap_Img);
}
}
}
//Chech if All Files is loaded.
function GAP_CheckFiles(Group)
{
if(Group !=undefined){
for (Gap_File in LiveGap.Files) {
if(!LiveGap.Files[Gap_File].Isloaded && LiveGap.Files[Gap_File].Group==Group.Id ){return false}
}
LiveGap.Log.push(new Gap_Log(Group,"Complete","finish loading Groups of Files" ));
return true;
}
if(Group ==undefined)
{
for (Gap_File in LiveGap.Files) {
if(!LiveGap.Files[Gap_File].Isloaded){return false}
}
return true;
}
}
//--------------------------------------
// Load a group of files
function GapAddGroupOfFile()
{
LiveGap.LoadingGroup=this.Id;
LiveGap.Log.push(new Gap_Log(this,"Add Group Of files ","------" ));
for (Gap_File in LiveGap.Files) {
// check if fancybox is loaded before in this page not duplicated it
/*
if(LiveGap.Files[Gap_File]==LiveGap.Files.FancyBox && LiveGap.Files[Gap_File].Group==this.Id)
{
alert("fancyBox is Checked:"+LiveGap.Files[Gap_File].Id);
if(typeof $.fancybox == 'function')
{
alert("fancyBox is loaded before");
LiveGap.Files[Gap_File].IsAdded=true;
LiveGap.Files[Gap_File].IsLoaded=true;
}
};
*/
//---------------------------------------------------------------------
if(!LiveGap.Files[Gap_File].IsAdded && LiveGap.Files[Gap_File].Group==this.Id ){LiveGap.Files[Gap_File].AddFile();}
}
}
function GAP_CheckGroupsOfFiles()
{
if(LiveGap.LoadingGroup==LiveGap.groupsOfFiles[LiveGap.groupsOfFiles.length-1].Id && GAP_CheckFiles(LiveGap.groupsOfFiles[LiveGap.groupsOfFiles.length-1])){Gap_Login();}
for(i=LiveGap.groupsOfFiles.length-2;i>=0;i--)
{if(LiveGap.LoadingGroup==LiveGap.groupsOfFiles[i].Id && GAP_CheckFiles(LiveGap.groupsOfFiles[i])){LiveGap.LoadingGroup=LiveGap.groupsOfFiles[i+1].Id;LiveGap.groupsOfFiles[i+1].AddFiles();}}
}
function GAP_Events_Files(GAP_File,MyEvent)
{
if( MyEvent=="Complete"){
if(GAP_File.Isloaded ){LiveGap.Log.push(new Gap_Log(GAP_File,MyEvent,"-------" ));}
//Check The loading image is loaded or still not.
if(GAP_File.Isloaded && GAP_File.Id=="LoadingSite" && GAP_File.Type=="Images")
{
if((document.domain) && document.domain.indexOf("livegap.")==-1)
{
// add the image
var Html = document.getElementsByTagName('html')[0];
var Gap_Img = document.createElement('img');
Gap_Img.src = LiveGap.Files.loading.URL;
Gap_Img.id="LoadingLogoImage";
Gap_Img.style.display="block";
Gap_Img.style.position="absolute";
Gap_Img.style.left="10%";
Gap_Img.style.top="10%";
//Gap_Img.style.zIndex="99999999";
document.body.appendChild(Gap_Img);
} }
}
}
RightPanelVisible=true;
var mainContainerWidth;
function hideRightPanel()
{
RightPanelVisible=false;
mainContainerWidth=$('#MainContainer').width();
$('#RightContainer').hide();
$('#MainContainerButton').show();
$('#MainContainer .ui-resizable-handle.ui-resizable-e').hide();
$('#MainContainer .ui-resizable-handle.ui-resizable-se').hide();
$('#MaxLimits').css('width','100%');
$('#MainContainer').css('width','100%');
}
function showRightPanel()
{
RightPanelVisible=true;
$('#RightContainer').show();
$('#MainContainerButton').hide();
$('#MainContainer .ui-resizable-handle.ui-resizable-e').show();
$('#MainContainer .ui-resizable-handle.ui-resizable-se').show();
$('#MaxLimits').css('width','80%');
console.log(mainContainerWidth);
$('#MainContainer').css('width',mainContainerWidth);
$('#RightContainer').width($('#ParentContainer').width()-$('#MainContainer').width());
if($('#RightContainer').width()<300){$('#RightContainer').width(300);$('#MainContainer').width($('#ParentContainer').width()-$('#RightContainer').width());}
CSSToPercent(['#MainContainer','#RightContainer','#BottomContainer'],['height','width']);
ResizePage();
}
function Gap_Login()
{
console.log("login")
document.body.innerHTML=HtmlEditor;
$( ".resizable" ).resizable({
containment: "#MaxLimits",
resize:function(event, ui)
{
$('#BottomContainer').height($('#ParentContainer').height()-$('#MainContainer').height());
$('#RightContainer').height($('#MainContainer').height());
if(RightPanelVisible==true){
$('#RightContainer').width($('#ParentContainer').width()-$('#MainContainer').width());
}
},
handles:"e, s, se",
start:function(event, ui){FixIframeStart()},
stop:function(event, ui)
{
FixIframeStop();
CSSToPercent(['#MainContainer','#RightContainer','#BottomContainer'],['height','width']);
ContainerHeightPadding=($('#ParentContainer').height()-$('#MainContainer').height()-$('#BottomContainer').height())/2;
ContainerWidthPadding=($('#ParentContainer').width()-$('#MainContainer').width()-$('#RightContainer').width())/2;
$('#MainContainer').css('padding-left',ContainerWidthPadding+"px");
$('#MainContainer').css('padding-top',ContainerHeightPadding+"px");
$('#RightContainer').css('padding-right',ContainerWidthPadding+"px");
$('#RightContainer').css('padding-top',ContainerHeightPadding+"px");
$('#BottomContainer').css('padding-bottom',ContainerHeightPadding+"px");
ResizePage();
}
});
$( "#MainTabs" ).tabs();
$( "#BottomTabs" ).tabs();
$( "#RightTabs" ).tabs();
ResizePage();
//MainDocument=new GapFile("Sample.html","text/html","index").add();
hideRightPanel();
MainFile=new GapFile(location.href,"text/html","index").add();
} FileDataDom="";
if(location.protocol=="file:"){FileDataDom=document.getElementsByTagName('html')[0].innerHTML;WelcomePage=false; }
if(typeof LiveGap.Files =="undefined") {
LiveGap.Files = {
JqueryUITheme:new Gap_Files(LiveGap.System.Http+"://"+LiveGap.System.Domain+"/css/themes/base/jquery-ui.min.css","CSS","JqueryUITheme","MainFile"),
MainCSS:new Gap_Files(LiveGap.System.Http+"://"+LiveGap.System.Domain+"/css/main.css","CSS","MainCSS","MainFile"),
CodeMirrorCSS:new Gap_Files(LiveGap.System.Http+"://"+LiveGap.System.Domain+"/css/codemirror.css","CSS","CodeMirrorCSS","MainFile"),
Jquery:new Gap_Files("https://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js","Script","Jquery","MainFile"),
HtmlEDitor:new Gap_Files(LiveGap.System.Http+"://"+LiveGap.System.Domain+"/js/HtmlEditor.js","Script","HtmlEDitor","MainFile2"),
CodemirrorJs:new Gap_Files(LiveGap.System.Http+"://"+LiveGap.System.Domain+"/js/codemirror-compressed.js?ab","Script","MirrorCodeJs","MainFile2"),
JqueryUI:new Gap_Files("https://ajax.googleapis.com/ajax/libs/jqueryui/1.10.3/jquery-ui.min.js","Script","JqueryUI","MainFile2"),
MainJs:new Gap_Files(LiveGap.System.Http+"://"+LiveGap.System.Domain+"/js/main.js","Script","MainJs","MainFile3"),
}
if(typeof FileId !== 'undefined')
{
LiveGap.Files["FileData"]=new Gap_Files(LiveGap.System.Http+"://"+LiveGap.System.Domain+"/js/file.php?fid="+FileId,"Script","FileData","MainFile2");
}
if(typeof FileId !== 'undefined' && typeof FileTemplate !== 'undefined')
{
LiveGap.Files["FileData"]=new Gap_Files(LiveGap.System.Http+"://"+LiveGap.System.Domain+"/js/file.php?fid="+FileId+"&tid="+FileTemplate,"Script","FileData","MainFile2");
}
if(typeof FileTemplate !== 'undefined' && typeof FileId === 'undefined')
{
LiveGap.Files["FileData"]=new Gap_Files(LiveGap.System.Http+"://"+LiveGap.System.Domain+"/js/file.php?fid="+FileTemplate,"Script","FileData","MainFile2");
}
LiveGap.groupsOfFiles=[new Gap_GroupOfFiles("MainFile"),new Gap_GroupOfFiles("MainFile2"),new Gap_GroupOfFiles("MainFile3")];
LiveGap.groupsOfFiles[0].AddFiles();
} ;
function GAP_Events(MyEvent)
{
if(this.Element="File"){GAP_Events_Files(this,MyEvent);}
GAP_CheckGroupsOfFiles();
Gap_log_Create();
}
// if Page is loaded Before
if (GAP_CheckFiles()){Gap_Login()};