still splitting it ! also canvas input fade in at first update

This commit is contained in:
jean-emmanuel 2016-02-27 16:34:39 +01:00
parent 72938f2a85
commit b67507fa3a
9 changed files with 347 additions and 238 deletions

File diff suppressed because one or more lines are too long

View file

@ -0,0 +1,169 @@
var editor = require('./editor')
module.exports = {
stateQuickSave: function(preset){
if (preset) {
STATE = preset
} else {
STATE = module.exports.stateGet()
}
$('.quickload').removeClass('disabled')
},
stateQuickLoad: function(){
module.exports.stateSet(STATE,true)
},
stateSave: function() {
state = module.exports.stateGet()
if (WEBFRAME) {
IPC.send('stateSave',STATE)
} else {
var down = $('<a download="'+new Date().toJSON().slice(0,10)+'_'+new Date().toJSON().slice(11,16)+'.preset"></a>')
var blob = new Blob([STATE],{type : 'text/plain'});
down.attr('href', window.URL.createObjectURL(blob))
down[0].click()
}
},
stateGet: function (){
var data = []
$.each(WIDGETS,function(i,widget) {
var v = widget[widget.length-1].getValue()
if (v!=undefined) data.push(i+' '+v)
})
return data.join('\n')
},
stateLoad: function() {
if (WEBFRAME) {
IPC.send('stateLoad')
} else {
var prompt = $('<input type="file" accept=".preset"/>')
prompt.click()
prompt.on('change',function(e){
var reader = new FileReader();
reader.onloadend = function(e) {
var preset = e.target.result
module.exports.stateSet(preset,true)
STATE = preset
}
reader.readAsText(e.target.files[0],'utf-8');
})
}
},
stateSend: function(){
var data = module.exports.stateGet()
module.exports.stateSet(data,true)
},
stateSet: function(preset,send){
$.each(preset.split('\n'),function(i,d) {
var data = d.split(' ')
setTimeout(function(){
if (WIDGETS[data[0]]!=undefined) {
WIDGETS[data[0]][WIDGETS[data[0]].length-1].setValue(data[1].split(','),send,true)
}
},i)
})
},
toggleFullscreen: function(){
if (WEBFRAME) {
IPC.send('fullscreen')
} else {
var isInFullScreen = document.webkitIsFullScreen
if (isInFullScreen) {
document.webkitExitFullscreen()
} else {
document.documentElement.webkitRequestFullScreen()
}
}
},
sessionBrowse: function(){
if (WEBFRAME) {
IPC.send('sessionBrowse')
} else {
var prompt = $('<input type="file" accept=".js"/>')
prompt.click()
prompt.on('change',function(e){
var reader = new FileReader();
reader.onloadend = function(e) {
var session = e.target.result
IPC.send('sessionOpen',{file:session})
}
reader.readAsText(e.target.files[0],'utf-8');
})
}
},
sessionSave: function() {
var sessionfile = JSON.stringify(SESSION,null,' ')
if (WEBFRAME) {
IPC.send('sessionSave',sessionfile)
} else {
var down = $('<a download="'+new Date().toJSON().slice(0,10)+'_'+new Date().toJSON().slice(11,16)+'.js"></a>')
var blob = new Blob([sessionfile],{type : 'text/plain'});
down.attr('href', window.URL.createObjectURL(blob))
down[0].click()
}
},
createPopup: function(title,content) {
var popup = $(`
<div class="popup">
<div class="popup-wrapper">
<div class="popup-title">${title}<span class="closer">${module.exports.icon('remove')}</span></div>
<div class="popup-content"></div>
</div>
</div>`),
closer = popup.find('.popup-title .closer')
closer.click(function(){
popup.close()
})
popup.close = function(){
$(document).unbind('keydown.popup')
popup.remove()
}
popup.find('.popup-content').append(content)
$('body').append(popup)
$(document).on('keydown.popup', function(e){
if (e.keyCode==27) popup.close()
})
return popup
},
luminosityReset: function(){
},
luminosityIncrease: function(){
},
luminosityReduce: function(){
},
editorEnable: editor.enable,
editorDisable: editor.disable
}

