diff --git a/CHANGELOG.md b/CHANGELOG.md index 09eb34ff..5193c538 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,8 @@ - custom module - expose `process` global +- scripting + - add `openUrl` function ## 1.8.10 diff --git a/package.json b/package.json index b4ccad68..c8255e61 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "name": "open-stage-control", "productName": "Open Stage Control", "description": "Libre and modular OSC / MIDI controller", - "version": "1.8.10", + "version": "1.8.11", "author": { "name": "Jean-Emmanuel Doucet", "email": "jean-emmanuel@ammd.net" diff --git a/resources/docs/docs/widgets/scripting.md b/resources/docs/docs/widgets/scripting.md index 0f44424a..f2c7ce42 100644 --- a/resources/docs/docs/widgets/scripting.md +++ b/resources/docs/docs/widgets/scripting.md @@ -161,7 +161,7 @@ Reference: #### `clearTimeout(id)` / `clearInterval(id)` -Clear timeout with matching `id`. +Clears timeout with matching `id`. Reference: @@ -174,7 +174,7 @@ Reference: - `id` (optional): widget `id` as a string -Give focus to a widget (ie input widget). +Gives focus to a widget (ie input widget). *Built-in client only*: tells the operating system to give the focus to the client window @@ -205,7 +205,7 @@ Sets the scroll state of a container. #### `toolbar(i1, i2, ...)` - `iX`: menu entry index -Trigger toolbar action at specified index. +Triggers toolbar action at specified index. !!! example "Examples" @@ -213,3 +213,12 @@ Trigger toolbar action at specified index. - `toolbar(3)` -> Toggle full screen Actions will only be triggered if initiated with a user interaction. Fullscreen cannot be toggled with a simulated interaction (i.e. using `/SET`) + + +#### `openUrl(url)` +- `url`: http(s) url + +*Built-in client only*: opens url with the system's default browser +*External client only*: opens url in a new tab + +If the event that triggered the script's execution was not initiated by a user interaction, this function will have no effect. diff --git a/src/client/widgets/scripts/script-vm.js b/src/client/widgets/scripts/script-vm.js index 007a9b22..99c66890 100644 --- a/src/client/widgets/scripts/script-vm.js +++ b/src/client/widgets/scripts/script-vm.js @@ -373,8 +373,17 @@ class ScriptVm extends Vm { } + this.sandbox.contentWindow.openUrl = (url)=>{ + + var options = this.getValueOptions() + + if (options.send) window.open(url, '_blank') + + } + for (var imports of ['set', 'get', 'getProp', 'getIndex', 'updateProp', 'send', 'httpGet', 'stateGet', 'stateSet', 'storage', - 'setInterval', 'clearInterval', 'setTimeout', 'clearTimeout', 'setFocus', 'unfocus', 'setScroll', 'getScroll', 'toolbar']) { + 'setInterval', 'clearInterval', 'setTimeout', 'clearTimeout', 'setFocus', 'unfocus', 'setScroll', 'getScroll', 'toolbar', + 'openUrl']) { this.sanitize(this.sandbox.contentWindow[imports]) }