simple-ui-builder
Advanced tools
Comparing version 1.0.30 to 1.0.31
{ | ||
"name": "simple-ui-builder", | ||
"version": "1.0.30", | ||
"version": "1.0.31", | ||
"description": "Build user interface like Lego bricks. UI.input(), UI.button(cb), UI.select(arr) etc. For lazy guys as I am.", | ||
@@ -5,0 +5,0 @@ "main": "ui.js", |
78
ui.js
@@ -94,8 +94,8 @@ /** | ||
cb = cb || function() { | ||
console.log("button clicked"); | ||
cb = cb || function(id) { | ||
console.log(id + " clicked"); | ||
}; | ||
if (typeof params == "string") params = { | ||
title: params, | ||
innerHTML: params, | ||
id: params | ||
@@ -132,2 +132,51 @@ }; | ||
UI.buttons = function(arr, cb, params) { | ||
if (!arr || !arr.length) return console.warn("no array to build buttons!"); | ||
if (typeof cb == "object") { | ||
if (typeof params == "function") { | ||
var temp = params; | ||
params = cb; | ||
cb = temp; | ||
} else if (typeof params == "undefined") { | ||
params = cb; | ||
cb = console.log; | ||
} | ||
} | ||
params = params || {}; | ||
cb = cb || function(id) { | ||
console.log(id + " clicked"); | ||
}; | ||
if (typeof params == "string") params = { | ||
innerHTML: params, | ||
id: params | ||
}; | ||
var i = 0; | ||
var l = arr.length; | ||
(function next() { | ||
var item = arr[i]; | ||
if (typeof item == "number") item = item.toString(); | ||
var buttonParams = { | ||
parent: params.parent, | ||
innerHTML: item, | ||
id: item.toLowerCase().replace(/[^\w\d]/g, "-"), | ||
style: { | ||
margin: "2px" | ||
} | ||
}; | ||
UI.button(cb, buttonParams); | ||
i++; | ||
if (i < l) next(); | ||
})(); | ||
}; | ||
UI.br = function(params) { | ||
@@ -167,3 +216,3 @@ | ||
if (!arr) return console.warn("no array to build radios!"); | ||
if (!arr || !arr.length) return console.warn("no array to build radios!"); | ||
@@ -439,3 +488,3 @@ params = params || {}; | ||
if (!arr) return console.warn("no array to build select!"); | ||
if (!arr || !arr.length) return console.warn("no array to build select!"); | ||
@@ -488,3 +537,3 @@ if ((typeof params == "function") && (typeof cb == "object")) { | ||
if(params.default && params.default == item) { | ||
if (params.default && params.default == item) { | ||
option.selected = true; | ||
@@ -499,3 +548,3 @@ } | ||
var selectedOptionNode = document.querySelector("option#" + params.id + "Option" + ":checked"); | ||
if(selectedOptionNode) cb(selectedOptionNode.value); | ||
if (selectedOptionNode) cb(selectedOptionNode.value); | ||
}; | ||
@@ -577,3 +626,5 @@ }; | ||
actionParams.className = ""; | ||
actionParams.style = {margin: "0px"}; | ||
actionParams.style = { | ||
margin: "0px" | ||
}; | ||
@@ -593,3 +644,6 @@ UI.button(actionParams, function() { | ||
clearParams.className = ""; | ||
clearParams.style = {margin: "0px", marginLeft: "5px"}; | ||
clearParams.style = { | ||
margin: "0px", | ||
marginLeft: "5px" | ||
}; | ||
@@ -609,4 +663,6 @@ UI.button(clearParams, function() { | ||
if(typeof arr[0] != "object") arr = arr.map(function (a) { | ||
return {value: a}; | ||
if (typeof arr[0] != "object") arr = arr.map(function(a) { | ||
return { | ||
value: a | ||
}; | ||
}); | ||
@@ -613,0 +669,0 @@ |
25656
612