View file

@ -1,10 +1,7 @@
var widgets = require('./widgets'),
widgetOptions = widgets.widgetOptions,
sync = widgets.sync,
parsewidgets = require('./parser').widgets,
utils = require('./utils'),
stateGet = utils.stateGet,
stateSet = utils.stateSet
parsewidgets = require('./parser').widgets
function getdata(obj){
@ -33,7 +30,15 @@ function getdata(obj){
}
module.exports.enable = function(){
var actions = require('./actions'),
stateGet = actions.stateGet,
stateSet = actions.stateSet,
init = require('./init'),
ui = require('./ui')
module.exports.disable()
$('.editor').append('<div class="editor-container"></div>')
var enableEditor = module.exports.enable
$('.widget').on('click.editor',function(e){
e.preventDefault()
@ -66,7 +71,7 @@ module.exports.enable = function(){
newContainer.children().first().click()
$('#sidepanel').scrollTop(scroll)
if (data.tabs && data.tabs.length) require('./ui')
if (data.tabs && data.tabs.length) ui()
}
@ -286,7 +291,7 @@ module.exports.enable = function(){
var state = stateGet()
require('./init')(SESSION,function(){
init(SESSION,function(){
stateSet(state,false)
enableEditor()
for (i in ontab) {
@ -401,6 +406,9 @@ module.exports.enable = function(){
e.preventDefault()
e.stopPropagation()
$('.widget.ui-resizable').resizable('destroy')
$('.widget.ui-draggable').draggable('destroy').find('.ui-draggable-handle').remove()
var data = SESSION,
form = $('<div class="form"></div>'),
container = $('#container')
@ -421,7 +429,7 @@ module.exports.enable = function(){
var state = stateGet()
require('./init')(SESSION,function(){
init(SESSION,function(){
stateSet(state,false)
enableEditor()
for (i in ontab) {
@ -492,5 +500,5 @@ module.exports.disable = function(){
$('.enable-editor').removeClass('on')
$('.disable-editor').addClass('on')
$('.editing').removeClass('editing')
$('.editor-container').empty()
$('.editor .editor-container').remove()
}

View file

@ -8,7 +8,7 @@ module.exports = function(session,callback) {
parsetabs(session,$('#container'),true)
ui()
ui.init()
sync()

View file

@ -0,0 +1,136 @@
var actions = require('./actions'),
icon = require('./utils').icon
var data = [
{
actions: [
{
title:'Fullscreen (F11)',
action:actions.toggleFullscreen
}
]
},
{
actions: [
{
title:icon('minus'),
action:actions.luminosityReduce
},
{
title:icon('adjust'),
action:actions.luminosityReset,
class:'disabled'
},
{
title:icon('plus'),
action:actions.luminosityIncrease
}
]
},
{
title: icon('sliders') + '&nbsp; State',
actions: [
{
title:'Store',
action:actions.stateQuickSave
},
{
title:'Recall',
action:actions.stateQuickLoad,
class:'disabled quickload'
},
{
title:'Send All',
action:actions.stateSend
},
{
title:'Import',
action:actions.stateLoad
},
{
title:'Export',
action:actions.stateSave
}
]
},
{
title: icon('edit') + '&nbsp; Editor',
class:'editor',
actions: [
{
title:'On',
action:actions.editorEnable,
class:'enable-editor'
},
{
title:'Off',
action:actions.editorDisable,
class:'on disable-editor'
},
{
title:'Root',
class:'editor-root disabled'
},
{
title:'Load',
action:actions.sessionBrowse
},
{
title:'Save',
action:actions.sessionSave
}
]
},
]
var sidepanel = function(data){
var bindAction = function(el,callback) {
el.click(function(){callback()})
}
var html = $('<ul id="options"></ul>')
for (i in data) {
var itemData = data[i]
var item = $('<li></li>'),
inner = $('<div></div>').appendTo(item)
wrapper = $('<div class="actions"></div>').appendTo(inner)
if (itemData.title) $('<div class="title">'+itemData.title+'</div>').prependTo(inner)
if (itemData.class) inner.attr('class',itemData.class)
for (j in itemData.actions) {
var actionData = itemData.actions[j]
var el = $('<a class="btn">'+actionData.title+'</a>').appendTo(wrapper)
if (actionData.action) bindAction(el, actionData.action)
if (actionData.class) el.addClass(actionData.class)
}
item.appendTo(html)
}
return html
}(data)
module.exports = function() {
$('#sidepanel').append(sidepanel)
actions.editorDisable()
$(`<a id="open-toggle">${icon('navicon')}</a>`).appendTo('#container').click(function(){
$('#open-toggle, #sidepanel, #container').toggleClass('sidepanel-open')
})
// in case where are hot loading a session
if ($('#sidepanel').hasClass('sidepanel-open')) {
$('#open-toggle, #container').addClass('sidepanel-open')
}
}

View file

@ -1,67 +1,7 @@
var editor = require('./editor'),
enableEditor = editor.enable,
disableEditor = editor.disable,
utils = require('./utils')
var actions = require('./actions'),
icon = require('./utils').icon
var sidepanel = function() {
$('#sidepanel').append(utils.createMenu([
{
label:'Fullscreen (F11)',
click:utils.toggleFullscreen,
icon:'tv'
},
{
html: `
<div>
<div class="title"><i class="fa fa-sliders"></i>&nbsp;Snapshot</div>
<div class="actions">
<a class="btn" data-action="utils.stateQuickSave">Store</a>
<a class="btn disabled quickload" data-action="utils.stateQuickLoad">Recall</a>
<a class="btn" data-action="utils.stateSend">Send</a>
</div>
<div class="actions">
<a class="btn" data-action="utils.stateLoad">Import</a>
<a class="btn" data-action="utils.stateSave">Export</a>
</div>
</div>
`
},
{
html:`<div class="editor">
<div class="title"><i class="fa fa-edit"></i>&nbsp;Session editor</div>
<div class="actions">
<a class="enable-editor btn" data-action="enableEditor">On</a>
<a class="disable-editor btn on" data-action="disableEditor">Off</a>
<a class="editor-root btn disabled">Root</a>
</div>
<div class="actions">
<a class="editor-import btn" data-action="utils.sessionBrowse">Load</a>
<a class="editor-export btn" data-action="utils.sessionSave">Save</a>
</div>
<div class="editor-container"></div>
</div>`,
}
]))
disableEditor()
$('[data-action]').each(function(){
$(this).click(function(){
eval($(this).attr('data-action')+'()')
})
})
$(`<a id="open-toggle">${utils.icon('navicon')}</a>`).appendTo('#container').click(function(){
$('#open-toggle, #sidepanel, #container').toggleClass('sidepanel-open')
})
// in case where are hot loading a session
if ($('#sidepanel').hasClass('sidepanel-open')) {
$('#open-toggle, #container').addClass('sidepanel-open')
}
}
var sidepanel = require('./sidepanel')
// Tabs...
var tabs = function() {
@ -128,8 +68,10 @@ var scrolls = function(){
}
module.exports = function(){
sidepanel()
tabs()
scrolls()
module.exports = {
init: function(){
sidepanel()
tabs()
scrolls()
}
}

View file

@ -1,164 +1,5 @@
module.exports = {
stateQuickSave: function(preset){
if (preset) {
STATE = preset
} else {
STATE = module.exports.stateGet()
}
$('.quickload').removeClass('disabled')
},
stateQuickLoad: function(){
module.exports.stateSet(STATE,true)
},
stateSave: function() {
state = module.exports.stateGet()
if (WEBFRAME) {
IPC.send('stateSave',STATE)
} else {
var down = $('<a download="'+new Date().toJSON().slice(0,10)+'_'+new Date().toJSON().slice(11,16)+'.preset"></a>')
var blob = new Blob([STATE],{type : 'text/plain'});
down.attr('href', window.URL.createObjectURL(blob))
down[0].click()
}
},
stateGet: function (){
var data = []
$.each(WIDGETS,function(i,widget) {
var v = widget[widget.length-1].getValue()
if (v!=undefined) data.push(i+' '+v)
})
return data.join('\n')
},
stateLoad: function() {
if (WEBFRAME) {
IPC.send('stateLoad')
} else {
var prompt = $('<input type="file" accept=".preset"/>')
prompt.click()
prompt.on('change',function(e){
var reader = new FileReader();
reader.onloadend = function(e) {
var preset = e.target.result
module.exports.stateSet(preset,true)
laststate = preset
}
reader.readAsText(e.target.files[0],'utf-8');
})
}
},
stateSend: function(){
var data = module.exports.stateGet()
module.exports.stateSet(data,true)
},
stateSet: function(preset,send){
$.each(preset.split('\n'),function(i,d) {
var data = d.split(' ')
setTimeout(function(){
if (WIDGETS[data[0]]!=undefined) {
WIDGETS[data[0]][WIDGETS[data[0]].length-1].setValue(data[1].split(','),send,true)
}
},i)
})
},
toggleFullscreen: function(){
if (WEBFRAME) {
IPC.send('fullscreen')
} else {
var isInFullScreen = document.webkitIsFullScreen
if (isInFullScreen) {
document.webkitExitFullscreen()
} else {
document.documentElement.webkitRequestFullScreen()
}
}
},
sessionBrowse: function(){
if (WEBFRAME) {
IPC.send('sessionBrowse')
} else {
var prompt = $('<input type="file" accept=".js"/>')
prompt.click()
prompt.on('change',function(e){
var reader = new FileReader();
reader.onloadend = function(e) {
var session = e.target.result
IPC.send('sessionOpen',{file:session})
}
reader.readAsText(e.target.files[0],'utf-8');
})
}
},
sessionSave: function() {
var sessionfile = JSON.stringify(SESSION,null,' ')
if (WEBFRAME) {
IPC.send('sessionSave',sessionfile)
} else {
var down = $('<a download="'+new Date().toJSON().slice(0,10)+'_'+new Date().toJSON().slice(11,16)+'.js"></a>')
var blob = new Blob([sessionfile],{type : 'text/plain'});
down.attr('href', window.URL.createObjectURL(blob))
down[0].click()
}
},
createMenu: function(template) {
var menu = $('<ul id="options"></ul>')
var closureClick = function(item) {
return function() {
item.click()
return false
}
}
for (i in template) {
var item = template[i],
label = item.label || 'undefined',
classname = item.class || '',
wrapper = $('<li></li>'),
html
if (!item.html) {
html = $(`<a class="${classname} btn">${label}</a>`)
} else {
html = $(item.html)
}
if (item.icon) html.prepend(module.exports.icon(item.icon)+'&nbsp;')
if (item.click) html.on('click',closureClick(item))
wrapper.append(html)
menu.append(wrapper)
}
return menu
},
createPopup: function(title,content) {
var popup = $(`

View file

@ -15,6 +15,7 @@
self.width = undefined
self.color = $('body').css('color')
self.center = settings.align == 'center'
self.visible = false
self.attr('tabindex',"0")
@ -24,6 +25,12 @@
height = canvas.height()
if (height==100 && width==100) return
if (!self.visible) {
self.visible = true
canvas.addClass('visible')
}
self.height=height
self.width=width

View file

@ -289,10 +289,12 @@ body {
.actions {
display: flex;
align-items: stretch;
flex-wrap:wrap;
a {
min-width:33.33%;
flex-grow:3;
padding:10rem;
display: block;
width:100%;
text-align: center;
&.on {
pointer-events: none;
@ -750,7 +752,11 @@ a {
canvas {
width:100%;
height:100%;
opacity: .8;
opacity: 0;
transition: opacity .2s;
&.visible {
opacity:.8;
}
}
input + canvas {
opacity: 0;