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