const qactive="#cccccc", qinactive="#333333", qneutral="#999999" // colours for tabs
var qbuts = [], qlays = [], qcurrent=0
var qwebs=[], qtxts=[], qcnt=-1
function OnStart() {
app.SetOrientation("landscape")
app.EnableBackKey(false)
lay = app.CreateLayout( "Linear", "Vertical,FillXY,Left" )
// scroller for tab buttons
scroll = app.CreateScroller(1,-1,"Horizontal")
lay.AddChild(scroll)
horiz1 = app.CreateLayout( "Linear","Horizontal,Left" )
lay.SetBackGradient( "green", "blue", "red", "left-right" )
scroll.AddChild(horiz1)
// load saved tabs (if any)
temp = app.LoadText("temp","")
if (temp == "") {
newtab()
} else {
urls = JSON.parse(temp)
urls.forEach(function (current) {newtab(current);} )
}
qbuts[0].GetParent().SetBackColor(qactive)
qbuts[0].SetTextColor(qactive)
qlays[0].Show()
app.AddLayout( lay )
}
// new tab
function newtab (url) {
qcnt+=1
but4=qaddbut(horiz1,"Tab "+qcnt,qcnt)
tab4=qaddlay(lay,qcnt)
horiz2 = app.AddLayout(tab4,"linear","horizontal")
// create controls and add to layout
back = app.AddButton(horiz2," [fa-backward]", -1, 0.09, "custom,fontawesome");
back.SetStyle("#cccccc", "#333333", 14, "#999999", 1, 0);
back.SetTextColor("#bada55")
back.SetOnTouch(function() {qwebs[qcurrent].Back();})
txt = app.AddTextEdit(horiz2,url,0.6,-1,"SingleLine")
qtxts[qcnt]=txt
txt.SetOnEnter(function () {qwebs[qcurrent].LoadUrl(this.GetText());})
forward = app.AddButton(horiz2,"[fa-forward]", -1, 0.09, "custom,fontawesome");
forward.SetStyle("#cccccc", "#333333", 14, "#999999", 1, 0);
forward.SetTextColor("#bada55")
forward.SetOnTouch(function () {qwebs[qcurrent].Forward();})
btnInfo = app.CreateButton("[fa-info]", -1, 0.09, "custom,fontawesome");
btnInfo.SetStyle("#cccccc", "#333333", 14, "#999999", 1, 0);
btnInfo.SetTextColor("#bada55");
btnInfo.SetTextSize(24);
btnInfo.SetOnTouch(btnInfo_OnTouch);
horiz2.AddChild(btnInfo);
tab = app.AddButton(horiz2,"[fa-plus]", -1, 0.05, "custom,fontawesome");
tab.SetStyle("#cccccc", "#333333", 14, "#999999", 1, 0);
tab.SetTextColor("#bada55")
tab.SetOnTouch( newtab)
close = app.AddButton( horiz2,"[fa-minus]", -1, 0.05, "custom,fontawesome");
close.SetStyle("#cccccc", "#333333", 14, "#999999", 1, 0);
close.SetTextColor("#bada55")
close.SetOnTouch(function() {qbuts[qcurrent].Hide();qwebs[qcurrent].Hide();})
web = app.AddWebView(tab4,1,0.9)
web.SetOnError(function(msg) {alert(msg);})
web.SetOnUrl(function (url) {progress(100);this.LoadUrl(url);})
web.SetOnProgress(progress)
web.LoadUrl( url )
qwebs[qcnt] = web
app.SimulateTouch(but4,0,0,"Down")
}
function qaddbut(qlay,qtxt,qidx) {
var v = app.AddLayout(qlay,"Linear","Touchthru")
v.Batch({
SetBackColor_: [qinactive],
SetPadding_: [0,0,0,5,"px"]
})
var q = app.CreateText(qtxt )
v.AddChild(q)
q.Batch({
SetBackColor_: [qinactive],
SetTextColor: [ qneutral ],
SetPadding_: [20,20,20,20,"px"],
SetOnTouchDown: [q_OnTouch]
})
q.data.qidx = qidx
ign = qbuts.push(q)
return q
}
function qaddlay(qlay,qidx) {
var q = app.AddLayout(qlay,"Linear", "FillXY")
q.Gone()
ign = qlays.push(q)
return q
}
function q_OnTouch () {
var qidx = this.data.qidx
if (qidx!=qcurrent) {
qbuts[qcurrent].SetTextColor(qneutral)
qbuts[qcurrent].GetParent().SetBackColor(qinactive)
qbuts[qidx].SetTextColor(qactive)
qbuts[qidx].GetParent().SetBackColor(qactive)
qlays[qcurrent].Gone()
qlays[qidx].Show()
qcurrent=qidx
}
}
function progress (percent) {
if (percent == 100) {
qbuts[qcurrent].SetText(qwebs[qcurrent].GetUrl());
qwebs[qcurrent].Execute("document.title",function (result) {qbuts[qcurrent].SetText(result);}) // show title in tab
qtxts[qcurrent].SetText(qwebs[qcurrent].GetUrl());
qwebs[qcnt].Execute("document.title",function (result) {qbuts[qcnt].SetText(result);}) // show title in tab
qtxts[qcnt].SetText(qwebs[qcnt].GetUrl());
}
}
// Create dialog
function btnDlg_OnTouch() {
dlg.Dismiss();
}
function btnInfo_OnTouch() {
dlg = app.CreateDialog("Infos", 0.8, 0.4 );
layDlg = app.CreateLayout("linear", "VCenter,FillXY");
layDlg.SetSize(0.7, 0.39);
dlg.AddLayout(layDlg);
var text = "<p>tmBrowser</p>" +
"<p>Version: 1.0</p>";
txt = app.CreateText( text, 1., -1, "Html,Link" );
txt.SetMargins( 0, 0.02, 0, 0 );
txt.SetPadding( 0.03, 0.03, 0.03, 0.03 );
txt.SetTextSize( 14 );
layDlg.AddChild( txt );
dlg.Show();
}
function OnConfig(){
horiz1.SetOrientation("landscape")
}
function OnBack() {
urls=[]
qwebs.forEach (function (current,idx) {
if (current.GetVisibility() == "Show") ign=urls.push(current.GetUrl());
})
temp = JSON.stringify(urls)
app.SaveText("temp",temp)
app.Exit()