rem ' BBjExecuteScriptEvent::getIndex
web = info(3,6)="5" or info(3,6)="6"
client = 0
if (!web) then
client = msgbox("BBjHtmlView Client",7+32+512,"BBjHtmlView","Swing","JavaFX","Chromium")
switch client
case 1; rem ' Swing
print stbl("!OPTIONS","CHROMIUM_HTMLVIEW=FALSE",ERR=*NEXT)
print stbl("!OPTIONS","JAVAFX_HTMLVIEW=FALSE",ERR=*NEXT)
break
case 2; rem ' JavaFX
print stbl("!OPTIONS","CHROMIUM_HTMLVIEW=FALSE",ERR=*NEXT)
print stbl("!OPTIONS","JAVAFX_HTMLVIEW=TRUE",ERR=*NEXT)
break
case 3; rem ' Chromium
print stbl("!OPTIONS","CHROMIUM_HTMLVIEW=TRUE",ERR=*NEXT)
print stbl("!OPTIONS","JAVAFX_HTMLVIEW=TRUE",ERR=*NEXT)
break
swend
endif
sysgui = unt
open (sysgui)"X0"
sysgui! = bbjapi().getSysGui()
window! = sysgui!.addWindow(50,50,300,400,"BBjExecuteScriptEvent::getScript",$00090003$)
window!.setCallback(window!.ON_CLOSE,"eoj")
gosub makehtml
htmlview! = window!.addHtmlView(101,25,25,250,150,html$)
htmlview!.setCallback(htmlview!.ON_PAGE_LOADED,"pageloaded")
if (web) then
htmlview!.injectScript("function doAlert() { console.log(alert('Alert dialog')); }",1)
htmlview!.injectScript("function doConfirm() { console.log(confirm('Confirm dialog')); }",1)
htmlview!.injectScript("function doPrompt() { console.log(prompt('Prompt dialog')); }",1)
endif
print "getClientType: ",htmlview!.getClientType(err=*next)
print "getClientVersion: ",htmlview!.getClientVersion(err=*next)
alert! = window!.addButton(102,25,200,250,25,"alert",$$)
alert!.setCallback(alert!.ON_BUTTON_PUSH,"alert")
confirm! = window!.addButton(103,25,250,250,25,"confirm",$$)
confirm!.setCallback(alert!.ON_BUTTON_PUSH,"confirm")
prompt! = window!.addButton(104,25,300,250,25,"prompt",$$)
prompt!.setCallback(prompt!.ON_BUTTON_PUSH,"prompt")
backgroundColor! = window!.addButton(105,25,350,250,25,"backgroundColor",$$)
backgroundColor!.setCallback(backgroundColor!.ON_BUTTON_PUSH,"backgroundColor")
process_events
eoj:
release
makehtml:
html$ = ""
html$ = html$ + "<!DOCTYPE html> <html> <body>"
html$ = html$ + "<br><button onclick='doAlert()'>Alert</button>"
html$ = html$ + "<br><button onclick='doConfirm()'>Confirm</button>"
html$ = html$ + "<br><button onclick='doPrompt()'>Prompt</button>"
html$ = html$ + "<script>"
html$ = html$ + "function doAlert() { console.log(alert('Alert dialog')); }"
html$ = html$ + "function doConfirm() { console.log(confirm('Confirm dialog')); }"
html$ = html$ + "function doPrompt() { console.log(prompt('Prompt dialog')); }"
html$ = html$ + "</script>"
html$ = html$ + "</body> </html>"
return
pageloaded:
htmlview!.setCallback(htmlview!.ON_EXECUTE_SCRIPT,"executeScript")
print sysgui!.getLastEvent().getEventName()
return
alert:
js$ = "alert('alert')"
gosub executeAsyncScript
return
confirm:
js$ = "confirm('confirm')"
gosub executeAsyncScript
return
prompt:
js$ = "prompt('prompt')"
gosub executeAsyncScript
return
executeScript:
event! = sysgui!.getLastEvent()
index = 0, index = event!.getIndex(err=*next)
msg$ = event!.getEventName()+" "+str(index)+" "+date(0:"%Hz:%mz:%sz.%tz %p")+$0a$
msg$ = msg$ + event!.getScript()+": "
result! = event!.getResult()
if (result! = null()) then
msg$ = msg$ + "null"
else
msg$ = msg$ + result!.getClass().getName() + " = " + result!.toString()
endif
print msg$
i = msgbox(msg$)
return
backgroundColor:
r = rnd(255)
g = rnd(255)
b = rnd(255)
rgb$ = "#"+hta(chr(r))+hta(chr(g))+hta(chr(b))
js$ = "document.body.style.backgroundColor = """+rgb$+""""
if web then js$ = "style.backgroundColor = """+rgb$+""""
gosub executeAsyncScript
return
executeAsyncScript:
index! = htmlview!.executeAsyncScript(js$)
print "executeAsyncScript ",index!," ",date(0:"%Hz:%mz:%sz.%tz %p")," ",js$
return
|