plots: add frame widget

This commit is contained in:
bordun 2018-08-28 17:29:56 +02:00
parent b5e7cef445
commit 7a0748355f
5 changed files with 153 additions and 2 deletions

View file

@ -37,6 +37,7 @@ module.exports.widgets = {
text: require('./plots/text'),
image: require('./plots/image'),
svg: require('./plots/svg'),
frame: require('./plots/frame'),
// containers
strip: require('./containers/strip'),
@ -65,7 +66,7 @@ module.exports.categories = {
'Buttons':['toggle','push','switch', 'dropdown'],
'Pads':['xy','rgb','multixy'],
'Matrices':['matrix', 'multifader','multitoggle','multipush', 'keyboard'],
'Plots':['plot','eq','visualizer','led', 'rgbled','meter','text', 'image', 'svg'],
'Plots':['plot','eq','visualizer','led', 'rgbled','meter','text', 'image', 'svg', 'frame'],
'Containers':['panel','strip','modal', 'clone'],
'Switchers':['switcher','crossfader'],
'Inputs':['input', 'keys', 'script', 'gyroscope']

View file

@ -0,0 +1,81 @@
var Widget = require('../common/widget'),
locales = require('../../locales'),
localUrlRe = /(^127\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$)|(^10\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$)|(^172\.1[6-9]{1}[0-9]{0,1}\.[0-9]{1,3}\.[0-9]{1,3}$)|(^172\.2[0-9]{1}[0-9]{0,1}\.[0-9]{1,3}\.[0-9]{1,3}$)|(^172\.3[0-1]{1}[0-9]{0,1}\.[0-9]{1,3}\.[0-9]{1,3}$)|(^192\.168\.[0-9]{1,3}\.[0-9]{1,3}$)/
class Frame extends Widget {
static defaults() {
return {
type:'frame',
id:'auto',
_geometry:'geometry',
left:'auto',
top:'auto',
width:'auto',
height:'auto',
_style:'style',
label:'auto',
css:'',
_frame: 'frame',
border: true,
_value: 'value',
default: '',
value: '',
_osc:'osc',
address:'auto',
preArgs:[],
}
}
constructor(options) {
super({...options, html: '<div class="frame"><iframe src=""></iframe></div>'})
if (!this.getProp('border')) this.container.classList.add('noborder')
this.frame = DOM.get(this.widget, 'iframe')[0]
this.errorText = DOM.create('<span>' + locales('iframe_unauthorized') + '<span>')
this.errorTextMounted = false
}
setValue(v, options={}) {
this.value = v
var parser = document.createElement('a')
parser.href = this.value
if (parser.hostname.match(localUrlRe)) {
this.frame.setAttribute('src', this.value)
this.widget.classList.remove('error')
if (this.errorTextMounted) {
this.widget.removeChild(this.errorText)
this.errorTextMounted = false
}
} else {
this.frame.setAttribute('src', '')
this.widget.classList.add('error')
this.widget.appendChild(this.errorText)
this.errorTextMounted = true
}
if (options.sync) this.changed(options)
}
}
module.exports = Frame

View file

@ -158,6 +158,53 @@
}
}
.frame-container {
width:100rem;
height:100rem;
padding:1rem;
.frame {
display: flex;
flex-direction: row;
justify-content: center;
align-items: center;
flex: 1 1 100%;
background-size:cover;
border:1rem solid var(--color-bg);
background-repeat: no-repeat;
iframe {
flex: 1 1 100%;
height: 100%;
width: 100%;
border: 0;
display: block;
}
iframe[src=""] {
pointer-events: none;
}
&.error {
iframe {
display: none;
}
}
}
&.noborder {
--color-border:transparent;
--color-light:transparent;
--color-light:transparent;
background: transparent;
padding: 0!important;
.frame {
outline:transparent!important;
border:0!important;
box-shadow:none!important;
margin: 0!important;
}
}
}
.editor-enabled .frame-container.nolabel iframe {
pointer-events: none;
}
.panel:not(.tab) > .led-container,
.panel:not(.tab) > .rgbled-container,
.panel:not(.tab) > .text-container,
@ -165,10 +212,11 @@
.panel:not(.tab) > .eq-container,
.panel:not(.tab) > .plot-container,
.panel:not(.tab) > .image-container,
.panel:not(.tab) > .frame-container,
.panel:not(.tab) > .svg-container {
--color-border:transparent;
padding: 0rem;
.plot, .text, .led, .image, .svg {
.plot, .text, .led, .image, .svg, .frame {
margin: 1rem;
box-shadow: 0 0 0 1rem var(--color-light),
0 0 0 1rem var(--color-fg);