-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy paththin.min.js
1 lines (1 loc) · 7.46 KB
/
thin.min.js
1
function poplayer(t){var e=document.createElement("popmask");e.style.zIndex=1e3;var n,i=document.createElement("popdialog");if(i.style.width="number"==typeof t.width?t.width+"px":t.width,e.appendChild(i),void 0!==t.header){n=document.createElement("popheader"),$(n).html(t.header);var a=document.createElement("closeicon");a.innerText="✕",a.onclick=function(){void 0!==t.onclose&&t.onclose(),$(e).remove()},a.onmouseover=function(){this.style.filter="alpha(opacity=80)",this.style.opacity=".8"},a.onmouseout=function(){this.style.filter="alpha(opacity=50)",this.style.opacity=".5"},n.appendChild(a),i.appendChild(n)}var o=document.createElement("popbody");switch(typeof t.height){case"string":o.style.height=t.height;break;case"number":o.style.height=t.height+"px";break;default:o.style.maxHeight="600px"}o.style.overflowY="scroll",i.appendChild(o),document.body.appendChild(e),void 0!==t.render?t.render({container:o}):$(o).render({data:t.data,template:t.template}),popDrag(n,i)}function popDrag(t,e,n){var i={left:0,top:0,currentX:0,currentY:0,flag:!1,resetPosition:function(){var t=$(e).css("left"),n=$(e).css("top");"auto"!==t&&(this.left=t),"auto"!==n&&(this.top=n)}};i.resetPosition(),t.onmousedown=function(e){i.flag=!0,e||(e=window.event,t.onselectstart=function(){return!1});var n=e;i.currentX=n.clientX,i.currentY=n.clientY},document.onmouseup=function(){i.flag=!1,i.resetPosition()},document.onmousemove=function(t){var a=t||window.event;if(i.flag){var o=a.clientX,c=a.clientY,r=o-i.currentX,l=c-i.currentY;return e.style.left=parseInt(i.left)+r+"px",e.style.top=parseInt(i.top)+l+"px","function"==typeof n&&n((parseInt(i.left)||0)+r,(parseInt(i.top)||0)+l),t.preventDefault&&t.preventDefault(),!1}}}$(function(){$(document).on("click","tab-nav",function(){$("tab-nav",this.parentElement).removeClass("active"),$(this).addClass("active");let t=this.getAttribute("function");"function"==typeof window[t]&&window[t]();var e=this.getAttribute("view");if(null!==e){var n=$(this).parents("multiview:first");$("view",n).removeClass("active"),$("view#"+e,n).addClass("active")}})}),$.fn.extend({render:function(t){function e(t){Array.isArray(t.d)?t.d.forEach(e=>{n({c:t.c,t:t.t,d:e})}):n({c:t.c,t:t.t,d:t.d})}function n(t){Array.isArray(t.t)?t.t.forEach(e=>{i({t:e,c:t.c,d:t.d})}):i({t:t.t,c:t.c,d:t.d})}function i(t){if("string"==typeof t.t){let e=document.createDocumentFragment();$(e).append(o({t:t.t,c:t.c})),t.c.appendChild(e)}else if("[object Object]"===Object.prototype.toString.call(t.t))a({c:t.c,t:t.t,d:t.d});else if("function"==typeof t.t){let e=c(t.c);t.t({container:t.c,data:e?e.data_of_thin:void 0})}else console.log(Object.prototype.toString.call(t.t))}function a(t){if(void 0!==t.t.datapath&&void 0===t.d){let n=r({container:t.c,path:t.t.datapath});null!==n&&e({c:t.c,d:n,t:t.t})}else{if(void 0!==t.t.if)switch(typeof t.t.if){case"function":t.t.if({container:t.c,data:t.t.data?t.t.data:t.data})?n({c:t.c,t:t.t.then}):t.t.else&&n({c:t.c,t:t.t.else});break;default:t.t.if?n({c:t.c,t:t.t.then}):t.t.else&&n({c:t.c,t:t.t.else})}else if(void 0!==t.t.switch){let e="function"==typeof t.t.switch?t.t.switch({container:t.c,data:t.t.data?t.t.data:t.data}):o({t:t.t.switch,c:t.c});void 0===t.t.case||(void 0!==t.t.case[e]?n({c:t.c,t:t.t.case[e]}):void 0!==t.t.case.default&&n({c:t.c,t:t.t.case.default}))}else if(void 0!==t.t.foreach){let n=null;"function"==typeof t.t.foreach?n=t.t.foreach({container:t.c,data:t.d}):"string"==typeof t.t.foreach?n=r({container:t.c,path:t.t.foreach}):Array.isArray(t.t.foreach)&&(n=t.t.foreach),n&&e({c:t.c,d:n,t:t.t.t})}else t.c&&i();function i(){let e=document.createElement(t.t.e?t.t.e:"div"),i=c(e);if(t.c.appendChild(e),t.t.data?e.data_of_thin=t.t.data:void 0!==t.d&&(e.data_of_thin=t.d),void 0!==t.t.name&&e.setAttribute("name",t.t.name),void 0!==t.t.id&&e.setAttribute("id",t.t.id),void 0!==t.t.class&&e.setAttribute("class",t.t.class),void 0!==t.t.width&&e.style.setProperty("width","number"==typeof t.t.width?t.t.width+"px":t.t.width),void 0!==t.t.height&&e.style.setProperty("height","number"==typeof t.t.height?t.t.height+"px":t.t.height),void 0!==t.t.options&&(Array.isArray(t.t.options)?t.t.options.forEach(t=>{e.options.add(new Option(t))}):"string"==typeof t.t.options&&t.t.options.split(",").forEach(t=>{e.options.add(new Option(t))})),void 0!==t.t.selected&&$(e).val(o({t:t.t.selected,c:e})),void 0!==t.t.value&&$(e).val(o({t:t.t.value,c:e})),t.t.bind&&i){let n=i.data_of_thin,a=t.t.bind.split("/");for(let t=0;t<a.length-1;t++)n=n[a[t]];$(e).val(n[a[a.length-1]]),$(e).on("change",t=>{let n=i.data_of_thin;for(let t=0;t<a.length-1;t++)n[a[t]]||(n[a[t]]={}),n=n[a[t]];n[a[a.length-1]]=$(e).val(),console.log(i.data_of_thin)})}switch(void 0!==t.t.click&&(e.onclick=function(){let e=c(this),n={};null!==e&&($("input",e).each(function(t,e){if(void 0!==this.attributes.name){let t=this.attributes.name.value;n[t]=$(this).val()}}),$("select",e).each(function(t,e){if(void 0!==this.attributes.name){let t=this.attributes.name.value;n[t]=$(this).val()}}),$("textarea",e).each(function(t,e){if(void 0!==this.attributes.name){let t=this.attributes.name.value;n[t]=$(this).val()}})),t.t.click({sender:this,org_data:e.data_of_thin,new_data:n})}),void 0!==t.t.event&&Object.keys(t.t.event).forEach(function(n){$(e).on(n,function(e){let n=c(this),i=new Object;$("input",n).each(function(t,e){if(void 0!==this.attributes.name){let t=this.attributes.name.value;i[t]=$(this).val()}}),$("select",n).each(function(t,e){if(void 0!==this.attributes.name){let t=this.attributes.name.value;i[t]=$(this).val()}}),$("textarea",n).each(function(t,e){if(void 0!==this.attributes.name){let t=this.attributes.name.value;i[t]=$(this).val()}}),t.t.event[e.type]({sender:this,type:e.type,event:e,org_data:n.data_of_thin,new_data:i})})}),t.t.e){case"fieldset":if(t.t.title){let n=document.createElement("legend");n.innerText=o({t:t.t.title,c:e}),e.appendChild(n)}break;case"field":case"f1":case"f2":case"f3":if(t.t.title){let n=document.createElement("label");n.innerText=o({t:t.t.title,c:e}),e.appendChild(n)}}void 0!==t.t.t&&n({c:e,t:t.t.t}),void 0!==t.t.a&&Object.keys(t.t.a).forEach(function(n){"function"==typeof t.t.a[n]?e.setAttribute(n,t.t.a[n]({container:e,data:i.data_of_thin})):e.setAttribute(n,o({t:t.t.a[n],c:e}))}),void 0!==t.t.style&&Object.keys(t.t.style).forEach(function(n){"function"==typeof t.t.style[n]?e.style.setProperty(n,t.t.style[n]({container:e,data:i.data_of_thin})):e.style.setProperty(n,o({t:t.t.style[n],c:e}))})}}}function o(t){var e=t.t,n=/\[\[[a-zA-Z0-9\-\.\/_]*\]\]/gi,i="string"!=typeof e?e:e.replace(n,function(e){for(var n=e.replace("[[","").replace("]]",""),i=n.split("/"),a=c(t.c),o=0;o<i.length;o++)if(".."===i[o]){if(!l(a))return e;a=c(a.parentNode)}else{if(l(a)){if(void 0===a.data_of_thin)return e;a=a.data_of_thin}if(null===a)return null;a=a[i[o]]}return null==a?"":a});return i}function c(t){for(;!t.hasOwnProperty("data_of_thin");){if(null===t.parentNode)return null;t=t.parentNode}return t}function r(t){let e=t.path.split("/"),n=c(t.container);for(let t=0;t<e.length;t++)if(".."===e[t]){if(!l(n))return null;n=c(n.parentNode)}else{if(l(n)){if(void 0===n.data_of_thin)return null;n=n.data_of_thin}if(null===n)return null;if(!(e[t]in n))return null;n=n[e[t]]}return n}function l(t){return!(!t||"undefined"==typeof window||t!==window&&!t.nodeType)}void 0===t.data&&(t.data={}),Array.isArray(t.template)||Array.isArray(t.data)||"[object Object]"===Object.prototype.toString.call(t.template)?e({c:this[0],t:t.template,d:t.data}):(this[0].data_of_thin=t.data,n({c:this[0],t:t.template}))}}),poplayer.close=function(t){console.log({pos:"poplayer.close",element:t})};