diff --git a/CHANGELOG.md b/CHANGELOG.md
index 0d6055b7..97f24a4e 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -7,6 +7,7 @@
- widgets
- canvas: expose touch pressure (as `event.force`) in the `touch` script.
+ - canvas: expose touch events for extra elements added with the `html` propery
## 1.13.1
diff --git a/resources/docs/docs/widgets/canvas.md b/resources/docs/docs/widgets/canvas.md
index 2864d835..59da5259 100644
--- a/resources/docs/docs/widgets/canvas.md
+++ b/resources/docs/docs/widgets/canvas.md
@@ -33,18 +33,24 @@ This script is executed when the widget is touched, when it is released, and dur
This script has access to the same variables and functions as the `script` property (except the event-specific ones), plus the following:
- `value`: widget value
-- `width`: widget width in pixels
-- `height`: widget height in pixels
+- `width`: canvas width in pixels
+- `height`: canvas height in pixels
- `event`: object containing the following:
- `type`: `"start"`, `"move"` or `"stop"`
- `target`: id of the widget under the pointer, `"this"` if it's the canvas widget itself, `null` if no widget is under the pointer
- - `offsetX`, `offsetY`: touch coordinates in pixels, relative to `target`
+ - `targetName`: name attribute of the html element under the pointer
+ - `targetTagName`: tag name of the html element under the pointer
+ - `offsetX`, `offsetY`: touch coordinates in pixels, relative to the html element under the pointer
- `movementX`, `movementY`: movement of the pointer in pixels since the last event
- `pointerId`: unique identifier used to differenciate fingers in multitouch situation
- `altKey`, `ctrlKey`, `shiftKey`: keyboard modifier states
- `force`: amount of pressure applied to the touch surface between `0` and `1` (see [Touch.force](https://developer.mozilla.org/en-US/docs/Web/API/Touch/force)). Equals `0` if the API is not supported or if no pressure information is found.
+!!! note "Extra html elements"
+ Elements added using the `html` property can be touched as well, `event.targetName` can be used to determine which element is touched.
+
+
### `draw`
This script is executed when the widget should be redrawn, which is when it's touched and when it receives a value.
@@ -52,8 +58,8 @@ This script is executed when the widget should be redrawn, which is when it's to
This script has access to the same variables and functions as the `script` property (except the event-specific ones), plus the following:
- `value`: widget value
-- `width`: widget width in pixels
-- `height`: widget height in pixels
+- `width`: canvas width in pixels
+- `height`: canvas height in pixels
- `ctx`: [canvas rendering context](https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D) of the widget
- `cssVars`: object containing the computed value of some of the widget's style properties such as `colorWidget`, `alphaFill`, `padding`, etc
diff --git a/resources/docs/docs/widgets/properties-reference.md b/resources/docs/docs/widgets/properties-reference.md
index 3868f641..20736db6 100644
--- a/resources/docs/docs/widgets/properties-reference.md
+++ b/resources/docs/docs/widgets/properties-reference.md
@@ -44,7 +44,7 @@
|
alphaFillOn
| `number` | "auto" | Fill color opacity (on). |
| lineWidth
| `number` | "auto" | Stroke width. |
| padding
| `number` | "auto" | Inner spacing. |
- | html
| `string` | "" | Custom html content to be inserted in the widget (before the widget's content). Elements are all unstyled by default, `css` should be used to customize their appearance.
The code is automatically wrapped in <div class="html"></div>
Allowed HTML tags:
h1-6, blockquote, p, a, ul, ol, nl, li,
b, i, strong, em, strike, code, hr, br, div,
table, thead, img, caption, tbody, tr, th, td, pre
Allowed attributes:
<*>: class, style, title
<img>: src, width, height |
+ | html
| `string` | "" | Custom html content to be inserted in the widget (before the widget's content). Elements are all unstyled by default, `css` should be used to customize their appearance.
The code is automatically wrapped in <div class="html"></div>
Allowed HTML tags:
h1-6, blockquote, p, a, ul, ol, nl, li,
b, i, strong, em, strike, code, hr, br, div,
table, thead, img, caption, tbody, tr, th, td, pre
Allowed attributes:
<*>: class, style, title, name
<img>: src, width, height |
| css
| `string` | "" | CSS rules. See documentation.
Some style-related properties can be set or read from css using css variables:
- `--color-background`: `colorBg`
- `--color-widget`: `colorWidget`
- `--color-fill`: `colorFill`
- `--color-stroke`: `colorStroke`
- `--color-text`: `colorText`
- `--widget-padding`: `padding`
- `--line-width`: `lineWidth`
- `--alpha-fill-on`: `alphaFillOn`
- `--alpha-fill-off`: `alphaFillOff`
- `--alpha-stroke`: `alphaStroke` |
diff --git a/src/client/widgets/common/widget.js b/src/client/widgets/common/widget.js
index 8da22c05..5b2da41c 100644
--- a/src/client/widgets/common/widget.js
+++ b/src/client/widgets/common/widget.js
@@ -89,7 +89,7 @@ class Widget extends EventEmitter {
' b, i, strong, em, strike, code, hr, br, div,',
' table, thead, img, caption, tbody, tr, th, td, pre',
'Allowed attributes:',
- ' <*>: class, style, title',
+ ' <*>: class, style, title, name',
' <img>: src, width, height',
]},
css: {type: 'string', value: '', help: [
@@ -1192,7 +1192,7 @@ class Widget extends EventEmitter {
Widget.sanitizeHtmlOptions = {
allowedTags: sanitizeHtml.defaults.allowedTags.concat(['img', 'h1', 'h2']).filter(x=>x!=='iframe'),
allowedAttributes: {
- '*': [ 'title', 'class', 'style'],
+ '*': [ 'title', 'class', 'style', 'name'],
'img': [ 'src' , 'title', 'class', 'style', 'width', 'height'],
'a': ['href', 'target']
},
diff --git a/src/client/widgets/pads/canvas.js b/src/client/widgets/pads/canvas.js
index 9ee644c6..d05f2c72 100644
--- a/src/client/widgets/pads/canvas.js
+++ b/src/client/widgets/pads/canvas.js
@@ -75,6 +75,8 @@ class CanvasWidget extends Canvas {
var event = {...e}
delete event.firstTarget
+ event.targetName = event.target.getAttribute('name')
+ event.targetTagName = event.target.tagName
var w = widgetManager.getWidgetByElement(event.target)
if (w) event.target = w === this ? 'this' : w.getProp('id')
else event.target = null
@@ -92,15 +94,15 @@ class CanvasWidget extends Canvas {
this.on('draginit',(e)=>{
touchCb(e, 'start')
- }, {element: this.widget, multitouch: true})
+ }, {element: this.container, multitouch: true})
this.on('drag',(e)=>{
touchCb(e, 'move')
- }, {element: this.widget, multitouch: true})
+ }, {element: this.container, multitouch: true})
this.on('dragend',(e)=>{
touchCb(e, 'stop')
- }, {element: this.widget, multitouch: true})
+ }, {element: this.container, multitouch: true})
if (this.getProp('continuous')) {
var freq = parseInt(this.getProp('continuous')) || 30
@@ -131,6 +133,8 @@ class CanvasWidget extends Canvas {
draw() {
+ if (!this.getProp('draw')) return
+
if (this.getProp('autoClear')) {
this.clear()
this.ctx.beginPath()
@@ -143,6 +147,7 @@ class CanvasWidget extends Canvas {
height: this.height,
cssVars: this.cssVars
}, {sync: false, send: false})
+
this.batchDraw()
}
diff --git a/src/scss/widgets/pads.scss b/src/scss/widgets/pads.scss
index debd59c2..34feae3e 100644
--- a/src/scss/widgets/pads.scss
+++ b/src/scss/widgets/pads.scss
@@ -134,7 +134,10 @@
--alpha-fill-on: 0.75;
--alpha-fill: var(--alpha-fill-off);
--widget-padding: 0rem;
-
+ .html {
+ pointer-events: auto;
+ }
+
inner {
position: relative;
flex: 1;