Merge branch 'master' into fastdom
This commit is contained in:
commit
f4a28dbec7
18 changed files with 158 additions and 110 deletions
|
|
@ -50,6 +50,7 @@ class ContextMenu extends UiWidget {
|
|||
})
|
||||
|
||||
this.container.addEventListener('touchstart', (e)=>{
|
||||
if (e.target.classList.contains('has-sub')) e.preventDefault()
|
||||
if (!e.target.classList.contains('focus')) {
|
||||
DOM.each(e.target.parentNode, '.focus', (el)=>{
|
||||
el.classList.remove('focus')
|
||||
|
|
|
|||
|
|
@ -1,10 +1,8 @@
|
|||
var UiWidget = require('./ui-widget'),
|
||||
Rgb = require('../widgets/pads/rgb'),
|
||||
UiModal = require('./ui-modal'),
|
||||
html = require('nanohtml'),
|
||||
chroma = require('chroma-js'),
|
||||
resize = require('../events/resize'),
|
||||
locales = require('../locales')
|
||||
resize = require('../events/resize')
|
||||
|
||||
|
||||
class ColorPicker extends UiWidget {
|
||||
|
|
@ -27,63 +25,56 @@ class ColorPicker extends UiWidget {
|
|||
}, parent: this})
|
||||
this.rgb.container.classList.add('not-editable')
|
||||
|
||||
this.modal = new UiModal({
|
||||
width: 280,
|
||||
height: 320,
|
||||
closable: true,
|
||||
title: '',
|
||||
hide: true,
|
||||
html: true,
|
||||
content: html`
|
||||
<div class="color-picker-modal">
|
||||
${this.rgb.container}
|
||||
<div class="actions">
|
||||
<div class="btn color-apply">${locales('inspector_color_apply')}</div>
|
||||
<div class="btn color-confirm">${locales('inspector_color_confirm')}</div>
|
||||
</div>
|
||||
</div>
|
||||
`,
|
||||
enterKey: this.confirm.bind(this)
|
||||
})
|
||||
|
||||
DOM.get(this.modal.container, '.color-confirm')[0].addEventListener('click', this.confirm.bind(this))
|
||||
DOM.get(this.modal.container, '.color-apply')[0].addEventListener('click', this.apply.bind(this))
|
||||
this.container = html`
|
||||
<div class="color-picker">
|
||||
${this.rgb.container}
|
||||
</div>
|
||||
`
|
||||
|
||||
this.rgb.on('change', (e)=>{
|
||||
e.stopPropagation = true
|
||||
this.value = chroma(this.rgb.value).hex()
|
||||
this.trigger('change', {preventHistory: true})
|
||||
})
|
||||
// this.rgb.on('dragend', (e)=>{
|
||||
// this.value = chroma(this.rgb.value).hex()
|
||||
// this.trigger('change')
|
||||
// })
|
||||
|
||||
this.rgb.on('dragend', (e)=>{
|
||||
this.value = chroma(this.rgb.value).hex()
|
||||
this.trigger('change')
|
||||
})
|
||||
|
||||
|
||||
this.opened = 0
|
||||
this.label = DOM.get(this.modal.container, '.title')[0]
|
||||
|
||||
this.escKeyHandler = ((e)=>{
|
||||
if (e.keyCode==27) this.close()
|
||||
}).bind(this)
|
||||
|
||||
this.enterKeyHandler = ((e)=>{
|
||||
if (e.keyCode == 13) this.confirm()
|
||||
}).bind(this)
|
||||
|
||||
}
|
||||
|
||||
open() {
|
||||
|
||||
this.label.innerHTML = this.name
|
||||
this.modal.open()
|
||||
this.parentNode.appendChild(this.container)
|
||||
resize.check(this.rgb.container)
|
||||
this.opened = 1
|
||||
|
||||
document.addEventListener('keydown', this.escKeyHandler)
|
||||
document.addEventListener('keydown', this.enterKeyHandler)
|
||||
}
|
||||
|
||||
close() {
|
||||
|
||||
this.modal.close()
|
||||
if (this.parentNode.contains(this.container)) {
|
||||
this.parentNode.removeChild(this.container)
|
||||
}
|
||||
this.setName()
|
||||
this.opened = 0
|
||||
|
||||
}
|
||||
|
||||
apply() {
|
||||
|
||||
this.value = chroma(this.rgb.getValue(true)).css('rgba')
|
||||
this.trigger('change')
|
||||
|
||||
document.removeEventListener('keydown', this.escKeyHandler)
|
||||
document.removeEventListener('keydown', this.enterKeyHandler)
|
||||
}
|
||||
|
||||
confirm() {
|
||||
|
|
@ -114,6 +105,13 @@ class ColorPicker extends UiWidget {
|
|||
|
||||
}
|
||||
|
||||
setParent(node) {
|
||||
|
||||
if (this.opened && node !== this.parentNode) this.close()
|
||||
this.parentNode = node
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
module.exports = ColorPicker
|
||||
|
|
|
|||
|
|
@ -41,11 +41,11 @@ class UiInspector extends UiWidget {
|
|||
this.parentContainer = DOM.get('osc-panel-container.right osc-panel-inner')[0]
|
||||
|
||||
this.colorPicker = new UiColorPicker()
|
||||
this.colorPicker.on('change', ()=>{
|
||||
this.colorPicker.on('change', (event)=>{
|
||||
var textarea = DOM.get(this.container, `textarea[name="${this.colorPicker.name}"]`)
|
||||
if (textarea) {
|
||||
textarea[0].value = this.colorPicker.value
|
||||
DOM.dispatchEvent(textarea[0], 'change')
|
||||
DOM.dispatchEvent(textarea[0], 'change', event)
|
||||
}
|
||||
})
|
||||
|
||||
|
|
@ -55,10 +55,9 @@ class UiInspector extends UiWidget {
|
|||
|
||||
if (node.tagName === 'OSC-INSPECTOR-CHECKBOX') {
|
||||
|
||||
var name = node.getAttribute('name')
|
||||
let name = node.getAttribute('name'),
|
||||
textarea = DOM.get(this.container, `textarea[name="${name}"]`)
|
||||
|
||||
|
||||
var textarea = DOM.get(this.container, `textarea[name="${name}"]`)
|
||||
if (textarea) {
|
||||
fastdom.mutate(()=>{
|
||||
textarea[0].value = !node.classList.contains('on')
|
||||
|
|
@ -68,9 +67,16 @@ class UiInspector extends UiWidget {
|
|||
|
||||
} else if (node.tagName === 'OSC-INSPECTOR-COLOR') {
|
||||
|
||||
this.colorPicker.setName(node.getAttribute('name'))
|
||||
this.colorPicker.setValue(node.getAttribute('value'))
|
||||
this.colorPicker.open()
|
||||
let name = node.getAttribute('name')
|
||||
|
||||
if (this.colorPicker.name === name) {
|
||||
this.colorPicker.close()
|
||||
} else {
|
||||
this.colorPicker.setParent(node.parentNode)
|
||||
this.colorPicker.setName(name)
|
||||
this.colorPicker.setValue(node.getAttribute('value'))
|
||||
this.colorPicker.open()
|
||||
}
|
||||
|
||||
} else if (node.tagName === 'LABEL') {
|
||||
|
||||
|
|
@ -196,6 +202,7 @@ class UiInspector extends UiWidget {
|
|||
var picker = DOM.get(this.container, `osc-inspector-color[name="${this.colorPicker.name}"]`)
|
||||
if (picker && picker[0]) {
|
||||
this.colorPicker.setValue(picker[0].getAttribute('value'))
|
||||
this.colorPicker.open()
|
||||
} else {
|
||||
this.colorPicker.close()
|
||||
}
|
||||
|
|
@ -231,7 +238,8 @@ class UiInspector extends UiWidget {
|
|||
|
||||
this.trigger('update', {
|
||||
propName: input.name,
|
||||
value: v
|
||||
value: v,
|
||||
preventHistory: event.detail && event.detail.preventHistory
|
||||
})
|
||||
|
||||
// this may not be reached if an error is thrown
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue