From 45beeaa8d5a854a3b2efde293f8d2ede5da2610f Mon Sep 17 00:00:00 2001 From: Ryan Huffman Date: Wed, 30 Apr 2014 09:45:53 -0700 Subject: [PATCH] Add dialog + location + window JS examples --- examples/dialogExample.js | 7 +++++++ examples/locationExample.js | 11 +++++++++++ examples/windowExample.js | 12 ++++++++++++ 3 files changed, 30 insertions(+) create mode 100644 examples/dialogExample.js create mode 100644 examples/locationExample.js create mode 100644 examples/windowExample.js diff --git a/examples/dialogExample.js b/examples/dialogExample.js new file mode 100644 index 0000000000..144b681950 --- /dev/null +++ b/examples/dialogExample.js @@ -0,0 +1,7 @@ +Window.alert("This is an alert box"); + +var confirmed = Window.confirm("This is a confirmation dialog") +Window.alert("Your response was: " + confirmed); + +var prompt = Window.prompt("This is a prompt dialog", "This is the default text"); +Window.alert("Your response was: " + prompt); diff --git a/examples/locationExample.js b/examples/locationExample.js new file mode 100644 index 0000000000..7530a3e3b6 --- /dev/null +++ b/examples/locationExample.js @@ -0,0 +1,11 @@ +var goto = Window.prompt("Where would you like to go? (ex. @username, #location, 1.0,500.3,100.2)"); +var url = "hifi://" + goto; +print("Going to: " + url); +location = url; + +// If the destination location is a user or named location the new location may not be set by the time execution reaches here +// because it requires an asynchronous lookup. Coordinate changes should be be reflected immediately, though. (ex: hifi://0,0,0) +print("URL: " + location.href); +print("Protocol: " + location.protocol); +print("Hostname: " + location.hostname); +print("Pathname: " + location.pathname); diff --git a/examples/windowExample.js b/examples/windowExample.js new file mode 100644 index 0000000000..afde83591d --- /dev/null +++ b/examples/windowExample.js @@ -0,0 +1,12 @@ +var width = 0, + height = 0; + +function onUpdate(dt) { + if (width != Window.innerWidth || height != Window.innerHeight) { + width = Window.innerWidth; + height = Window.innerHeight; + print("New window dimensions: " + width + ", " + height); + } +} + +Script.update.connect(onUpdate);