diff --git a/CHANGELOG.md b/CHANGELOG.md
index 4783e766..f6ba17cb 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -10,6 +10,7 @@
- widgets
- input: allow using a number in `numeric` to specify stepping value for mousewheel interaction
+ - root: add `onPreload` scripting property
## 1.25.6
diff --git a/resources/docs/docs/widgets/scripting.md b/resources/docs/docs/widgets/scripting.md
index 843a4641..5c9fea44 100644
--- a/resources/docs/docs/widgets/scripting.md
+++ b/resources/docs/docs/widgets/scripting.md
@@ -103,6 +103,10 @@ The following variables are available in this context:
- `meta` (`boolean`): `true` if meta key is pressed
+### `onPreload`
+
+This script is specific to the root widget, it's called before any other widget is created and can be used to create global variables / functions accessible in other scripts.
+
## Available variables
The following variables and functions are accessible in this context.
diff --git a/src/client/widgets/common/widget.js b/src/client/widgets/common/widget.js
index eff09c00..fa131940 100644
--- a/src/client/widgets/common/widget.js
+++ b/src/client/widgets/common/widget.js
@@ -142,7 +142,7 @@ class Widget extends EventEmitter {
bypass: {type: 'boolean', value: false, help: 'Set to `true` to prevent the widget from sending any osc message'}
},
scripting: {
- onCreate: {type: 'script', value: '', editor: 'javascript', help: ['Script executed when the widget is created. See documentation.']},
+ onCreate: {type: 'script', value: '', editor: 'javascript', help: ['Script executed when the widget (and its children) is created. See documentation.']},
onValue: {type: 'script', value: '', editor: 'javascript', help: ['Script executed when the widget\'s value updates. See documentation.']},
}
}
diff --git a/src/client/widgets/containers/panel.js b/src/client/widgets/containers/panel.js
index d0ef778d..ecfe2e3d 100644
--- a/src/client/widgets/containers/panel.js
+++ b/src/client/widgets/containers/panel.js
@@ -6,6 +6,7 @@ var Container = require('../common/container'),
setScrollbarColor = require('../../ui/scrollbar-color'),
iOS13 = require('../../ui/ios') === 13,
Fader = require('../sliders/fader'), faderDefaults,
+ Script = require('../scripts/script'),
resize = require('../../events/resize'),
fastdom = require('fastdom')
@@ -56,6 +57,16 @@ class Panel extends Container() {
this.childrenType = ''
+ if (options.root && this.getProp('onPreload')) {
+ this.scripts.onPreload = new Script({
+ widget: this,
+ property: 'onPreload',
+ code: this.getProp('onPreload'),
+ context: {}
+ })
+ if (this.scripts.onPreload) this.scripts.onPreload.run({}, {})
+ }
+
this.container.classList.toggle('no-inner-padding', !this.getProp('innerPadding'))
this.container.classList.toggle('no-scroll', !this.getProp('scroll'))
this.container.classList.add('layout-' + this.getProp('layout'))
diff --git a/src/client/widgets/containers/root.js b/src/client/widgets/containers/root.js
index 9803494f..1cfcebae 100644
--- a/src/client/widgets/containers/root.js
+++ b/src/client/widgets/containers/root.js
@@ -30,6 +30,9 @@ class Root extends StaticProperties(Panel, {visible: true, label: false, id: 'ro
_separator_root_style: 'Root style',
hideMenu: {type: 'boolean', value: false, help: 'Set to `true` to hide the main menu button.'},
+ },
+ scripting: {
+ onPreload: {type: 'script', value: '', editor: 'javascript', help: ['Script executed before any other widget is created. See documentation.']},
}
})