separate js file for editor & some fixes
This commit is contained in:
parent
8032d355b2
commit
081f1346c1
5 changed files with 23 additions and 369 deletions
File diff suppressed because one or more lines are too long
|
|
@ -2,4 +2,5 @@ require('./parser.js') // session file parser
|
|||
require('./utils.js') // state managing & inspector
|
||||
require('./widgets.js') // widgets types and behaviour definition
|
||||
require('./callbacks.js')// calls from mainProcess
|
||||
require('./editor.js') // ...
|
||||
require('./init.js') // ...
|
||||
|
|
|
|||
|
|
@ -35,15 +35,19 @@ init = function(session,callback) {
|
|||
html:`<div class="editor btn">
|
||||
<div class="title"><i class="fa fa-edit"></i> Editor</div>
|
||||
<div class="actions">
|
||||
<a class="enable-editor btn">Enabled</a>
|
||||
<a class="disable-editor btn on">Disabled</a>
|
||||
<a class="editor-root btn disabled">Root</a>
|
||||
<a class="enable-editor btn align-center">On</a>
|
||||
<a class="disable-editor btn on align-center">Off</a>
|
||||
<a class="editor-root btn disabled align-center">Root</a>
|
||||
<a class="editor-export btn align-center"><i class="fa fa-save"></i></a>
|
||||
</div>
|
||||
<div class="editor-container"></div>
|
||||
</div>`,
|
||||
}
|
||||
]))
|
||||
|
||||
$('.enable-editor').click(enableEditor)
|
||||
$('.disable-editor').click(disableEditor)
|
||||
|
||||
|
||||
|
||||
// MASTER DRAGGING (while shift key pressed)
|
||||
|
|
@ -74,7 +78,7 @@ init = function(session,callback) {
|
|||
|
||||
|
||||
|
||||
function sidepanel() {
|
||||
sidepanel = function() {
|
||||
$(`<a id="open-toggle">${icon('navicon')}</a>`).appendTo('#container').click(function(){
|
||||
$('#open-toggle, #sidepanel, #container').toggleClass('sidepanel-open')
|
||||
})
|
||||
|
|
@ -83,7 +87,7 @@ init = function(session,callback) {
|
|||
|
||||
// Widget Synchronization : widget that share the same id will update each other
|
||||
// without sending any extra osc message
|
||||
function sync() {
|
||||
sync = function() {
|
||||
$.each(__widgets__,function(i,widget) {
|
||||
if (widget.length>1) {
|
||||
var script =''
|
||||
|
|
@ -110,7 +114,7 @@ init = function(session,callback) {
|
|||
sync()
|
||||
|
||||
// Tabs...
|
||||
function tabs() {
|
||||
tabs = function() {
|
||||
$('.tablist a').click(function(){
|
||||
|
||||
var id = $(this).data('tab')
|
||||
|
|
@ -133,7 +137,7 @@ init = function(session,callback) {
|
|||
// if shift is pressed (native), or if there is no vertical scrollbar,
|
||||
// or if mouse is on h-scrollbar
|
||||
var scrollbarHeight = 20
|
||||
function scrolls(){
|
||||
scrolls = function(){
|
||||
if (webFrame) {
|
||||
$('.tab').on('mousewheel.zoom',function(e) {
|
||||
// console.log(e)
|
||||
|
|
@ -184,365 +188,6 @@ init = function(session,callback) {
|
|||
|
||||
|
||||
|
||||
function getdata(obj){
|
||||
var path = []
|
||||
|
||||
do {
|
||||
if (obj.hasClass('widget')) {
|
||||
path.unshift(obj.index())
|
||||
path.unshift('widgets')
|
||||
} else if (obj.hasClass('tab')){
|
||||
path.unshift(obj.index())
|
||||
path.unshift('tabs')
|
||||
} else if (obj.attr('id')=='container') {
|
||||
break
|
||||
}
|
||||
|
||||
} while(obj = obj.parent() )
|
||||
|
||||
path.splice(0,1)
|
||||
|
||||
for (var i=0,obj=session, path=path, len=path.length; i<len; i++){
|
||||
obj = obj[path[i]];
|
||||
};
|
||||
return obj;
|
||||
|
||||
}
|
||||
|
||||
function enableEditor(){
|
||||
disableEditor()
|
||||
$('.widget').on('click.editor',function(e){
|
||||
e.preventDefault()
|
||||
e.stopPropagation()
|
||||
|
||||
var container = $(this),
|
||||
parent = container.parent(),
|
||||
parentContainer = parent.parent().hasClass('content')?parent:parent.parent(),
|
||||
index = container.index(),
|
||||
data = getdata(container),
|
||||
form = $('<div class="form"></div>')
|
||||
|
||||
$('.editing').removeClass('editing')
|
||||
container.addClass('editing')
|
||||
|
||||
var updateWidget = function(){
|
||||
var newContainer = parsewidgets([data],parent)
|
||||
|
||||
container.remove()
|
||||
|
||||
if (index == parent.children().length-1) {
|
||||
newContainer.detach().appendTo(parent)
|
||||
} else {
|
||||
newContainer.detach().insertBefore(parent.children().eq(index))
|
||||
}
|
||||
enableEditor()
|
||||
sync()
|
||||
|
||||
newContainer.children().first().click()
|
||||
|
||||
}
|
||||
|
||||
for (i in data) {
|
||||
if (i!='widgets' && i!='tabs') {
|
||||
var type = typeof data[i]
|
||||
var d = type == 'object'?JSON.stringify(data[i]):data[i]
|
||||
var input = $(`
|
||||
<label>${i}</label>
|
||||
<input data-type="${type}" value='${d}' title="${i}"/>
|
||||
`)
|
||||
input.appendTo(form)
|
||||
input.on('change',function(){
|
||||
var v = $(this).data('type') == 'object'?JSON.parse($(this).val()):$(this).val()
|
||||
data[$(this).attr('title')]= v=='true'||v=='false'?eval(v):v
|
||||
updateWidget()
|
||||
})
|
||||
|
||||
}
|
||||
}
|
||||
if (data.widgets) {
|
||||
|
||||
var list = $('<ul class="input"></ul>')
|
||||
|
||||
for (i in data.widgets) {
|
||||
var label = data.widgets[i].label!='auto'&&data.widgets[i].label!=false?data.widgets[i].label:data.widgets[i].id
|
||||
var item = $(`<li data-index="${i}" class="sortables" data-id="${data.widgets[i].id}"><a class="btn small">${label}</a></li>`)
|
||||
.appendTo(list)
|
||||
.click(function(){
|
||||
container.find('.widget').first().parent().children('.widget').eq($(this).attr('data-index')).click()
|
||||
})
|
||||
var remove = $('<span><i class="fa fa-remove"></i></span>')
|
||||
.appendTo(item)
|
||||
.click(function(){
|
||||
data.widgets.splice($(this).parent().attr('data-index'),1)
|
||||
updateWidget()
|
||||
})
|
||||
}
|
||||
|
||||
list.sortable({forcePlaceholderSize: true, items: '.sortables'}).on('sortupdate',function(e,ui){
|
||||
var prevIndex = $(ui.item).attr('data-index')
|
||||
var newIndex = $(ui.item).index()
|
||||
|
||||
data.widgets.splice(newIndex, 0, data.widgets.splice(prevIndex, 1)[0])
|
||||
|
||||
updateWidget()
|
||||
})
|
||||
|
||||
var add = $(`<li><a class="btn small">+</a></li>`).appendTo(list).click(function(){
|
||||
data.widgets = data.widgets || []
|
||||
data.widgets.push({})
|
||||
|
||||
updateWidget()
|
||||
})
|
||||
|
||||
$('<label>widgets</label>').appendTo(form)
|
||||
list.appendTo(form)
|
||||
|
||||
}
|
||||
|
||||
$('.editor-container').html(form)
|
||||
scrolls()
|
||||
})
|
||||
|
||||
|
||||
$('a[data-tab]').on('click.editor',function(e){
|
||||
e.preventDefault()
|
||||
e.stopPropagation()
|
||||
|
||||
var link = $(this),
|
||||
container = $(link.attr('data-tab')),
|
||||
parent = container.parent(),
|
||||
parentContainer = container.parent().parent(),
|
||||
index = container.index(),
|
||||
data = getdata(container),
|
||||
form = $('<div class="form"></div>')
|
||||
|
||||
$('.editing').removeClass('editing')
|
||||
link.addClass('editing')
|
||||
|
||||
var ontab = []
|
||||
$('.tab.on').each(function(i){
|
||||
ontab.push($(this).attr('id'))
|
||||
})
|
||||
ontab.splice(ontab.indexOf(container.attr('id')),1)
|
||||
ontab.push(container.attr('id'))
|
||||
|
||||
var updateTab = function() {
|
||||
|
||||
container.empty()
|
||||
parsewidgets(data.widgets,container)
|
||||
|
||||
enableEditor()
|
||||
sync()
|
||||
|
||||
link.click()
|
||||
}
|
||||
|
||||
var updateSession = function(){
|
||||
|
||||
$('#container').empty()
|
||||
|
||||
init(session,function(){
|
||||
enableEditor()
|
||||
for (i in ontab) {
|
||||
$(`a[data-tab="#${ontab[i]}"]`).click()
|
||||
}
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
for (i in data) {
|
||||
if (i!='widgets' && i!='tabs') {
|
||||
var type = typeof data[i]
|
||||
var d = type == 'object'?JSON.stringify(data[i]):data[i]
|
||||
var input = $(`
|
||||
<label>${i}</label>
|
||||
<input data-type="${type}" value='${d}' title="${i}"/>
|
||||
`)
|
||||
input.appendTo(form)
|
||||
input.on('change',function(){
|
||||
var v = $(this).data('type') == 'object'?JSON.parse($(this).val()):$(this).val()
|
||||
data[$(this).attr('title')]= v=='true'||v=='false'?eval(v):v
|
||||
updateSession()
|
||||
})
|
||||
|
||||
}
|
||||
}
|
||||
if (!data.tabs || data.tabs.length==0) {
|
||||
|
||||
var list = $('<ul class="input"></ul>')
|
||||
|
||||
for (i in data.widgets) {
|
||||
var label = data.widgets[i].label!='auto'&&data.widgets[i].label!=false?data.widgets[i].label:data.widgets[i].id
|
||||
var item = $(`<li data-index="${i}" class="sortables" data-id="${data.widgets[i].id}"><a class="btn small">${label}</a></li>`)
|
||||
.appendTo(list)
|
||||
.click(function(){
|
||||
container.find('.widget').first().parent().children('.widget').eq($(this).attr('data-index')).click()
|
||||
})
|
||||
var remove = $('<span><i class="fa fa-remove"></i></span>')
|
||||
.appendTo(item)
|
||||
.click(function(){
|
||||
data.widgets.splice($(this).parent().attr('data-index'),1)
|
||||
updateTab()
|
||||
})
|
||||
}
|
||||
|
||||
list.sortable({forcePlaceholderSize: true, items: '.sortables'}).on('sortupdate',function(e,ui){
|
||||
var prevIndex = $(ui.item).attr('data-index')
|
||||
var newIndex = $(ui.item).index()
|
||||
|
||||
data.widgets.splice(newIndex, 0, data.widgets.splice(prevIndex, 1)[0])
|
||||
|
||||
updateTab()
|
||||
|
||||
})
|
||||
|
||||
var add = $(`<li><a class="btn small">+</a></li>`).appendTo(list).click(function(){
|
||||
data.widgets = data.widgets || []
|
||||
data.widgets.push({})
|
||||
|
||||
updateTab()
|
||||
})
|
||||
$('<label>widgets</label>').appendTo(form)
|
||||
list.appendTo(form)
|
||||
|
||||
}
|
||||
|
||||
if (!data.widgets || data.widgets.length==0) {
|
||||
//tabs
|
||||
var list = $('<ul class="input"></ul>')
|
||||
|
||||
for (i in data.tabs) {
|
||||
var label = data.tabs[i].label
|
||||
var item = $(`<li data-index="${i}" class="sortables"><a class="btn small">${label}</a></li>`)
|
||||
.appendTo(list)
|
||||
.click(function(){
|
||||
var id = container.find('.tab').first().parent().children('.tab').eq($(this).attr('data-index')).attr('id')
|
||||
$(`a[data-tab="#${id}"]`).click()
|
||||
})
|
||||
var remove = $('<span><i class="fa fa-remove"></i></span>')
|
||||
.appendTo(item)
|
||||
.click(function(){
|
||||
data.tabs.splice($(this).parent().attr('data-index'),1)
|
||||
updateSession()
|
||||
})
|
||||
}
|
||||
|
||||
list.sortable({forcePlaceholderSize: true, items: '.sortables'}).on('sortupdate',function(e,ui){
|
||||
var prevIndex = $(ui.item).attr('data-index')
|
||||
var newIndex = $(ui.item).index()
|
||||
|
||||
data.tabs.splice(newIndex, 0, data.tabs.splice(prevIndex, 1)[0])
|
||||
|
||||
updateSession()
|
||||
})
|
||||
|
||||
var add = $(`<li><a class="btn small">+</a></li>`).appendTo(list).click(function(){
|
||||
data.tabs = data.tabs || []
|
||||
data.tabs.push({})
|
||||
|
||||
updateSession()
|
||||
})
|
||||
$('<label>tabs</label>').appendTo(form)
|
||||
list.appendTo(form)
|
||||
}
|
||||
|
||||
$('.editor-container').html(form)
|
||||
scrolls()
|
||||
})
|
||||
$('.editor-root').removeClass('disabled').on('click.editor',function(e){
|
||||
e.preventDefault()
|
||||
e.stopPropagation()
|
||||
|
||||
var data = session,
|
||||
form = $('<div class="form"></div>'),
|
||||
container = $('#container')
|
||||
|
||||
$('.editing').removeClass('editing')
|
||||
$(this).addClass('editing')
|
||||
|
||||
var ontab = []
|
||||
$('.tab.on').each(function(i){
|
||||
ontab.push($(this).attr('id'))
|
||||
})
|
||||
ontab.splice(ontab.indexOf(container.attr('id')),1)
|
||||
ontab.push(container.attr('id'))
|
||||
|
||||
|
||||
var updateSession = function(){
|
||||
|
||||
$('#container').empty()
|
||||
|
||||
init(session,function(){
|
||||
enableEditor()
|
||||
for (i in ontab) {
|
||||
$(`a[data-tab="#${ontab[i]}"]`).click()
|
||||
}
|
||||
$('.editor-root').click()
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
|
||||
var list = $('<ul class="input"></ul>')
|
||||
|
||||
for (i in data) {
|
||||
var label = data[i].label
|
||||
var item = $(`<li data-index="${i}" class="sortables"><a class="btn small">${label}</a></li>`)
|
||||
.appendTo(list)
|
||||
.click(function(){
|
||||
var id = $('#container > .content > .tab').eq($(this).attr('data-index')).attr('id')
|
||||
$(`a[data-tab="#${id}"]`).click()
|
||||
})
|
||||
var remove = $('<span><i class="fa fa-remove"></i></span>')
|
||||
.appendTo(item)
|
||||
.click(function(){
|
||||
data.splice($(this).parent().attr('data-index'),1)
|
||||
updateSession()
|
||||
})
|
||||
}
|
||||
|
||||
list.sortable({forcePlaceholderSize: true, items: '.sortables'}).on('sortupdate',function(e,ui){
|
||||
var prevIndex = $(ui.item).attr('data-index')
|
||||
var newIndex = $(ui.item).index()
|
||||
|
||||
data.splice(newIndex, 0, data.splice(prevIndex, 1)[0])
|
||||
|
||||
updateSession()
|
||||
})
|
||||
|
||||
var add = $(`<li><a class="btn small">+</a></li>`).appendTo(list).click(function(){
|
||||
data = data || []
|
||||
data.push({})
|
||||
|
||||
updateSession()
|
||||
})
|
||||
$('<label>tabs</label>').appendTo(form)
|
||||
list.appendTo(form)
|
||||
|
||||
|
||||
$('.editor-container').html(form)
|
||||
})
|
||||
|
||||
$('.enable-editor').addClass('on')
|
||||
$('.disable-editor').removeClass('on')
|
||||
}
|
||||
function disableEditor(){
|
||||
$('.widget').off('click.editor')
|
||||
$('a[data-tab]').off('click.editor')
|
||||
$('.editor-root').off('click.editor').addClass('disabled')
|
||||
$('.enable-editor').removeClass('on')
|
||||
$('.disable-editor').addClass('on')
|
||||
$('.editing').removeClass('editing')
|
||||
$('.editor-container').empty()
|
||||
}
|
||||
|
||||
|
||||
// $('#open-toggle').click()
|
||||
|
||||
$('.enable-editor').click(enableEditor)
|
||||
$('.disable-editor').click(disableEditor)
|
||||
|
||||
|
||||
if (callback) callback()
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -14,6 +14,7 @@ widgetOptions = {
|
|||
top:'auto',
|
||||
width:'auto',
|
||||
height:'auto',
|
||||
stretch:false,
|
||||
widgets:[]
|
||||
},
|
||||
led: {
|
||||
|
|
@ -56,7 +57,6 @@ widgetOptions = {
|
|||
label:'auto',
|
||||
width:'auto',
|
||||
split:false,
|
||||
// range:{r:{min:0,max:255},g:{min:0,max:255},b:{min:255}},
|
||||
absolute:false,
|
||||
path:'auto',
|
||||
target:false
|
||||
|
|
@ -109,6 +109,7 @@ createWidget.panel = function(widgetData,container) {
|
|||
width = parseInt(widgetData.width)==widgetData.width?parseInt(widgetData.width)+'rem' : widgetData.width,
|
||||
height = parseInt(widgetData.height)==widgetData.height?parseInt(widgetData.height)+'rem' : widgetData.height
|
||||
|
||||
if (widgetData.stretch) widget.addClass('stretch')
|
||||
|
||||
container.css({
|
||||
left:'auto',
|
||||
|
|
|
|||
|
|
@ -144,14 +144,21 @@ body {
|
|||
border:1rem solid $color-border;
|
||||
padding:15rem;
|
||||
position: relative;
|
||||
white-space: nowrap;
|
||||
text-overflow: ellipsis;
|
||||
overflow: hidden;
|
||||
&.small {
|
||||
padding:5rem
|
||||
padding:5rem;
|
||||
padding-right: 15rem;
|
||||
}
|
||||
&.disabled {
|
||||
pointer-events: none;
|
||||
color:$color-text-fade;
|
||||
background: $bg-3d-off;
|
||||
}
|
||||
&.align-center {
|
||||
text-align: center
|
||||
}
|
||||
}
|
||||
a.btn {
|
||||
&:hover {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue