first commit
This commit is contained in:
298
js/knode.js
Normal file
298
js/knode.js
Normal file
@@ -0,0 +1,298 @@
|
||||
// 노트 엘리먼트 생성
|
||||
function createnode(nodeType, innerText, attr, thistext) {
|
||||
var elem = document.createElement(nodeType);
|
||||
if (innerText !== "" ) {
|
||||
if (Array.isArray(innerText)) {
|
||||
if (thistext) elem.appendChild(document.createTextNode(thistext));
|
||||
innerText.forEach(function (value, id) {
|
||||
var tempElement = ""
|
||||
if(value.hasOwnProperty("element")) {
|
||||
tempElement = createnode(value.element, value.text, value.attr, value.thistext);
|
||||
elem.appendChild(tempElement);
|
||||
} else {
|
||||
elem.appendChild(value);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
if(nodeType === "SELECT") {
|
||||
var opt = document.createElement("OPTION")
|
||||
opt.appendChild(document.createTextNode(innerText))
|
||||
opt.value = ""
|
||||
elem.appendChild(opt)
|
||||
} else {
|
||||
/*
|
||||
var text = document.createTextNode(innerText)
|
||||
elem.appendChild(text)
|
||||
*/
|
||||
//20220126 박준성
|
||||
elem.innerHTML = innerText;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (typeof(attr) === "object") {
|
||||
elem = setAttributes(elem, attr);
|
||||
}
|
||||
return elem
|
||||
}
|
||||
|
||||
|
||||
// 노드에 속성값 부여
|
||||
function setAttributes(el, options) {
|
||||
|
||||
if (!Array.isArray(el) && typeof (el) == "object") {
|
||||
Object.keys(options).forEach(function (attr) {
|
||||
if(attr === "checked") {
|
||||
options[attr] === "true" ? el.setAttribute(attr,"checked") : el.removeAttribute(attr)
|
||||
} else {
|
||||
el.setAttribute(attr, options[attr]);
|
||||
}
|
||||
})
|
||||
} else if (Array.isArray(el)) {
|
||||
el.forEach(function (thisEl) {
|
||||
if(attr === "checked") {
|
||||
options[attr] === "true" ? thisEl.setAttribute(attr,"checked") : thisEl.removeAttribute(attr)
|
||||
} else {
|
||||
thisEl.setAttribute(attr, options[attr]);
|
||||
}
|
||||
})
|
||||
} else {
|
||||
alert('형식이 잘못 되었습니다.')
|
||||
}
|
||||
return el
|
||||
}
|
||||
|
||||
// 여러개의 노드를 노드 타입별로 생성 타입이 하나일경우 하나의 타입으로 innerTexts들의 개수만큼 생성
|
||||
// allOption일 경우 innerTexts를 모든 nodeTypes에 적용
|
||||
|
||||
function createnode_m(nodeTypes, innerTexts, allOption) {
|
||||
var node_arr = []
|
||||
|
||||
if (Array.isArray(nodeTypes)) {
|
||||
if (allOption) {
|
||||
nodeTypes.forEach(function (thisEl, id) {
|
||||
node_arr.push(createnode(thisEl, innerTexts));
|
||||
});
|
||||
} else {
|
||||
|
||||
if (nodeTypes.length != innerTexts.length) {
|
||||
alert("생성 엘리먼트와 텍스트 수가 맞지 않습니다.");
|
||||
return false;
|
||||
}
|
||||
nodeTypes.forEach(function (thisEl, id) {
|
||||
node_arr.push(createnode(thisEl, innerTexts[id]));
|
||||
});
|
||||
}
|
||||
return node_arr
|
||||
} else if (!Array.isArray(nodeTypes) && Array.isArray(innerTexts)) {
|
||||
innerTexts.forEach(function (thisEl) {
|
||||
node_arr.push(createnode(nodeTypes, thisEl));
|
||||
});
|
||||
return node_arr
|
||||
} else if (typeof (nodeTypes) === "string" && typeof (innerTexts) === "string") {
|
||||
return createnode(nodeTypes, innerTexts);
|
||||
} else {
|
||||
alert('형식이 잘못 되었습니다.')
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// appendChild 한번에 여러개하기 attr은 모든 childnodes에 속성값.
|
||||
function appendChild_m(target, childnodes, attr) {
|
||||
var add_childnodes_attr;
|
||||
|
||||
if (!Array.isArray(childnodes) && typeof (childnodes) === "string") {
|
||||
if (attr !== undefined) {
|
||||
add_childnodes_attr = setAttributes(childnodes, attr);
|
||||
target.appendChild(add_childnodes_attr);
|
||||
} else {
|
||||
target.appendChild(childnodes)
|
||||
}
|
||||
} else {
|
||||
childnodes.forEach(function (el) {
|
||||
if (Array.isArray(el)) appendChild_m(target, el)
|
||||
if (attr !== undefined) {
|
||||
add_childnodes_attr = setAttributes(el, attr);
|
||||
target.appendChild(add_childnodes_attr);
|
||||
} else {
|
||||
target.appendChild(el)
|
||||
}
|
||||
})
|
||||
}
|
||||
return target;
|
||||
}
|
||||
|
||||
|
||||
function getById(id) {
|
||||
return document.getElementById(id)
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @date 2020-03-10
|
||||
* @param {*} type
|
||||
* @param {*} id
|
||||
* @param {*} text
|
||||
* @returns
|
||||
*/
|
||||
function form_inline_input(type, id, text, attr) {
|
||||
var a = {
|
||||
"element": "DIV",
|
||||
"text": [
|
||||
{
|
||||
"element": "INPUT",
|
||||
"text": "",
|
||||
"attr": { "type": type, "class": "form-check form-check-input", "id": id }
|
||||
},
|
||||
{
|
||||
"element": "label",
|
||||
"text": text,
|
||||
"attr": { "class": "form-check form-check-label", "for": id }
|
||||
}
|
||||
],
|
||||
"attr": { "class": "form-check form-check-inline" }
|
||||
}
|
||||
|
||||
if(attr) Object.assign(a["text"][0].attr,attr);
|
||||
|
||||
return a;
|
||||
}
|
||||
|
||||
function input_box(input, chk , option ) {
|
||||
if(!chk) chk = "false";
|
||||
var a = {
|
||||
"element": "label",
|
||||
"text": [
|
||||
{
|
||||
"element": "INPUT",
|
||||
"text": "",
|
||||
"attr": { "type": input.type, "class": to_blank(input.class) , "checked":chk}
|
||||
}
|
||||
],
|
||||
"thistext" : input.text
|
||||
}
|
||||
|
||||
if(option === "node")
|
||||
a = createnode("span",[a]);
|
||||
|
||||
return a;
|
||||
}
|
||||
|
||||
|
||||
function make_input_text(op,name,attr) {
|
||||
var input = []
|
||||
if(op.prev) {
|
||||
input.push({
|
||||
"element":"div",
|
||||
"text":[
|
||||
{"element" : "span" , "attr" : {"class":"input-group-text"} , "text" : op.prev}
|
||||
],
|
||||
"attr":{"class":"input-group-prepend"}
|
||||
})
|
||||
}
|
||||
input.push(
|
||||
{
|
||||
"element" : "INPUT",
|
||||
"text" : "",
|
||||
"attr" : {"class":"form-control d-inline-block","type":op.type ,"onkeyup":op.onkeyup || "", "onchange": op.onchange || "" ,"name":name, "placeholder":op.text || "","id":name}
|
||||
}
|
||||
)
|
||||
if(op.after) {
|
||||
input.push({
|
||||
"element":"div",
|
||||
"text":[
|
||||
{"element" : "span" , "attr" : {"class":"input-group-text"} , "text" : op.after}
|
||||
],
|
||||
"attr":{"class":"input-group-appened"}
|
||||
})
|
||||
}
|
||||
|
||||
return {
|
||||
"element" : "DIV",
|
||||
"text" : input,
|
||||
"attr" : attr === undefined ? {"class":"input-group"} : attr
|
||||
}
|
||||
}
|
||||
|
||||
function make_container(cols) { /* 컨테이너 만들기 */
|
||||
var co = createnode("div","",{"class":"container-fluid"})
|
||||
var r = createnode("div","",{"class":"row"})
|
||||
var c = []
|
||||
cols.forEach(function(col,index){
|
||||
c.push(createnode("div","",{"class":col}));
|
||||
r.appendChild(c[index]);
|
||||
})
|
||||
co.appendChild(r)
|
||||
return {
|
||||
"getcontainer": function(){
|
||||
return co;
|
||||
},
|
||||
"getcolList" : function() {
|
||||
return c;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function make_datalist(list) {
|
||||
var listid = ID();
|
||||
var obj = {"input":"","list":""}
|
||||
var input = createnode("input","",{"type":"text","list":listid,"style":"width:120px;"});
|
||||
var dlist = list.map(function(ele){return createnode("option",ele,{"value":ele})});
|
||||
var datalist = createnode("datalist",dlist,{"id":listid});
|
||||
obj.input = input;
|
||||
obj.list = datalist;
|
||||
return obj;
|
||||
}
|
||||
|
||||
/* dnum - 문서 수, drange - 보여질 문서 수, prange - 보여질 페이지 수 ,bsize - 버튼 사이즈 */
|
||||
function make_paging(dnum, drange, prange, bsize) {
|
||||
|
||||
var size = +(bsize || 20);
|
||||
var range = +(prange || 10);
|
||||
var trange = Math.ceil(dnum / drange);
|
||||
|
||||
if( range > trange) {
|
||||
range = trange;
|
||||
}
|
||||
|
||||
var pagetable = createnode("table","");
|
||||
var left = createnode("td",[createnode("i","",{"class":"fa fa-caret-left","aria-hidden":"true"})],{"style":"cursor:pointer;width:25px","class":"text-primary text-center "});
|
||||
var pagetd = createnode("td","");
|
||||
var right = createnode("td",[createnode("i","",{"class":"fa fa-caret-right","aria-hidden":"true"})],{"style":"cursor:pointer;width:25px","class":"text-primary text-center "});
|
||||
var pagingdiv = createnode("div","",{"class":"","id":"pagenation","style":"width:"+(range * size)+"px"})
|
||||
|
||||
Array(trange).fill("").forEach(function(v,i){
|
||||
var pbtn = createnode("div",i+1,{"class":"p-1 paging-item border rounded text-center d-inline-block position-relative","style":"width:"+size+"px;height:"+size+"px;" });
|
||||
if(!i) $(pbtn).addClass("paging-item-selected");
|
||||
pagingdiv.appendChild(pbtn);
|
||||
});
|
||||
|
||||
pagetd.appendChild(pagingdiv)
|
||||
pagetable.appendChild(createnode("tr",[left,pagetd,right]));
|
||||
$(pagingdiv).css({
|
||||
"white-space":"nowrap",
|
||||
"overflow-x" : "hidden",
|
||||
"width": (range * bsize)+"px"
|
||||
})
|
||||
|
||||
$(left).click(function(){
|
||||
$(pagingdiv).animate({scrollLeft:pagingdiv.scrollLeft-(size * range)},70);
|
||||
});
|
||||
|
||||
$(right).click(function(){
|
||||
$(pagingdiv).animate({scrollLeft:pagingdiv.scrollLeft+(size * range)},70);
|
||||
});
|
||||
|
||||
return pagetable;
|
||||
}
|
||||
|
||||
function make_select(name,optionlist){
|
||||
var select = createnode("SELECT","",{"class":"form-control","name":name});
|
||||
select.appendChild(createnode("OPTION","선택",{"value":""}));
|
||||
optionlist.forEach(function(v,id){
|
||||
select.appendChild(createnode("OPTION",v.label,{"value":v.value}));
|
||||
})
|
||||
return select;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user