Widgets in containers can also be absolutely positionned (within parents boundaries).

Panels can contain tabs !
This commit is contained in:
jean-emmanuel 2016-02-14 11:44:02 +01:00
parent 2581e27928
commit 5f8b085785
8 changed files with 74 additions and 32 deletions

View file

@ -126,11 +126,12 @@ It can also be a self invoking function that returns an array of objects :
widgets: [] // [array] of widget objects
```
- **Panel** : *widget containers with arbitrary position and size*
- **Panel** : *widget/tabs containers*
```
type:'panel',
stretch:false, // [bool] set to true to stretch widgets width (don't put horizontal strips in it)
widgets: [] // [array] of widget objects
widgets: [], // [array] of widget objects
tabs: [] // [array] of tab objects
```
- **fader**

File diff suppressed because one or more lines are too long

View file

@ -56,6 +56,8 @@ enableEditor = function(){
newContainer.children().first().click()
$('#sidepanel').scrollTop(scroll)
if (data.tabs && data.tabs.length) tabs()
}
$('.widget.ui-resizable').resizable('destroy')
@ -71,17 +73,15 @@ enableEditor = function(){
}
})
if (!$(this).parents('.strip, .panel').length) {
$(this).draggable({
helper: "ui-helper",
$(this).draggable({
stop: function( event, ui ) {
data.top = ui.position.top
data.left = ui.offset.left
data.top = ui.position.top// - $(this).parent().position().top
data.left = ui.position.left - $(this).parent().position().left
updateWidget()
},
handle:'.ui-draggable-handle'
}).append('<div class="ui-draggable-handle"></div>')
}
handle:'.ui-draggable-handle',
containment:'parent'
}).append('<div class="ui-draggable-handle"></div>')
for (i in data) {
if (i!='widgets' && i!='tabs') {
@ -128,7 +128,7 @@ enableEditor = function(){
}
}
if (data.widgets) {
if (data.widgets && (!data.tabs || data.tabs.length==0)) {
var list = $('<ul class="input"></ul>')
@ -168,6 +168,45 @@ enableEditor = function(){
}
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)
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.tabs.splice(newIndex, 0, data.tabs.splice(prevIndex, 1)[0])
updateWidget()
})
var add = $(`<li><a class="btn small">+</a></li>`).appendTo(list).click(function(){
data.tabs = data.tabs || []
data.tabs.push({})
updateWidget()
})
$('<label>tabs</label>').appendTo(form)
list.appendTo(form)
}
$('.editor-container').html(form)
scrolls()
})
@ -187,6 +226,9 @@ enableEditor = function(){
$('.editing').removeClass('editing')
link.addClass('editing')
$('.widget.ui-resizable').resizable('destroy')
$('.widget.ui-draggable').draggable('destroy').find('.ui-draggable-handle').remove()
var ontab = []
$('.tab.on').each(function(i){
ontab.push($(this).attr('id'))

View file

@ -2,7 +2,7 @@ init = function(session,callback) {
$('#container').empty()
parsetabs(session,$('#container'))
parsetabs(session,$('#container'),true)
// create sidepanel

View file

@ -19,9 +19,8 @@ hashCode = function(s){
session = []
parsetabs = function(tabs,parent){
parsetabs = function(tabs,parent,main){
var main = !parent.hasClass('tab')
if (main) {
__widgets__ = {}
__widgetsIds__ = {}
@ -104,10 +103,10 @@ parsewidgets = function(widgets,parent) {
widgetData[k] = tmp
}
if (parent[0].className.match(/strip|panel/)) {
delete widgetData.top
delete widgetData.left
}
// if (parent[0].className.match(/strip|panel/)) {
// delete widgetData.top
// delete widgetData.left
// }
var width = parseInt(widgetData.width)==widgetData.width?parseInt(widgetData.width)+'rem' : widgetData.width,
height = parseInt(widgetData.height)==widgetData.height?parseInt(widgetData.height)+'rem' : widgetData.height,

View file

@ -20,7 +20,8 @@ widgetOptions = {
width:'auto',
height:'auto',
stretch:false,
widgets:[]
widgets:[],
tabs:[]
},
led: {
type:'led',
@ -157,8 +158,11 @@ createWidget.panel = function(widgetData,container) {
if (widgetData.stretch) widget.addClass('stretch')
parsewidgets(widgetData.widgets,widget)
if (widgetData.tabs.length) {
parsetabs(widgetData.tabs,widget)
} else {
parsewidgets(widgetData.widgets,widget)
}
widget.getValue = function(){return}
widget.setValue = function(){return}
return widget

View file

@ -331,6 +331,9 @@ a.btn {
}
}
.editing {
z-index: 99999999!important;
}
.editing:before {
content:"";
z-index: 999;

View file

@ -7,16 +7,9 @@
top:40,
left:200,
height:400,width:300,
widgets:[
// these are fader (all options to defaults)
{
},
{
},
{
},
{
}
tabs: [
{widgets:[{},{},{}]}
,{widgets:[{},{},{},{}]}
]
},
{