updated by GasGit automation
This commit is contained in:
parent
9317041efb
commit
fe531809fd
1 changed files with 257 additions and 147 deletions
|
@ -1,17 +1,17 @@
|
||||||
function Elementer() {
|
function Elementer() {
|
||||||
|
|
||||||
var self = this;
|
var self = this;
|
||||||
var elements_, detail_, layout_, container_, main_, classes_, root_,initial_, initialSource_ ="standard",standard_;
|
var elements_, detail_, layout_, container_, main_, classes_, root_,initial_, initialSource_ ="standard",standard_;
|
||||||
|
|
||||||
// the default layout
|
// the default layout
|
||||||
// anything added by .setLayout() will be merged with this
|
// anything added by .setLayout() will be merged with this
|
||||||
var defLayout_ = {
|
var defLayout_ = {
|
||||||
|
|
||||||
settings: {
|
settings: {
|
||||||
prefix: "layout",
|
prefix: "layout",
|
||||||
root: "root"
|
root: "root"
|
||||||
},
|
},
|
||||||
|
|
||||||
pages: {
|
pages: {
|
||||||
root: {
|
root: {
|
||||||
label: "Settings",
|
label: "Settings",
|
||||||
|
@ -19,7 +19,8 @@ function Elementer() {
|
||||||
classes: {
|
classes: {
|
||||||
branch: "",
|
branch: "",
|
||||||
nav: {
|
nav: {
|
||||||
prevIcon: ""
|
prevIcon: "",
|
||||||
|
showTitle:false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -42,43 +43,51 @@ function Elementer() {
|
||||||
tdLabel: "",
|
tdLabel: "",
|
||||||
icon: "mui--text-dark-secondary material-icons",
|
icon: "mui--text-dark-secondary material-icons",
|
||||||
tdIcon: "mui--align-middle",
|
tdIcon: "mui--align-middle",
|
||||||
|
tdNextIcon:"mui--align-middle mui--text-right",
|
||||||
option:"",
|
option:"",
|
||||||
nav: {
|
nav: {
|
||||||
nextIcon: "chevron_right",
|
nextIcon: "chevron_right",
|
||||||
prevIcon: "chevron_left"
|
prevIcon: "", // chevron_left to enable back at top of page.
|
||||||
|
showTitle:true
|
||||||
},
|
},
|
||||||
hide: "mui--hide",
|
hide: "mui--hide",
|
||||||
show: "mui--show"
|
show: "mui--show"
|
||||||
};
|
};
|
||||||
|
|
||||||
var defStyles_ = {
|
var defStyles_ = {
|
||||||
td: "padding:3px",
|
td: "padding:3px;",
|
||||||
tdLabel: "padding:3px",
|
tdLabel: "padding:3px;",
|
||||||
tdIcon: "padding:3px;max-width:30px;",
|
tdIcon: "padding:3px;max-width:32px;",
|
||||||
tdElement: "padding:3px",
|
tdElement: "padding:3px;",
|
||||||
backLabel:"position:relative;vertical-align: middle;",
|
backLabel:"position:relative;vertical-align: middle;",
|
||||||
icon:"vertical-align: middle;",
|
icon:"vertical-align: middle;",
|
||||||
elementContainer:"padding:0px;margin:0;",
|
elementContainer:"padding:0px;margin:0;",
|
||||||
navCursor:"cursor: pointer; cursor: hand;",
|
navCursor:"cursor: pointer; cursor: hand;",
|
||||||
backLabel:"cursor: pointer; cursor: hand;"
|
backLabel:"cursor: pointer; cursor: hand;",
|
||||||
|
tdNextIcon: "padding:3px;",
|
||||||
};
|
};
|
||||||
|
|
||||||
var defDetail_ = {
|
var defDetail_ = {
|
||||||
selectTemplate: {
|
selectTemplate: {
|
||||||
tag: "SELECT",
|
tag: "SELECT",
|
||||||
classes:{
|
classes:{
|
||||||
elementContainer:"mui-select"
|
elementContainer:""
|
||||||
},
|
},
|
||||||
values:{
|
values:{
|
||||||
property:"value",
|
property:"value",
|
||||||
resetable:true
|
resetable:true
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
textAreaTemplate: {
|
textAreaTemplate: {
|
||||||
tag: "TEXTAREA",
|
tag: "TEXTAREA",
|
||||||
label:"Input text area",
|
label:"Input text area",
|
||||||
classes:{
|
classes:{
|
||||||
elementContainer:"mui-textfield"
|
elementContainer:"",
|
||||||
|
tdElement:"mui-text-left",
|
||||||
|
},
|
||||||
|
styles:{
|
||||||
|
element:"width:100%;"
|
||||||
},
|
},
|
||||||
values:{
|
values:{
|
||||||
property:"value",
|
property:"value",
|
||||||
|
@ -86,21 +95,66 @@ function Elementer() {
|
||||||
value:"",
|
value:"",
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
buttonTemplate:{
|
buttonTemplate:{
|
||||||
tag:"BUTTON",
|
tag:"BUTTON",
|
||||||
label:"",
|
label:"",
|
||||||
classes:{
|
classes:{
|
||||||
element:"mui-btn"
|
element:"",
|
||||||
|
tdElement:"button-item",
|
||||||
|
tr:"button-place",
|
||||||
|
cancel:""
|
||||||
},
|
},
|
||||||
properties:{
|
properties:{
|
||||||
type:"button"
|
type:"button"
|
||||||
},
|
},
|
||||||
|
styles:{
|
||||||
|
tdElement:"padding-top:10px;"
|
||||||
|
},
|
||||||
values:{
|
values:{
|
||||||
property:"innerHTML",
|
property:"innerHTML",
|
||||||
value:"Submit",
|
value:"SUBMIT",
|
||||||
resetable:false
|
resetable:false
|
||||||
|
},
|
||||||
|
custom:{
|
||||||
|
cancelButton:true,
|
||||||
|
cancelText:"BACK",
|
||||||
|
outside:true,
|
||||||
|
backListener:true
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
resetButtonTemplate:{
|
||||||
|
tag:"BUTTON",
|
||||||
|
label:"",
|
||||||
|
classes:{
|
||||||
|
element:"action ",
|
||||||
|
tdElement:"button-item",
|
||||||
|
tr:"button-place",
|
||||||
|
cancel:""
|
||||||
|
},
|
||||||
|
properties:{
|
||||||
|
type:"button",
|
||||||
|
disabled:true
|
||||||
|
},
|
||||||
|
styles:{
|
||||||
|
tdElement:"padding-top:10px;"
|
||||||
|
},
|
||||||
|
values:{
|
||||||
|
property:"innerHTML",
|
||||||
|
value:"APPLY",
|
||||||
|
resetable:false
|
||||||
|
},
|
||||||
|
custom:{
|
||||||
|
cancelButton:true,
|
||||||
|
cancelText:"BACK",
|
||||||
|
outside:true,
|
||||||
|
backListener:true
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
textTemplate: {
|
textTemplate: {
|
||||||
tag: "INPUT",
|
tag: "INPUT",
|
||||||
label: "Input text",
|
label: "Input text",
|
||||||
|
@ -109,10 +163,10 @@ function Elementer() {
|
||||||
type: "text"
|
type: "text"
|
||||||
},
|
},
|
||||||
styles: {
|
styles: {
|
||||||
element: "max-width:100px;"
|
element: "width:50px;"
|
||||||
},
|
},
|
||||||
classes:{
|
classes:{
|
||||||
elementContainer:"mui-textfield"
|
elementContainer:""
|
||||||
},
|
},
|
||||||
values: {
|
values: {
|
||||||
property:"value",
|
property:"value",
|
||||||
|
@ -129,8 +183,11 @@ function Elementer() {
|
||||||
min: 0,
|
min: 0,
|
||||||
max: 100
|
max: 100
|
||||||
},
|
},
|
||||||
|
styles: {
|
||||||
|
element:"width:50px;"
|
||||||
|
},
|
||||||
classes:{
|
classes:{
|
||||||
elementContainer:"mui-textfield"
|
elementContainer:""
|
||||||
},
|
},
|
||||||
values: {
|
values: {
|
||||||
property:"value",
|
property:"value",
|
||||||
|
@ -144,7 +201,7 @@ function Elementer() {
|
||||||
type: "checkbox"
|
type: "checkbox"
|
||||||
},
|
},
|
||||||
classes:{
|
classes:{
|
||||||
elementContainer:"mui-checkbox"
|
elementContainer:""
|
||||||
},
|
},
|
||||||
values: {
|
values: {
|
||||||
property:"checked",
|
property:"checked",
|
||||||
|
@ -159,7 +216,7 @@ function Elementer() {
|
||||||
name: "radioGroup"
|
name: "radioGroup"
|
||||||
},
|
},
|
||||||
classes:{
|
classes:{
|
||||||
elementContainer:"mui-radio"
|
elementContainer:""
|
||||||
},
|
},
|
||||||
values: {
|
values: {
|
||||||
property:"checked",
|
property:"checked",
|
||||||
|
@ -177,6 +234,9 @@ function Elementer() {
|
||||||
label: "subhead",
|
label: "subhead",
|
||||||
classes: {
|
classes: {
|
||||||
label: "mui--text-accent"
|
label: "mui--text-accent"
|
||||||
|
},
|
||||||
|
styles: {
|
||||||
|
tdLabel:"padding:3px;padding-top:13px;"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
contentTemplate: {
|
contentTemplate: {
|
||||||
|
@ -187,7 +247,7 @@ function Elementer() {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* these are the computed values/styles and classes generated by the elementer
|
* these are the computed values/styles and classes generated by the elementer
|
||||||
* @return {object} the computed values/styles etc
|
* @return {object} the computed values/styles etc
|
||||||
*/
|
*/
|
||||||
|
@ -215,9 +275,9 @@ function Elementer() {
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* return the elements generated
|
* return the elements generated
|
||||||
* @return {object} the element view
|
* @return {object} the element view
|
||||||
*/
|
*/
|
||||||
self.getElements = function() {
|
self.getElements = function() {
|
||||||
return elements_;
|
return elements_;
|
||||||
};
|
};
|
||||||
|
@ -225,82 +285,82 @@ function Elementer() {
|
||||||
return layout_;
|
return layout_;
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* @param {object} detail an object with the item details
|
* @param {object} detail an object with the item details
|
||||||
* @return {Elementer} self
|
* @return {Elementer} self
|
||||||
*/
|
*/
|
||||||
self.setDetail = function(detail) {
|
self.setDetail = function(detail) {
|
||||||
detail_ = Utils.vanMerge([defDetail_, detail]);
|
detail_ = Utils.vanMerge([defDetail_, detail]);
|
||||||
return self;
|
return self;
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {object} detail an object with the item layout
|
* @param {object} detail an object with the item layout
|
||||||
* @return {Elementer} self
|
* @return {Elementer} self
|
||||||
*/
|
*/
|
||||||
self.setLayout = function(layout) {
|
self.setLayout = function(layout) {
|
||||||
layout_ = Utils.vanMerge([defLayout_, layout]);
|
layout_ = Utils.vanMerge([defLayout_, layout]);
|
||||||
return self;
|
return self;
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* this is the container that hosts the main
|
* this is the container that hosts the main
|
||||||
* content of the elementer
|
* content of the elementer
|
||||||
* @param {string|element} container elementer content
|
* @param {string|element} container elementer content
|
||||||
* @return {Elementer} self
|
* @return {Elementer} self
|
||||||
*/
|
*/
|
||||||
self.setContainer = function(container) {
|
self.setContainer = function(container) {
|
||||||
container_ = DomUtils.elem(container);
|
container_ = DomUtils.elem(container);
|
||||||
return self;
|
return self;
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*this is the container of the main page hosting the
|
*this is the container of the main page hosting the
|
||||||
* link to the elementer content
|
* link to the elementer content
|
||||||
* if specified it will be hidden or shown
|
* if specified it will be hidden or shown
|
||||||
* depending on whether we are at the top level
|
* depending on whether we are at the top level
|
||||||
* @param {string|element} main main hosting element
|
* @param {string|element} main main hosting element
|
||||||
* @return {Elementer} self
|
* @return {Elementer} self
|
||||||
*/
|
*/
|
||||||
self.setMain = function(main) {
|
self.setMain = function(main) {
|
||||||
main_ = DomUtils.elem(main);
|
main_ = DomUtils.elem(main);
|
||||||
return self;
|
return self;
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*this is the root element
|
*this is the root element
|
||||||
* which will normally be a child of main
|
* which will normally be a child of main
|
||||||
* @param {string|element} root hook to elementer
|
* @param {string|element} root hook to elementer
|
||||||
* @return {Elementer} self
|
* @return {Elementer} self
|
||||||
*/
|
*/
|
||||||
self.setRoot = function(root) {
|
self.setRoot = function(root) {
|
||||||
root_ = DomUtils.elem(root);
|
root_ = DomUtils.elem(root);
|
||||||
return self;
|
return self;
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*this is an object with the required formatting classes
|
*this is an object with the required formatting classes
|
||||||
* if you are using muicss, then this is optional
|
* if you are using muicss, then this is optional
|
||||||
* @param {object} classes your class definitions to merge
|
* @param {object} classes your class definitions to merge
|
||||||
* @return {Elementer} self
|
* @return {Elementer} self
|
||||||
*/
|
*/
|
||||||
self.setClasses = function(classes) {
|
self.setClasses = function(classes) {
|
||||||
classes_ = Utils.vanMerge([defClasses_, classes]);
|
classes_ = Utils.vanMerge([defClasses_, classes]);
|
||||||
return self;
|
return self;
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* put the settings back to standard
|
* put the settings back to standard
|
||||||
* @return {Elementer} self
|
* @return {Elementer} self
|
||||||
*/
|
*/
|
||||||
self.restorestandard = function() {
|
self.restorestandard = function() {
|
||||||
self.applySettings (standard_);
|
self.applySettings (standard_);
|
||||||
return self;
|
return self;
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* put the settings back to what they were initially
|
* put the settings back to what they were initially
|
||||||
* @return {Elementer} self
|
* @return {Elementer} self
|
||||||
*/
|
*/
|
||||||
self.restoreInitial = function() {
|
self.restoreInitial = function() {
|
||||||
self.applySettings (initial_);
|
self.applySettings (initial_);
|
||||||
return self;
|
return self;
|
||||||
|
@ -324,9 +384,9 @@ function Elementer() {
|
||||||
},{});
|
},{});
|
||||||
};
|
};
|
||||||
/**
|
/**
|
||||||
*this creates the elements
|
*this creates the elements
|
||||||
* @return {Elementer} self
|
* @return {Elementer} self
|
||||||
*/
|
*/
|
||||||
self.build = function() {
|
self.build = function() {
|
||||||
// in case just using default
|
// in case just using default
|
||||||
classes_ = classes_ || defClasses_;
|
classes_ = classes_ || defClasses_;
|
||||||
|
@ -334,7 +394,7 @@ function Elementer() {
|
||||||
if (!detail_ || !layout_ || !container_ || !root_) {
|
if (!detail_ || !layout_ || !container_ || !root_) {
|
||||||
throw 'a container, detail, root and layout are all required'
|
throw 'a container, detail, root and layout are all required'
|
||||||
}
|
}
|
||||||
|
|
||||||
// this is the final result
|
// this is the final result
|
||||||
elements_ = {
|
elements_ = {
|
||||||
controls: {},
|
controls: {},
|
||||||
|
@ -345,50 +405,47 @@ function Elementer() {
|
||||||
|
|
||||||
// this is the computed styles etc.
|
// this is the computed styles etc.
|
||||||
initial_ = {};
|
initial_ = {};
|
||||||
|
|
||||||
// clear out the container
|
// clear out the container
|
||||||
container_.innerHTML = "";
|
container_.innerHTML = "";
|
||||||
|
|
||||||
// short cut
|
// short cut
|
||||||
var ea = DomUtils.addElem;
|
var ea = DomUtils.addElem;
|
||||||
|
|
||||||
// do the root
|
// do the root
|
||||||
doLayout(root_, layout_.settings.root, layout_, detail_);
|
doLayout(root_, layout_.settings.root, layout_, detail_);
|
||||||
|
|
||||||
// do the others
|
// do the others
|
||||||
Object.keys(layout_.pages).forEach(function(k) {
|
Object.keys(layout_.pages).forEach(function(k) {
|
||||||
|
|
||||||
if (k !== layout_.settings.root) {
|
if (k !== layout_.settings.root) {
|
||||||
doLayout(container_, k, layout_, detail_);
|
doLayout(container_, k, layout_, detail_);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// set the initial visibility state
|
// set the initial visibility state
|
||||||
var rt = layout_.settings.root;
|
var rt = layout_.settings.root;
|
||||||
var onEnter = layout_.pages[rt].on ? layout_.pages[rt].on.enter : null;
|
var onEnter = layout_.pages[rt].on ? layout_.pages[rt].on.enter : null;
|
||||||
showThis(elements_.pages[rt], onEnter);
|
showThis(elements_.pages[rt], onEnter);
|
||||||
|
|
||||||
return self;
|
return self;
|
||||||
|
|
||||||
function doLayout(parent, branchName, layout, details) {
|
function doLayout(parent, branchName, layout, details) {
|
||||||
|
|
||||||
// working on this layout
|
// working on this layout
|
||||||
var lob = layout.pages[branchName];
|
var lob = layout.pages[branchName];
|
||||||
|
|
||||||
// merge with any specific classes for this layout page
|
// merge with any specific classes for this layout page
|
||||||
var ec = Utils.vanMerge([classes_, lob.classes]);
|
var ec = Utils.vanMerge([classes_, lob.classes]);
|
||||||
var es = Utils.vanMerge ([defStyles_ , lob.styles || {}]);
|
var es = Utils.vanMerge ([defStyles_ , lob.styles || {}]);
|
||||||
|
|
||||||
// the container for this layout
|
// the container for this layout
|
||||||
var dv = ea(parent, "div", "", ec.branch);
|
var dv = ea(parent, "div", "", ec.branch);
|
||||||
dv.id = layout.settings.prefix + "-" + branchName;
|
dv.id = layout.settings.prefix + "-" + branchName;
|
||||||
|
|
||||||
elements_.pages[branchName] = dv;
|
elements_.pages[branchName] = dv;
|
||||||
|
|
||||||
// prev icon - hide this and go back to whoever called
|
function backListener (elm) {
|
||||||
if (ec.nav.prevIcon) {
|
elm.addEventListener('click', function(e) {
|
||||||
var dvp = ea(dv, "div", "", ec.backLabel, es.backLabel);
|
|
||||||
var backIcon = ea(dvp, "span", ec.nav.prevIcon, ec.icon, es.icon);
|
|
||||||
ea(dvp, "span", "Back to ???", ec.backLabel, es.backLabel).id = layout.settings.prefix + "-" + branchName + "-backcomment";
|
|
||||||
dvp.addEventListener('click', function(e) {
|
|
||||||
|
|
||||||
// do exit processing
|
// do exit processing
|
||||||
var onExit = layout_.pages[branchName].on ? layout_.pages[branchName].on.exit : null;
|
var onExit = layout_.pages[branchName].on ? layout_.pages[branchName].on.exit : null;
|
||||||
|
@ -401,44 +458,53 @@ function Elementer() {
|
||||||
var onEnter = layout_.pages[elb.branchName].on ? layout_.pages[elb.branchName].on.enter : null;
|
var onEnter = layout_.pages[elb.branchName].on ? layout_.pages[elb.branchName].on.enter : null;
|
||||||
showThis(elb.element, onEnter);
|
showThis(elb.element, onEnter);
|
||||||
});
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// prev icon - hide this and go back to whoever called
|
||||||
|
if (ec.nav.prevIcon) {
|
||||||
|
|
||||||
|
var dvp = ea(dv, "div", "", ec.backLabel, es.backLabel);
|
||||||
|
var backIcon = ea(dvp, "span", ec.nav.prevIcon, ec.icon, es.icon);
|
||||||
|
ea(dvp, "span", "Back to ???", ec.backLabel, es.backLabel).id = layout.settings.prefix + "-" + branchName + "-backcomment";
|
||||||
|
backListener (dvp);
|
||||||
|
|
||||||
|
}
|
||||||
// use a table to lay out
|
// use a table to lay out
|
||||||
var tab = ea(dv, "table", "", ec.table, es.table);
|
var tab = ea(dv, "table", "", ec.table, es.table);
|
||||||
// the section title
|
// the section title
|
||||||
var tr = ea(tab, "tr", "", ec.tr, es.tr);
|
var tr = ea(tab, "tr", "", ec.tr, es.tr);
|
||||||
|
|
||||||
if (ec.nav.prevIcon) {
|
if (ec.nav.showTitle) {
|
||||||
|
|
||||||
var td = ea(tr, "td", "", ec.td, es.td);
|
var td = ea(tr, "td", "", ec.td, es.td);
|
||||||
td.colSpan = 3;
|
td.colSpan = 3;
|
||||||
ea(td, "span", DomUtils.fillLabel(lob.label), ec.title, es.title);
|
ea(td, "span", DomUtils.fillLabel(lob.label), ec.title, es.title);
|
||||||
}
|
}
|
||||||
|
|
||||||
lob.items.forEach(function(d) {
|
lob.items.forEach(function(d) {
|
||||||
if (layout.pages[d]) {
|
if (layout.pages[d]) {
|
||||||
// its a reference to another section
|
// its a reference to another section
|
||||||
|
|
||||||
var ob = layout.pages[d];
|
var ob = layout.pages[d];
|
||||||
// bring in any override classes
|
// bring in any override classes
|
||||||
var fc = Utils.vanMerge([ec, ob.classes]);
|
var fc = Utils.vanMerge([ec, ob.classes]);
|
||||||
var fs = Utils.vanMerge([es, ob.styles]);
|
var fs = Utils.vanMerge([es, ob.styles]);
|
||||||
var tr = ea(tab, "tr", "", fc.tr, fc.nav.nextIcon ? fs.navCursor : fs.tr);
|
var tr = ea(tab, "tr", "", fc.tr, fc.nav.nextIcon ? fs.navCursor : fs.tr);
|
||||||
|
|
||||||
// the icon
|
// the icon
|
||||||
|
|
||||||
if (ob.icon) {
|
if (ob.icon) {
|
||||||
var td = ea(tr, "td", "", fc.tdIcon, fs.tdIcon);
|
var td = ea(tr, "td", "", fc.tdIcon, fs.tdIcon);
|
||||||
ea(td, "i", ob.icon, fc.icon, fs.icon);
|
ea(td, "i", ob.icon, fc.icon, fs.icon);
|
||||||
}
|
}
|
||||||
|
|
||||||
// the label
|
// the label
|
||||||
var td = ea(tr, "td", "", fc.tdLabel, fs.tdLabel);
|
var td = ea(tr, "td", "", fc.tdLabel, fs.tdLabel);
|
||||||
var label = ob.label ? ea(td, "label", DomUtils.fillLabel(ob.label), fc.subhead, fc.nav.nextIcon ? fs.navCursor : fs.subhead) : null;
|
var label = ob.label ? ea(td, "label", DomUtils.fillLabel(ob.label), fc.subhead, fc.nav.nextIcon ? fs.navCursor : fs.subhead) : null;
|
||||||
if (!ob.icon) {
|
if (!ob.icon) {
|
||||||
td.colSpan = 2;
|
td.colSpan = 2;
|
||||||
}
|
}
|
||||||
// the next icon
|
|
||||||
var td = ea(tr, "td", "", fc.tdIcon, fs.tdIcon);
|
|
||||||
|
|
||||||
function clickPointer (elem , itemName, brName ) {
|
function clickPointer (elem , itemName, brName ) {
|
||||||
elem.addEventListener ('click', function () {
|
elem.addEventListener ('click', function () {
|
||||||
|
@ -450,7 +516,7 @@ function Elementer() {
|
||||||
var backComment = DomUtils.elem(layout.settings.prefix + "-" + d + "-backcomment");
|
var backComment = DomUtils.elem(layout.settings.prefix + "-" + d + "-backcomment");
|
||||||
if (backComment) {
|
if (backComment) {
|
||||||
var lb = DomUtils.fillLabel(layout_.pages[brName].label);
|
var lb = DomUtils.fillLabel(layout_.pages[brName].label);
|
||||||
backComment.innerHTML = "Back to " + lb;
|
backComment.innerHTML = "Back to " + lb ;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
var onEnter = layout_.pages[itemName].on ? layout_.pages[itemName].on.enter : null;
|
var onEnter = layout_.pages[itemName].on ? layout_.pages[itemName].on.enter : null;
|
||||||
|
@ -460,12 +526,17 @@ function Elementer() {
|
||||||
|
|
||||||
// add navigation to next level
|
// add navigation to next level
|
||||||
if (fc.nav.nextIcon) {
|
if (fc.nav.nextIcon) {
|
||||||
|
var td = ea(tr, "td", "", fc.tdNextIcon, fs.tdNextIcon);
|
||||||
|
td.colSpan = 2;
|
||||||
ea(td, "i", fc.nav.nextIcon, fc.icon, fs.icon);
|
ea(td, "i", fc.nav.nextIcon, fc.icon, fs.icon);
|
||||||
clickPointer (tr,d, branchName);
|
clickPointer (tr,d, branchName);
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
|
var td = ea(tr, "td", "", fc.tdIcon, fs.tdIcon);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
// it should be some real stuff
|
// it should be some real stuff
|
||||||
|
|
||||||
if (!details[d]) {
|
if (!details[d]) {
|
||||||
throw d + ' layout reference not found in details';
|
throw d + ' layout reference not found in details';
|
||||||
}
|
}
|
||||||
|
@ -473,108 +544,147 @@ function Elementer() {
|
||||||
throw 'template ' + details[d].template + ' not found';
|
throw 'template ' + details[d].template + ' not found';
|
||||||
}
|
}
|
||||||
var ob = Utils.vanMerge([details[details[d].template], details[d]]);
|
var ob = Utils.vanMerge([details[details[d].template], details[d]]);
|
||||||
|
|
||||||
var fc = Utils.vanMerge([ec, ob.classes]);
|
var fc = Utils.vanMerge([ec, ob.classes]);
|
||||||
var fs = Utils.vanMerge([es, ob.styles]);
|
var fs = Utils.vanMerge([es, ob.styles]);
|
||||||
var tr = ea(tab, "tr", "", fc.tr, fs.tr);
|
|
||||||
|
|
||||||
|
// could be after the table
|
||||||
// the label
|
if (ob.custom && ob.custom.outside) {
|
||||||
if (ob.custom && ob.custom.spanCols) {
|
var tr = ea(dv , "div", "", fc.tr, fs.tr);
|
||||||
|
// the element container
|
||||||
// this element spans all columns
|
var td = ea(tr, "div", "", fc.tdElement, fs.tdElement);
|
||||||
var td = ea(tr, "td", "", fc.tdElement, fs.tdElement);
|
|
||||||
td.colSpan = 3;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
else {
|
else {
|
||||||
|
var tr = ea(tab, "tr", "", fc.tr, fs.tr);
|
||||||
// the icon
|
var used = 0;
|
||||||
|
|
||||||
|
// the icon is the first column
|
||||||
if (ob.icon) {
|
if (ob.icon) {
|
||||||
var td = ea(tr, "td", "", fc.tdIcon, fs.tdIcon);
|
var td = ea(tr, "td", "", fc.tdIcon, fs.tdIcon);
|
||||||
ea(td, "i", ob.icon, fc.icon);
|
ea(td, "i", ob.icon, fc.icon);
|
||||||
|
used++;
|
||||||
}
|
}
|
||||||
var td = ea(tr, "td", "", fc.tdLabel, fs.tdLabel);
|
|
||||||
var label = ob.label ? ea(td, "label", DomUtils.fillLabel(ob.label), fc.label, fs.label) : null;
|
|
||||||
if (!ob.icon) {
|
|
||||||
td.colSpan = 2;
|
|
||||||
}
|
|
||||||
|
|
||||||
// the element
|
|
||||||
var td = ea(tr, "td", "", fc.tdElement, fs.tdElement);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
if (ob.tag) {
|
|
||||||
var ediv = ea(td, "span", "", fc.elementContainer, fs.elementContainer);
|
|
||||||
var elem = ea(ediv, ob.tag, "", fc.element, fs.element);
|
|
||||||
elem.id = dv.id + "-" + d + "-elem";
|
|
||||||
if (label) label['for'] = elem.id;
|
|
||||||
|
|
||||||
|
// now the label
|
||||||
|
var label = null;
|
||||||
|
if (ob.label) {
|
||||||
|
var td = ea(tr, "td", "", fc.tdLabel, fs.tdLabel);
|
||||||
|
var label = ea(td, "label", DomUtils.fillLabel(ob.label), fc.label, fs.label) ;
|
||||||
|
used++;
|
||||||
|
}
|
||||||
|
|
||||||
|
// the element.. if there's a tag we'll need a space for it
|
||||||
|
if (ob.tag) {
|
||||||
|
used++;
|
||||||
|
var td = ea(tr, "td", "", fc.tdElement, fs.tdElement);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
// now create an element
|
||||||
|
var elemCancel = null,elem = null;
|
||||||
|
if (ob.tag) {
|
||||||
|
if (!(ob.custom && ob.custom.cancelOnly)) {
|
||||||
|
var ediv = ea(td, "span", "", fc.elementContainer, fs.elementContainer);
|
||||||
|
var elem = ea(ediv, ob.tag, "", fc.element, fs.element);
|
||||||
|
elem.id = dv.id + "-" + d + "-elem";
|
||||||
|
if (label) label['for'] = elem.id;
|
||||||
|
}
|
||||||
|
// there may be a cancel button needed
|
||||||
|
if (ob.custom && ob.custom.cancelButton) {
|
||||||
|
var ediv = ea (tr, "span", "", fc.elementContainer , fs.elementContainer);
|
||||||
|
var elemCancel = ea (ediv , ob.tag , "", fc.cancel , fs.cancel );
|
||||||
|
elemCancel.id = dv.id + "-" + d + "-elem" + "-cancel";
|
||||||
|
if (ob.custom && ob.custom.backListener) {
|
||||||
|
backListener (elemCancel);
|
||||||
|
}
|
||||||
|
}
|
||||||
// this should only apply to selects
|
// this should only apply to selects
|
||||||
// but i'll leave it unchecked and just do it anyway
|
// but i'll leave it unchecked and just do it anyway
|
||||||
if (ob.options){
|
if (ob.options && elem){
|
||||||
ob.options.forEach(function(g){
|
ob.options.forEach(function(g){
|
||||||
ea (elem,"option",g,fc.option,fs.option).value = g;
|
ea (elem,"option",g,fc.option,fs.option).value = g;
|
||||||
});
|
|
||||||
}
|
|
||||||
if (ob.properties) {
|
|
||||||
Object.keys(ob.properties).forEach(function(e) {
|
|
||||||
elem[e] = ob.properties[e];
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
if (ob.properties && elem) {
|
||||||
|
Object.keys(ob.properties).forEach(function(e) {
|
||||||
|
// now its possible that the propertty doesnt exist for every browser
|
||||||
|
// for example input type="color" will throw exceptin
|
||||||
|
// when running on excel 2016 sidebar so just pass on error with a console.log
|
||||||
|
try {
|
||||||
|
elem[e] = ob.properties[e];
|
||||||
|
}
|
||||||
|
catch (err) {
|
||||||
|
console.log(err + ':continuing and ignoring');
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
if (ob.values && ob.values.property) {
|
}
|
||||||
|
|
||||||
|
if (elemCancel){
|
||||||
|
elemCancel.innerHTML = ob.custom && ob.custom.cancelText ? ob.custom.cancelText : "Cancel";
|
||||||
|
}
|
||||||
|
|
||||||
|
if (elem && ob.values && ob.values.property) {
|
||||||
elem[ob.values.property] = ob.values.value;
|
elem[ob.values.property] = ob.values.value;
|
||||||
elements_.values[d] = ob.values;
|
elements_.values[d] = ob.values;
|
||||||
if(ob.values.resetable) {
|
if(ob.values.resetable) {
|
||||||
initial_[d] = ob.values.value;
|
initial_[d] = ob.values.value;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// now apply any onchange/ click etc.
|
// now apply any onchange/ click etc.
|
||||||
if (ob.on) {
|
if (ob.on && elem) {
|
||||||
Object.keys (ob.on).forEach(function (o) {
|
Object.keys (ob.on).forEach(function (o) {
|
||||||
elem.addEventListener (o , function (e) {
|
elem.addEventListener (o , function (e) {
|
||||||
ob.on[o] (self , branchName , ob , e);
|
ob.on[o] (self , branchName , ob , e);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
elements_.controls[d] = elem;
|
|
||||||
|
if (!(ob.custom && ob.custom.outside)) {
|
||||||
|
// swallow up the rest
|
||||||
|
if (td)td.colSpan = 5 - used ;
|
||||||
|
}
|
||||||
|
elements_.controls[d] = elem || elemCancel;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
standard_ = Utils.clone(initial_);
|
standard_ = Utils.clone(initial_);
|
||||||
return dv;
|
return dv;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function showThis(keep, onEnter) {
|
function showThis(keep, onEnter) {
|
||||||
var dh = DomUtils.hide,
|
var dh = DomUtils.hide,
|
||||||
de = DomUtils.elem,
|
de = DomUtils.elem,
|
||||||
ep = elements_.pages;
|
ep = elements_.pages;
|
||||||
|
|
||||||
// ensure all other pages are hidden
|
// ensure all other pages are hidden
|
||||||
Object.keys(ep).forEach(function(p) {
|
Object.keys(ep).forEach(function(p) {
|
||||||
dh(ep[p], true, classes_.hide);
|
dh(ep[p], true, classes_.hide);
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
// if the active page is the root then show the main too.
|
// if the active page is the root then show the main too.
|
||||||
if (main_) {
|
if (main_) {
|
||||||
var showMain = de(keep).id === ep[layout_.settings.root].id;
|
var showMain = de(keep).id === ep[layout_.settings.root].id;
|
||||||
dh(main_, !showMain, classes_.hide);
|
dh(main_, !showMain, classes_.hide);
|
||||||
}
|
}
|
||||||
|
|
||||||
// do any on enter
|
// do any on enter
|
||||||
if (onEnter) {
|
if (onEnter) {
|
||||||
onEnter(self, de(keep).id.match(/-(.+)$/)[1])
|
onEnter(self, de(keep).id.match(/-(.+)$/)[1])
|
||||||
}
|
}
|
||||||
|
|
||||||
// show the active page
|
// show the active page
|
||||||
dh(keep, false, classes_.hide);
|
dh(keep, false, classes_.hide);
|
||||||
}
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
};
|
};
|
Loading…
Add table
Add a link
Reference in a new issue