Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

a-template

Package Overview
Dependencies
Maintainers
2
Versions
48
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

a-template - npm Package Compare versions

Comparing version 0.5.5 to 0.6.0

41

build/a-template.js

@@ -8,3 +8,3 @@ /**

* author: steelydylan
* version: 0.5.3
* version: 0.5.5
*

@@ -778,2 +778,3 @@ * ie-array-find-polyfill:

this.atemplate = [];
this.events = [];
if (opt) {

@@ -826,2 +827,7 @@ Object.keys(opt).forEach(function (key) {

});
this.events.push({
element: ele,
selector: '[data-bind]',
event: bindType
});
}

@@ -860,4 +866,16 @@ }, {

});
this.events.push({
element: ele,
selector: dataAction,
event: bindType
});
}
}, {
key: 'removeTemplateEvents',
value: function removeTemplateEvents() {
this.events.forEach(function (event) {
(0, _util.off)(event.element, event.selector, event.event);
});
}
}, {
key: 'addTemplate',

@@ -1361,7 +1379,10 @@ value: function addTemplate(id, html) {

var listenerList = [];
var on = exports.on = function on(element, query, eventNames, fn) {
var capture = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : false;
var events = eventNames.split(' ');
events.forEach(function (event) {
element.addEventListener(event, function (e) {
var target = e.target;
var listener = function listener(e) {
var delegateTarget = findAncestor(e.target, query);

@@ -1372,2 +1393,16 @@ if (delegateTarget) {

}
};
listenerList.push({ listener: listener, element: element, query: query, event: event, capture: capture });
element.addEventListener(event, listener, capture);
});
};
var off = exports.off = function off(element, query, eventNames) {
var events = eventNames.split(' ');
events.forEach(function (event) {
listenerList.forEach(function (item, index) {
if (item.element === element && item.query === query && item.event === event) {
element.removeEventListener(event, item.listener, item.capture);
listenerList.splice(index, 1);
}
});

@@ -1374,0 +1409,0 @@ });

4

build/a-template.min.js

@@ -8,3 +8,3 @@ /**

* author: steelydylan
* version: 0.5.3
* version: 0.5.5
*

@@ -27,2 +27,2 @@ * ie-array-find-polyfill:

*/
(function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.aTemplate=f()}})(function(){var define,module,exports;return function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s}({1:[function(require,module,exports){"use strict";if(!Array.prototype.find){Object.defineProperty(Array.prototype,"find",{value:function(predicate){if(this==null){throw new TypeError("this is null or not defined")}var obj=Object(this);var len=obj.length>>>0;if(typeof predicate!=="function"){throw new TypeError("predicate must be a function")}var thisArg=arguments[1];var index=0;while(index<len){var iValue=obj[index];if(predicate.call(thisArg,iValue,index,obj)){return iValue}index++}return undefined}})}},{}],2:[function(require,module,exports){"use strict";var range;var NS_XHTML="http://www.w3.org/1999/xhtml";var doc=typeof document==="undefined"?undefined:document;var testEl=doc?doc.body||doc.createElement("div"):{};var actualHasAttributeNS;if(testEl.hasAttributeNS){actualHasAttributeNS=function(el,namespaceURI,name){return el.hasAttributeNS(namespaceURI,name)}}else if(testEl.hasAttribute){actualHasAttributeNS=function(el,namespaceURI,name){return el.hasAttribute(name)}}else{actualHasAttributeNS=function(el,namespaceURI,name){return el.getAttributeNode(namespaceURI,name)!=null}}var hasAttributeNS=actualHasAttributeNS;function toElement(str){if(!range&&doc.createRange){range=doc.createRange();range.selectNode(doc.body)}var fragment;if(range&&range.createContextualFragment){fragment=range.createContextualFragment(str)}else{fragment=doc.createElement("body");fragment.innerHTML=str}return fragment.childNodes[0]}function compareNodeNames(fromEl,toEl){var fromNodeName=fromEl.nodeName;var toNodeName=toEl.nodeName;if(fromNodeName===toNodeName){return true}if(toEl.actualize&&fromNodeName.charCodeAt(0)<91&&toNodeName.charCodeAt(0)>90){return fromNodeName===toNodeName.toUpperCase()}else{return false}}function createElementNS(name,namespaceURI){return!namespaceURI||namespaceURI===NS_XHTML?doc.createElement(name):doc.createElementNS(namespaceURI,name)}function moveChildren(fromEl,toEl){var curChild=fromEl.firstChild;while(curChild){var nextChild=curChild.nextSibling;toEl.appendChild(curChild);curChild=nextChild}return toEl}function morphAttrs(fromNode,toNode){var attrs=toNode.attributes;var i;var attr;var attrName;var attrNamespaceURI;var attrValue;var fromValue;for(i=attrs.length-1;i>=0;--i){attr=attrs[i];attrName=attr.name;attrNamespaceURI=attr.namespaceURI;attrValue=attr.value;if(attrNamespaceURI){attrName=attr.localName||attrName;fromValue=fromNode.getAttributeNS(attrNamespaceURI,attrName);if(fromValue!==attrValue){fromNode.setAttributeNS(attrNamespaceURI,attrName,attrValue)}}else{fromValue=fromNode.getAttribute(attrName);if(fromValue!==attrValue){fromNode.setAttribute(attrName,attrValue)}}}attrs=fromNode.attributes;for(i=attrs.length-1;i>=0;--i){attr=attrs[i];if(attr.specified!==false){attrName=attr.name;attrNamespaceURI=attr.namespaceURI;if(attrNamespaceURI){attrName=attr.localName||attrName;if(!hasAttributeNS(toNode,attrNamespaceURI,attrName)){fromNode.removeAttributeNS(attrNamespaceURI,attrName)}}else{if(!hasAttributeNS(toNode,null,attrName)){fromNode.removeAttribute(attrName)}}}}}function syncBooleanAttrProp(fromEl,toEl,name){if(fromEl[name]!==toEl[name]){fromEl[name]=toEl[name];if(fromEl[name]){fromEl.setAttribute(name,"")}else{fromEl.removeAttribute(name,"")}}}var specialElHandlers={OPTION:function(fromEl,toEl){syncBooleanAttrProp(fromEl,toEl,"selected")},INPUT:function(fromEl,toEl){syncBooleanAttrProp(fromEl,toEl,"checked");syncBooleanAttrProp(fromEl,toEl,"disabled");if(fromEl.value!==toEl.value){fromEl.value=toEl.value}if(!hasAttributeNS(toEl,null,"value")){fromEl.removeAttribute("value")}},TEXTAREA:function(fromEl,toEl){var newValue=toEl.value;if(fromEl.value!==newValue){fromEl.value=newValue}var firstChild=fromEl.firstChild;if(firstChild){var oldValue=firstChild.nodeValue;if(oldValue==newValue||!newValue&&oldValue==fromEl.placeholder){return}firstChild.nodeValue=newValue}},SELECT:function(fromEl,toEl){if(!hasAttributeNS(toEl,null,"multiple")){var selectedIndex=-1;var i=0;var curChild=toEl.firstChild;while(curChild){var nodeName=curChild.nodeName;if(nodeName&&nodeName.toUpperCase()==="OPTION"){if(hasAttributeNS(curChild,null,"selected")){selectedIndex=i;break}i++}curChild=curChild.nextSibling}fromEl.selectedIndex=i}}};var ELEMENT_NODE=1;var TEXT_NODE=3;var COMMENT_NODE=8;function noop(){}function defaultGetNodeKey(node){return node.id}function morphdomFactory(morphAttrs){return function morphdom(fromNode,toNode,options){if(!options){options={}}if(typeof toNode==="string"){if(fromNode.nodeName==="#document"||fromNode.nodeName==="HTML"){var toNodeHtml=toNode;toNode=doc.createElement("html");toNode.innerHTML=toNodeHtml}else{toNode=toElement(toNode)}}var getNodeKey=options.getNodeKey||defaultGetNodeKey;var onBeforeNodeAdded=options.onBeforeNodeAdded||noop;var onNodeAdded=options.onNodeAdded||noop;var onBeforeElUpdated=options.onBeforeElUpdated||noop;var onElUpdated=options.onElUpdated||noop;var onBeforeNodeDiscarded=options.onBeforeNodeDiscarded||noop;var onNodeDiscarded=options.onNodeDiscarded||noop;var onBeforeElChildrenUpdated=options.onBeforeElChildrenUpdated||noop;var childrenOnly=options.childrenOnly===true;var fromNodesLookup={};var keyedRemovalList;function addKeyedRemoval(key){if(keyedRemovalList){keyedRemovalList.push(key)}else{keyedRemovalList=[key]}}function walkDiscardedChildNodes(node,skipKeyedNodes){if(node.nodeType===ELEMENT_NODE){var curChild=node.firstChild;while(curChild){var key=undefined;if(skipKeyedNodes&&(key=getNodeKey(curChild))){addKeyedRemoval(key)}else{onNodeDiscarded(curChild);if(curChild.firstChild){walkDiscardedChildNodes(curChild,skipKeyedNodes)}}curChild=curChild.nextSibling}}}function removeNode(node,parentNode,skipKeyedNodes){if(onBeforeNodeDiscarded(node)===false){return}if(parentNode){parentNode.removeChild(node)}onNodeDiscarded(node);walkDiscardedChildNodes(node,skipKeyedNodes)}function indexTree(node){if(node.nodeType===ELEMENT_NODE){var curChild=node.firstChild;while(curChild){var key=getNodeKey(curChild);if(key){fromNodesLookup[key]=curChild}indexTree(curChild);curChild=curChild.nextSibling}}}indexTree(fromNode);function handleNodeAdded(el){onNodeAdded(el);var curChild=el.firstChild;while(curChild){var nextSibling=curChild.nextSibling;var key=getNodeKey(curChild);if(key){var unmatchedFromEl=fromNodesLookup[key];if(unmatchedFromEl&&compareNodeNames(curChild,unmatchedFromEl)){curChild.parentNode.replaceChild(unmatchedFromEl,curChild);morphEl(unmatchedFromEl,curChild)}}handleNodeAdded(curChild);curChild=nextSibling}}function morphEl(fromEl,toEl,childrenOnly){var toElKey=getNodeKey(toEl);var curFromNodeKey;if(toElKey){delete fromNodesLookup[toElKey]}if(toNode.isSameNode&&toNode.isSameNode(fromNode)){return}if(!childrenOnly){if(onBeforeElUpdated(fromEl,toEl)===false){return}morphAttrs(fromEl,toEl);onElUpdated(fromEl);if(onBeforeElChildrenUpdated(fromEl,toEl)===false){return}}if(fromEl.nodeName!=="TEXTAREA"){var curToNodeChild=toEl.firstChild;var curFromNodeChild=fromEl.firstChild;var curToNodeKey;var fromNextSibling;var toNextSibling;var matchingFromEl;outer:while(curToNodeChild){toNextSibling=curToNodeChild.nextSibling;curToNodeKey=getNodeKey(curToNodeChild);while(curFromNodeChild){fromNextSibling=curFromNodeChild.nextSibling;if(curToNodeChild.isSameNode&&curToNodeChild.isSameNode(curFromNodeChild)){curToNodeChild=toNextSibling;curFromNodeChild=fromNextSibling;continue outer}curFromNodeKey=getNodeKey(curFromNodeChild);var curFromNodeType=curFromNodeChild.nodeType;var isCompatible=undefined;if(curFromNodeType===curToNodeChild.nodeType){if(curFromNodeType===ELEMENT_NODE){if(curToNodeKey){if(curToNodeKey!==curFromNodeKey){if(matchingFromEl=fromNodesLookup[curToNodeKey]){if(curFromNodeChild.nextSibling===matchingFromEl){isCompatible=false}else{fromEl.insertBefore(matchingFromEl,curFromNodeChild);fromNextSibling=curFromNodeChild.nextSibling;if(curFromNodeKey){addKeyedRemoval(curFromNodeKey)}else{removeNode(curFromNodeChild,fromEl,true)}curFromNodeChild=matchingFromEl}}else{isCompatible=false}}}else if(curFromNodeKey){isCompatible=false}isCompatible=isCompatible!==false&&compareNodeNames(curFromNodeChild,curToNodeChild);if(isCompatible){morphEl(curFromNodeChild,curToNodeChild)}}else if(curFromNodeType===TEXT_NODE||curFromNodeType==COMMENT_NODE){isCompatible=true;if(curFromNodeChild.nodeValue!==curToNodeChild.nodeValue){curFromNodeChild.nodeValue=curToNodeChild.nodeValue}}}if(isCompatible){curToNodeChild=toNextSibling;curFromNodeChild=fromNextSibling;continue outer}if(curFromNodeKey){addKeyedRemoval(curFromNodeKey)}else{removeNode(curFromNodeChild,fromEl,true)}curFromNodeChild=fromNextSibling}if(curToNodeKey&&(matchingFromEl=fromNodesLookup[curToNodeKey])&&compareNodeNames(matchingFromEl,curToNodeChild)){fromEl.appendChild(matchingFromEl);morphEl(matchingFromEl,curToNodeChild)}else{var onBeforeNodeAddedResult=onBeforeNodeAdded(curToNodeChild);if(onBeforeNodeAddedResult!==false){if(onBeforeNodeAddedResult){curToNodeChild=onBeforeNodeAddedResult}if(curToNodeChild.actualize){curToNodeChild=curToNodeChild.actualize(fromEl.ownerDocument||doc)}fromEl.appendChild(curToNodeChild);handleNodeAdded(curToNodeChild)}}curToNodeChild=toNextSibling;curFromNodeChild=fromNextSibling}while(curFromNodeChild){fromNextSibling=curFromNodeChild.nextSibling;if(curFromNodeKey=getNodeKey(curFromNodeChild)){addKeyedRemoval(curFromNodeKey)}else{removeNode(curFromNodeChild,fromEl,true)}curFromNodeChild=fromNextSibling}}var specialElHandler=specialElHandlers[fromEl.nodeName];if(specialElHandler){specialElHandler(fromEl,toEl)}}var morphedNode=fromNode;var morphedNodeType=morphedNode.nodeType;var toNodeType=toNode.nodeType;if(!childrenOnly){if(morphedNodeType===ELEMENT_NODE){if(toNodeType===ELEMENT_NODE){if(!compareNodeNames(fromNode,toNode)){onNodeDiscarded(fromNode);morphedNode=moveChildren(fromNode,createElementNS(toNode.nodeName,toNode.namespaceURI))}}else{morphedNode=toNode}}else if(morphedNodeType===TEXT_NODE||morphedNodeType===COMMENT_NODE){if(toNodeType===morphedNodeType){if(morphedNode.nodeValue!==toNode.nodeValue){morphedNode.nodeValue=toNode.nodeValue}return morphedNode}else{morphedNode=toNode}}}if(morphedNode===toNode){onNodeDiscarded(fromNode)}else{morphEl(morphedNode,toNode,childrenOnly);if(keyedRemovalList){for(var i=0,len=keyedRemovalList.length;i<len;i++){var elToRemove=fromNodesLookup[keyedRemovalList[i]];if(elToRemove){removeNode(elToRemove,elToRemove.parentNode,false)}}}}if(!childrenOnly&&morphedNode!==fromNode&&fromNode.parentNode){if(morphedNode.actualize){morphedNode=morphedNode.actualize(fromNode.ownerDocument||doc)}fromNode.parentNode.replaceChild(morphedNode,fromNode)}return morphedNode}}var morphdom=morphdomFactory(morphAttrs);module.exports=morphdom},{}],3:[function(require,module,exports){"use strict";Object.defineProperty(exports,"__esModule",{value:true});var _createClass=function(){function defineProperties(target,props){for(var i=0;i<props.length;i++){var descriptor=props[i];descriptor.enumerable=descriptor.enumerable||false;descriptor.configurable=true;if("value"in descriptor)descriptor.writable=true;Object.defineProperty(target,descriptor.key,descriptor)}}return function(Constructor,protoProps,staticProps){if(protoProps)defineProperties(Constructor.prototype,protoProps);if(staticProps)defineProperties(Constructor,staticProps);return Constructor}}();require("ie-array-find-polyfill");var _morphdom=require("morphdom");var _morphdom2=_interopRequireDefault(_morphdom);var _util=require("./util");function _interopRequireDefault(obj){return obj&&obj.__esModule?obj:{"default":obj}}function _toConsumableArray(arr){if(Array.isArray(arr)){for(var i=0,arr2=Array(arr.length);i<arr.length;i++){arr2[i]=arr[i]}return arr2}else{return Array.from(arr)}}function _classCallCheck(instance,Constructor){if(!(instance instanceof Constructor)){throw new TypeError("Cannot call a class as a function")}}var eventType="input paste copy click change keydown keyup keypress contextmenu mouseup mousedown mousemove touchstart touchend touchmove compositionstart compositionend focus";var bindType="input change click";var dataAction=eventType.replace(/([a-z]+)/g,"[data-action-$1],")+"[data-action]";var aTemplate=function(){function aTemplate(opt){var _this=this;_classCallCheck(this,aTemplate);this.atemplate=[];if(opt){Object.keys(opt).forEach(function(key){_this[key]=opt[key]})}if(!this.data){this.data={}}if(!this.templates){this.templates=[]}var templates=this.templates;var length=templates.length;for(var i=0,n=length;i<n;i+=1){var template=this.templates[i];var html=(0,_util.selector)("#"+template).innerHTML;this.atemplate.push({id:template,html:html,binded:false})}}_createClass(aTemplate,[{key:"addDataBind",value:function addDataBind(ele){var _this2=this;(0,_util.on)(ele,"[data-bind]",bindType,function(e){var target=e.delegateTarget;var data=target.getAttribute("data-bind");var attr=target.getAttribute("href");var value=target.value;if(attr){value=value.replace("#","")}if(target.getAttribute("type")==="checkbox"){(function(){var arr=[];var items=document.querySelectorAll('[data-bind="'+data+'"]');[].forEach.call(items,function(item){if(item.checked){arr.push(item.value)}})})()}else if(target.getAttribute("type")!=="radio"){_this2.updateDataByString(data,value)}})}},{key:"addActionBind",value:function addActionBind(ele){var _this3=this;(0,_util.on)(ele,dataAction,eventType,function(e){var target=e.delegateTarget;var events=eventType.split(" ");var action="action";events.forEach(function(event){if(target.getAttribute("data-action-"+event)){if(e.type===event){action+="-"+event}}});var string=target.getAttribute("data-"+action);if(!string){return}var method=string.replace(/\(.*?\);?/,"");var parameter=string.replace(/(.*?)\((.*?)\);?/,"$2");var pts=parameter.split(",");_this3.e=e;if(_this3.method&&_this3.method[method]){var _method;(_method=_this3.method)[method].apply(_method,_toConsumableArray(pts))}else if(_this3[method]){_this3[method].apply(_this3,_toConsumableArray(pts))}})}},{key:"addTemplate",value:function addTemplate(id,html){this.atemplate.push({id:id,html:html,binded:false});this.templates.push(id)}},{key:"getData",value:function getData(){return JSON.parse(JSON.stringify(this.data))}},{key:"saveData",value:function saveData(key){var data=JSON.stringify(this.data);localStorage.setItem(key,data)}},{key:"setData",value:function setData(opt){var _this4=this;Object.keys(opt).forEach(function(key){if(typeof opt[key]!=="function"){_this4.data[key]=opt[key]}})}},{key:"loadData",value:function loadData(key){var data=JSON.parse(localStorage.getItem(key));if(data){this.setData(data)}}},{key:"getRand",value:function getRand(a,b){return~~(Math.random()*(b-a+1))+a}},{key:"getRandText",value:function getRandText(limit){var ret="";var strings="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";var length=strings.length;for(var i=0;i<limit;i+=1){ret+=strings.charAt(Math.floor(this.getRand(0,length)))}return ret}},{key:"getDataFromObj",value:function getDataFromObj(s,o){s=s.replace(/\[([\w\-\.ぁ-んァ-ヶ亜-熙]+)\]/g,".$1");s=s.replace(/^\./,"");var a=s.split(".");while(a.length){var n=a.shift();if(n in o){o=o[n]}else{return null}}return o}},{key:"getDataByString",value:function getDataByString(s){var o=this.data;return this.getDataFromObj(s,o)}},{key:"updateDataByString",value:function updateDataByString(path,newValue){var object=this.data;var stack=path.split(".");while(stack.length>1){object=object[stack.shift()]}object[stack.shift()]=newValue}},{key:"removeDataByString",value:function removeDataByString(path){var object=this.data;var stack=path.split(".");while(stack.length>1){object=object[stack.shift()]}var shift=stack.shift();if(shift.match(/^\d+$/)){object.splice(Number(shift),1)}else{delete object[shift]}}},{key:"resolveBlock",value:function resolveBlock(html,item,i){var that=this;var touchs=html.match(/<!-- BEGIN ([\w\-\.ぁ-んァ-ヶ亜-熙]+):touch#([\w\-\.ぁ-んァ-ヶ亜-熙]+) -->/g);var touchnots=html.match(/<!-- BEGIN ([\w\-\.ぁ-んァ-ヶ亜-熙]+):touchnot#([\w\-\.ぁ-んァ-ヶ亜-熙]+) -->/g);var exists=html.match(/<!-- BEGIN ([\w\-\.ぁ-んァ-ヶ亜-熙]+):exist -->/g);var empties=html.match(/<!-- BEGIN ([\w\-\.ぁ-んァ-ヶ亜-熙]+):empty -->/g);if(touchs){for(var k=0,n=touchs.length;k<n;k+=1){var start=touchs[k];start=start.replace(/([\w\-\.ぁ-んァ-ヶ亜-熙]+):touch#([\w\-\.ぁ-んァ-ヶ亜-熙]+)/,"($1):touch#($2)");var end=start.replace(/BEGIN/,"END");var reg=new RegExp(start+"(([\\n\\r\\t]|.)*?)"+end,"g");html=html.replace(reg,function(m,key2,val,next){var itemkey=typeof item[key2]==="function"?item[key2].apply(that):that.getDataFromObj(key2,item);if(""+itemkey===val){return next}return""})}}if(touchnots){for(var _k=0,_n=touchnots.length;_k<_n;_k+=1){var _start=touchnots[_k];_start=_start.replace(/([\w\-\.ぁ-んァ-ヶ亜-熙]+):touchnot#([\w\-\.ぁ-んァ-ヶ亜-熙]+)/,"($1):touchnot#($2)");var _end=_start.replace(/BEGIN/,"END");var _reg=new RegExp(_start+"(([\\n\\r\\t]|.)*?)"+_end,"g");html=html.replace(_reg,function(m,key2,val,next){var itemkey=typeof item[key2]==="function"?item[key2].apply(that):that.getDataFromObj(key2,item);if(""+itemkey!==val){return next}return""})}}if(exists){for(var _k2=0,_n2=exists.length;_k2<_n2;_k2+=1){var _start2=exists[_k2];_start2=_start2.replace(/([\w\-\.ぁ-んァ-ヶ亜-熙]+):exist/,"($1):exist");var _end2=_start2.replace(/BEGIN/,"END");var _reg2=new RegExp(_start2+"(([\\n\\r\\t]|.)*?)"+_end2,"g");html=html.replace(_reg2,function(m,key2,next){var itemkey=typeof item[key2]==="function"?item[key2].apply(that):that.getDataFromObj(key2,item);if(itemkey||itemkey===0){return next}return""})}}if(empties){for(var _k3=0,_n3=empties.length;_k3<_n3;_k3+=1){var _start3=empties[_k3];_start3=_start3.replace(/([\w\-\.ぁ-んァ-ヶ亜-熙]+):empty/,"($1):empty");var _end3=_start3.replace(/BEGIN/,"END");var empty=new RegExp(_start3+"(([\\n\\r\\t]|.)*?)"+_end3,"g");html=html.replace(empty,function(m,key2,next){var itemkey=typeof item[key2]==="function"?item[key2].apply(that):that.getDataFromObj(key2,item);if(!itemkey&&itemkey!==0){return next}return""})}}html=html.replace(/{([\w\-\.ぁ-んァ-ヶ亜-熙]+)}(\[([\w\-\.ぁ-んァ-ヶ亜-熙]+)\])*/g,function(n,key3,key4,converter){var data=void 0;if(""+key3==="i"){data=i}else if(item[key3]||item[key3]===0){if(typeof item[key3]==="function"){data=item[key3].apply(that)}else{data=item[key3]}}else{if(converter&&that.convert&&that.convert[converter]){return that.convert[converter].call(that,"")}return""}if(converter&&that.convert&&that.convert[converter]){return that.convert[converter].call(that,data)}return data});return html}},{key:"resolveAbsBlock",value:function resolveAbsBlock(html){var that=this;html=html.replace(/{(.*?)}/g,function(n,key3){var data=that.getDataByString(key3);if(typeof data!=="undefined"){if(typeof data==="function"){return data.apply(that)}return data}return n});return html}},{key:"resolveInclude",value:function resolveInclude(html){var include=/<!-- #include id="(.*?)" -->/g;html=html.replace(include,function(m,key){return(0,_util.selector)("#"+key).innerHTML});return html}},{key:"resolveWith",value:function resolveWith(html){var width=/<!-- BEGIN ([\w\-\.ぁ-んァ-ヶ亜-熙]+):with -->(([\n\r\t]|.)*?)<!-- END ([\w\-\.ぁ-んァ-ヶ亜-熙]+):with -->/g;html=html.replace(width,function(m,key){m=m.replace(/data\-bind=['"](.*?)['"]/g,"data-bind='"+key+".$1'");return m});return html}},{key:"resolveLoop",value:function resolveLoop(html){var loop=/<!-- BEGIN ([\w\-\.ぁ-んァ-ヶ亜-熙]+?):loop -->(([\n\r\t]|.)*?)<!-- END ([\w\-\.ぁ-んァ-ヶ亜-熙]+?):loop -->/g;var that=this;html=html.replace(loop,function(m,key,val){var keyItem=that.getDataByString(key);var keys=[];if(typeof keyItem==="function"){keys=keyItem.apply(that)}else{keys=keyItem}var ret="";if(keys instanceof Array){for(var i=0,n=keys.length;i<n;i+=1){ret+=that.resolveBlock(val,keys[i],i)}}ret=ret.replace(/\\([^\\])/g,"$1");return ret});return html}},{key:"removeData",value:function removeData(arr){var data=this.data;Object.keys(data).forEach(function(i){for(var t=0,n=arr.length;t<n;t+=1){if(i===arr[t]){delete data[i]}}});return this}},{key:"hasLoop",value:function hasLoop(txt){var loop=/<!-- BEGIN ([\w\-\.ぁ-んァ-ヶ亜-熙]+?):loop -->(([\n\r\t]|.)*?)<!-- END ([\w\-\.ぁ-んァ-ヶ亜-熙]+?):loop -->/g;if(txt.match(loop)){return true}return false}},{key:"getHtml",value:function getHtml(query,row){var template=this.atemplate.find(function(item){return item.id===query});var html="";if(template&&template.html){html=template.html}if(row){html=query}if(!html){return""}var data=this.data;html=this.resolveInclude(html);html=this.resolveWith(html);while(this.hasLoop(html)){html=this.resolveLoop(html)}html=this.resolveBlock(html,data);html=html.replace(/\\([^\\])/g,"$1");html=this.resolveAbsBlock(html);return html.replace(/^([\t ])*\n/gm,"")}},{key:"update",value:function update(){var _this5=this;var renderWay=arguments.length>0&&arguments[0]!==undefined?arguments[0]:"html";var part=arguments[1];var templates=this.templates;if(this.beforeUpdated){this.beforeUpdated()}var _loop=function _loop(i,n){var tem=templates[i];var query="#"+tem;var html=_this5.getHtml(tem);var target=(0,_util.selector)("[data-id='"+tem+"']");if(!target){(0,_util.selector)(query).insertAdjacentHTML("afterend",'<div data-id="'+tem+'"></div>');if(renderWay==="text"){(0,_util.selector)("[data-id='"+tem+"']").innerText=html}else{(0,_util.selector)("[data-id='"+tem+"']").innerHTML=html}}else if(renderWay==="text"){target.innerText=html}else if(part){var doc=document.createElement("div");doc.innerHTML=html;var partHtml=doc.querySelector(part).outerHTML;(0,_morphdom2.default)(target.querySelector(part),partHtml)}else{(0,_morphdom2.default)(target,"<div data-id='"+tem+"'>"+html+"</div>")}var template=_this5.atemplate.find(function(item){return item.id===tem});if(!template.binded){template.binded=true;_this5.addDataBind((0,_util.selector)("[data-id='"+tem+"']"));_this5.addActionBind((0,_util.selector)("[data-id='"+tem+"']"))}};for(var i=0,n=templates.length;i<n;i+=1){_loop(i,n)}this.updateBindingData(part);if(this.onUpdated){this.onUpdated(part)}return this}},{key:"updateBindingData",value:function updateBindingData(part){var _this6=this;var templates=this.templates;for(var i=0,n=templates.length;i<n;i+=1){var temp=templates[i];var _template=(0,_util.selector)("[data-id='"+temp+"']");if(part){_template=_template.querySelector(part)}var binds=_template.querySelectorAll("[data-bind]");[].forEach.call(binds,function(item){var data=_this6.getDataByString(item.getAttribute("data-bind"));if(item.getAttribute("type")==="checkbox"||item.getAttribute("type")==="radio"){if(data===item.value){item.checked=true}}else{item.value=data}});var onewaybinds=_template.querySelectorAll("[data-bind-oneway]");[].forEach.call(onewaybinds,function(item){var data=_this6.getDataByString(item.getAttribute("data-bind-oneway"));if(item.getAttribute("type")==="checkbox"||item.getAttribute("type")==="radio"){if(data===item.value){item.checked=true}}else{item.value=data}})}return this}},{key:"applyMethod",value:function applyMethod(method){var _method2;for(var _len=arguments.length,args=Array(_len>1?_len-1:0),_key=1;_key<_len;_key++){args[_key-1]=arguments[_key]}return(_method2=this.method)[method].apply(_method2,args)}},{key:"getComputedProp",value:function getComputedProp(prop){return this.data[prop].apply(this)}},{key:"remove",value:function remove(path){var object=this.data;var stack=path.split(".");while(stack.length>1){object=object[stack.shift()]}var shift=stack.shift();if(shift.match(/^\d+$/)){object.splice(Number(shift),1)}else{delete object[shift]}return this}}]);return aTemplate}();exports.default=aTemplate;module.exports=exports["default"]},{"./util":4,"ie-array-find-polyfill":1,morphdom:2}],4:[function(require,module,exports){"use strict";Object.defineProperty(exports,"__esModule",{value:true});var matches=exports.matches=function matches(element,query){var matches=(element.document||element.ownerDocument).querySelectorAll(query);var i=matches.length;while(--i>=0&&matches.item(i)!==element){}return i>-1};var selector=exports.selector=function selector(_selector){return document.querySelector(_selector)};var findAncestor=exports.findAncestor=function findAncestor(element,selector){if(typeof element.closest==="function"){return element.closest(selector)||null}while(element&&element!==document){if(matches(element,selector)){return element}element=element.parentElement}return null};var on=exports.on=function on(element,query,eventNames,fn){var events=eventNames.split(" ");events.forEach(function(event){element.addEventListener(event,function(e){var target=e.target;var delegateTarget=findAncestor(e.target,query);if(delegateTarget){e.delegateTarget=delegateTarget;fn(e)}})})}},{}]},{},[3])(3)});
(function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.aTemplate=f()}})(function(){var define,module,exports;return function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s}({1:[function(require,module,exports){"use strict";if(!Array.prototype.find){Object.defineProperty(Array.prototype,"find",{value:function(predicate){if(this==null){throw new TypeError("this is null or not defined")}var obj=Object(this);var len=obj.length>>>0;if(typeof predicate!=="function"){throw new TypeError("predicate must be a function")}var thisArg=arguments[1];var index=0;while(index<len){var iValue=obj[index];if(predicate.call(thisArg,iValue,index,obj)){return iValue}index++}return undefined}})}},{}],2:[function(require,module,exports){"use strict";var range;var NS_XHTML="http://www.w3.org/1999/xhtml";var doc=typeof document==="undefined"?undefined:document;var testEl=doc?doc.body||doc.createElement("div"):{};var actualHasAttributeNS;if(testEl.hasAttributeNS){actualHasAttributeNS=function(el,namespaceURI,name){return el.hasAttributeNS(namespaceURI,name)}}else if(testEl.hasAttribute){actualHasAttributeNS=function(el,namespaceURI,name){return el.hasAttribute(name)}}else{actualHasAttributeNS=function(el,namespaceURI,name){return el.getAttributeNode(namespaceURI,name)!=null}}var hasAttributeNS=actualHasAttributeNS;function toElement(str){if(!range&&doc.createRange){range=doc.createRange();range.selectNode(doc.body)}var fragment;if(range&&range.createContextualFragment){fragment=range.createContextualFragment(str)}else{fragment=doc.createElement("body");fragment.innerHTML=str}return fragment.childNodes[0]}function compareNodeNames(fromEl,toEl){var fromNodeName=fromEl.nodeName;var toNodeName=toEl.nodeName;if(fromNodeName===toNodeName){return true}if(toEl.actualize&&fromNodeName.charCodeAt(0)<91&&toNodeName.charCodeAt(0)>90){return fromNodeName===toNodeName.toUpperCase()}else{return false}}function createElementNS(name,namespaceURI){return!namespaceURI||namespaceURI===NS_XHTML?doc.createElement(name):doc.createElementNS(namespaceURI,name)}function moveChildren(fromEl,toEl){var curChild=fromEl.firstChild;while(curChild){var nextChild=curChild.nextSibling;toEl.appendChild(curChild);curChild=nextChild}return toEl}function morphAttrs(fromNode,toNode){var attrs=toNode.attributes;var i;var attr;var attrName;var attrNamespaceURI;var attrValue;var fromValue;for(i=attrs.length-1;i>=0;--i){attr=attrs[i];attrName=attr.name;attrNamespaceURI=attr.namespaceURI;attrValue=attr.value;if(attrNamespaceURI){attrName=attr.localName||attrName;fromValue=fromNode.getAttributeNS(attrNamespaceURI,attrName);if(fromValue!==attrValue){fromNode.setAttributeNS(attrNamespaceURI,attrName,attrValue)}}else{fromValue=fromNode.getAttribute(attrName);if(fromValue!==attrValue){fromNode.setAttribute(attrName,attrValue)}}}attrs=fromNode.attributes;for(i=attrs.length-1;i>=0;--i){attr=attrs[i];if(attr.specified!==false){attrName=attr.name;attrNamespaceURI=attr.namespaceURI;if(attrNamespaceURI){attrName=attr.localName||attrName;if(!hasAttributeNS(toNode,attrNamespaceURI,attrName)){fromNode.removeAttributeNS(attrNamespaceURI,attrName)}}else{if(!hasAttributeNS(toNode,null,attrName)){fromNode.removeAttribute(attrName)}}}}}function syncBooleanAttrProp(fromEl,toEl,name){if(fromEl[name]!==toEl[name]){fromEl[name]=toEl[name];if(fromEl[name]){fromEl.setAttribute(name,"")}else{fromEl.removeAttribute(name,"")}}}var specialElHandlers={OPTION:function(fromEl,toEl){syncBooleanAttrProp(fromEl,toEl,"selected")},INPUT:function(fromEl,toEl){syncBooleanAttrProp(fromEl,toEl,"checked");syncBooleanAttrProp(fromEl,toEl,"disabled");if(fromEl.value!==toEl.value){fromEl.value=toEl.value}if(!hasAttributeNS(toEl,null,"value")){fromEl.removeAttribute("value")}},TEXTAREA:function(fromEl,toEl){var newValue=toEl.value;if(fromEl.value!==newValue){fromEl.value=newValue}var firstChild=fromEl.firstChild;if(firstChild){var oldValue=firstChild.nodeValue;if(oldValue==newValue||!newValue&&oldValue==fromEl.placeholder){return}firstChild.nodeValue=newValue}},SELECT:function(fromEl,toEl){if(!hasAttributeNS(toEl,null,"multiple")){var selectedIndex=-1;var i=0;var curChild=toEl.firstChild;while(curChild){var nodeName=curChild.nodeName;if(nodeName&&nodeName.toUpperCase()==="OPTION"){if(hasAttributeNS(curChild,null,"selected")){selectedIndex=i;break}i++}curChild=curChild.nextSibling}fromEl.selectedIndex=i}}};var ELEMENT_NODE=1;var TEXT_NODE=3;var COMMENT_NODE=8;function noop(){}function defaultGetNodeKey(node){return node.id}function morphdomFactory(morphAttrs){return function morphdom(fromNode,toNode,options){if(!options){options={}}if(typeof toNode==="string"){if(fromNode.nodeName==="#document"||fromNode.nodeName==="HTML"){var toNodeHtml=toNode;toNode=doc.createElement("html");toNode.innerHTML=toNodeHtml}else{toNode=toElement(toNode)}}var getNodeKey=options.getNodeKey||defaultGetNodeKey;var onBeforeNodeAdded=options.onBeforeNodeAdded||noop;var onNodeAdded=options.onNodeAdded||noop;var onBeforeElUpdated=options.onBeforeElUpdated||noop;var onElUpdated=options.onElUpdated||noop;var onBeforeNodeDiscarded=options.onBeforeNodeDiscarded||noop;var onNodeDiscarded=options.onNodeDiscarded||noop;var onBeforeElChildrenUpdated=options.onBeforeElChildrenUpdated||noop;var childrenOnly=options.childrenOnly===true;var fromNodesLookup={};var keyedRemovalList;function addKeyedRemoval(key){if(keyedRemovalList){keyedRemovalList.push(key)}else{keyedRemovalList=[key]}}function walkDiscardedChildNodes(node,skipKeyedNodes){if(node.nodeType===ELEMENT_NODE){var curChild=node.firstChild;while(curChild){var key=undefined;if(skipKeyedNodes&&(key=getNodeKey(curChild))){addKeyedRemoval(key)}else{onNodeDiscarded(curChild);if(curChild.firstChild){walkDiscardedChildNodes(curChild,skipKeyedNodes)}}curChild=curChild.nextSibling}}}function removeNode(node,parentNode,skipKeyedNodes){if(onBeforeNodeDiscarded(node)===false){return}if(parentNode){parentNode.removeChild(node)}onNodeDiscarded(node);walkDiscardedChildNodes(node,skipKeyedNodes)}function indexTree(node){if(node.nodeType===ELEMENT_NODE){var curChild=node.firstChild;while(curChild){var key=getNodeKey(curChild);if(key){fromNodesLookup[key]=curChild}indexTree(curChild);curChild=curChild.nextSibling}}}indexTree(fromNode);function handleNodeAdded(el){onNodeAdded(el);var curChild=el.firstChild;while(curChild){var nextSibling=curChild.nextSibling;var key=getNodeKey(curChild);if(key){var unmatchedFromEl=fromNodesLookup[key];if(unmatchedFromEl&&compareNodeNames(curChild,unmatchedFromEl)){curChild.parentNode.replaceChild(unmatchedFromEl,curChild);morphEl(unmatchedFromEl,curChild)}}handleNodeAdded(curChild);curChild=nextSibling}}function morphEl(fromEl,toEl,childrenOnly){var toElKey=getNodeKey(toEl);var curFromNodeKey;if(toElKey){delete fromNodesLookup[toElKey]}if(toNode.isSameNode&&toNode.isSameNode(fromNode)){return}if(!childrenOnly){if(onBeforeElUpdated(fromEl,toEl)===false){return}morphAttrs(fromEl,toEl);onElUpdated(fromEl);if(onBeforeElChildrenUpdated(fromEl,toEl)===false){return}}if(fromEl.nodeName!=="TEXTAREA"){var curToNodeChild=toEl.firstChild;var curFromNodeChild=fromEl.firstChild;var curToNodeKey;var fromNextSibling;var toNextSibling;var matchingFromEl;outer:while(curToNodeChild){toNextSibling=curToNodeChild.nextSibling;curToNodeKey=getNodeKey(curToNodeChild);while(curFromNodeChild){fromNextSibling=curFromNodeChild.nextSibling;if(curToNodeChild.isSameNode&&curToNodeChild.isSameNode(curFromNodeChild)){curToNodeChild=toNextSibling;curFromNodeChild=fromNextSibling;continue outer}curFromNodeKey=getNodeKey(curFromNodeChild);var curFromNodeType=curFromNodeChild.nodeType;var isCompatible=undefined;if(curFromNodeType===curToNodeChild.nodeType){if(curFromNodeType===ELEMENT_NODE){if(curToNodeKey){if(curToNodeKey!==curFromNodeKey){if(matchingFromEl=fromNodesLookup[curToNodeKey]){if(curFromNodeChild.nextSibling===matchingFromEl){isCompatible=false}else{fromEl.insertBefore(matchingFromEl,curFromNodeChild);fromNextSibling=curFromNodeChild.nextSibling;if(curFromNodeKey){addKeyedRemoval(curFromNodeKey)}else{removeNode(curFromNodeChild,fromEl,true)}curFromNodeChild=matchingFromEl}}else{isCompatible=false}}}else if(curFromNodeKey){isCompatible=false}isCompatible=isCompatible!==false&&compareNodeNames(curFromNodeChild,curToNodeChild);if(isCompatible){morphEl(curFromNodeChild,curToNodeChild)}}else if(curFromNodeType===TEXT_NODE||curFromNodeType==COMMENT_NODE){isCompatible=true;if(curFromNodeChild.nodeValue!==curToNodeChild.nodeValue){curFromNodeChild.nodeValue=curToNodeChild.nodeValue}}}if(isCompatible){curToNodeChild=toNextSibling;curFromNodeChild=fromNextSibling;continue outer}if(curFromNodeKey){addKeyedRemoval(curFromNodeKey)}else{removeNode(curFromNodeChild,fromEl,true)}curFromNodeChild=fromNextSibling}if(curToNodeKey&&(matchingFromEl=fromNodesLookup[curToNodeKey])&&compareNodeNames(matchingFromEl,curToNodeChild)){fromEl.appendChild(matchingFromEl);morphEl(matchingFromEl,curToNodeChild)}else{var onBeforeNodeAddedResult=onBeforeNodeAdded(curToNodeChild);if(onBeforeNodeAddedResult!==false){if(onBeforeNodeAddedResult){curToNodeChild=onBeforeNodeAddedResult}if(curToNodeChild.actualize){curToNodeChild=curToNodeChild.actualize(fromEl.ownerDocument||doc)}fromEl.appendChild(curToNodeChild);handleNodeAdded(curToNodeChild)}}curToNodeChild=toNextSibling;curFromNodeChild=fromNextSibling}while(curFromNodeChild){fromNextSibling=curFromNodeChild.nextSibling;if(curFromNodeKey=getNodeKey(curFromNodeChild)){addKeyedRemoval(curFromNodeKey)}else{removeNode(curFromNodeChild,fromEl,true)}curFromNodeChild=fromNextSibling}}var specialElHandler=specialElHandlers[fromEl.nodeName];if(specialElHandler){specialElHandler(fromEl,toEl)}}var morphedNode=fromNode;var morphedNodeType=morphedNode.nodeType;var toNodeType=toNode.nodeType;if(!childrenOnly){if(morphedNodeType===ELEMENT_NODE){if(toNodeType===ELEMENT_NODE){if(!compareNodeNames(fromNode,toNode)){onNodeDiscarded(fromNode);morphedNode=moveChildren(fromNode,createElementNS(toNode.nodeName,toNode.namespaceURI))}}else{morphedNode=toNode}}else if(morphedNodeType===TEXT_NODE||morphedNodeType===COMMENT_NODE){if(toNodeType===morphedNodeType){if(morphedNode.nodeValue!==toNode.nodeValue){morphedNode.nodeValue=toNode.nodeValue}return morphedNode}else{morphedNode=toNode}}}if(morphedNode===toNode){onNodeDiscarded(fromNode)}else{morphEl(morphedNode,toNode,childrenOnly);if(keyedRemovalList){for(var i=0,len=keyedRemovalList.length;i<len;i++){var elToRemove=fromNodesLookup[keyedRemovalList[i]];if(elToRemove){removeNode(elToRemove,elToRemove.parentNode,false)}}}}if(!childrenOnly&&morphedNode!==fromNode&&fromNode.parentNode){if(morphedNode.actualize){morphedNode=morphedNode.actualize(fromNode.ownerDocument||doc)}fromNode.parentNode.replaceChild(morphedNode,fromNode)}return morphedNode}}var morphdom=morphdomFactory(morphAttrs);module.exports=morphdom},{}],3:[function(require,module,exports){"use strict";Object.defineProperty(exports,"__esModule",{value:true});var _createClass=function(){function defineProperties(target,props){for(var i=0;i<props.length;i++){var descriptor=props[i];descriptor.enumerable=descriptor.enumerable||false;descriptor.configurable=true;if("value"in descriptor)descriptor.writable=true;Object.defineProperty(target,descriptor.key,descriptor)}}return function(Constructor,protoProps,staticProps){if(protoProps)defineProperties(Constructor.prototype,protoProps);if(staticProps)defineProperties(Constructor,staticProps);return Constructor}}();require("ie-array-find-polyfill");var _morphdom=require("morphdom");var _morphdom2=_interopRequireDefault(_morphdom);var _util=require("./util");function _interopRequireDefault(obj){return obj&&obj.__esModule?obj:{"default":obj}}function _toConsumableArray(arr){if(Array.isArray(arr)){for(var i=0,arr2=Array(arr.length);i<arr.length;i++){arr2[i]=arr[i]}return arr2}else{return Array.from(arr)}}function _classCallCheck(instance,Constructor){if(!(instance instanceof Constructor)){throw new TypeError("Cannot call a class as a function")}}var eventType="input paste copy click change keydown keyup keypress contextmenu mouseup mousedown mousemove touchstart touchend touchmove compositionstart compositionend focus";var bindType="input change click";var dataAction=eventType.replace(/([a-z]+)/g,"[data-action-$1],")+"[data-action]";var aTemplate=function(){function aTemplate(opt){var _this=this;_classCallCheck(this,aTemplate);this.atemplate=[];this.events=[];if(opt){Object.keys(opt).forEach(function(key){_this[key]=opt[key]})}if(!this.data){this.data={}}if(!this.templates){this.templates=[]}var templates=this.templates;var length=templates.length;for(var i=0,n=length;i<n;i+=1){var template=this.templates[i];var html=(0,_util.selector)("#"+template).innerHTML;this.atemplate.push({id:template,html:html,binded:false})}}_createClass(aTemplate,[{key:"addDataBind",value:function addDataBind(ele){var _this2=this;(0,_util.on)(ele,"[data-bind]",bindType,function(e){var target=e.delegateTarget;var data=target.getAttribute("data-bind");var attr=target.getAttribute("href");var value=target.value;if(attr){value=value.replace("#","")}if(target.getAttribute("type")==="checkbox"){(function(){var arr=[];var items=document.querySelectorAll('[data-bind="'+data+'"]');[].forEach.call(items,function(item){if(item.checked){arr.push(item.value)}})})()}else if(target.getAttribute("type")!=="radio"){_this2.updateDataByString(data,value)}});this.events.push({element:ele,selector:"[data-bind]",event:bindType})}},{key:"addActionBind",value:function addActionBind(ele){var _this3=this;(0,_util.on)(ele,dataAction,eventType,function(e){var target=e.delegateTarget;var events=eventType.split(" ");var action="action";events.forEach(function(event){if(target.getAttribute("data-action-"+event)){if(e.type===event){action+="-"+event}}});var string=target.getAttribute("data-"+action);if(!string){return}var method=string.replace(/\(.*?\);?/,"");var parameter=string.replace(/(.*?)\((.*?)\);?/,"$2");var pts=parameter.split(",");_this3.e=e;if(_this3.method&&_this3.method[method]){var _method;(_method=_this3.method)[method].apply(_method,_toConsumableArray(pts))}else if(_this3[method]){_this3[method].apply(_this3,_toConsumableArray(pts))}});this.events.push({element:ele,selector:dataAction,event:bindType})}},{key:"removeTemplateEvents",value:function removeTemplateEvents(){this.events.forEach(function(event){(0,_util.off)(event.element,event.selector,event.event)})}},{key:"addTemplate",value:function addTemplate(id,html){this.atemplate.push({id:id,html:html,binded:false});this.templates.push(id)}},{key:"getData",value:function getData(){return JSON.parse(JSON.stringify(this.data))}},{key:"saveData",value:function saveData(key){var data=JSON.stringify(this.data);localStorage.setItem(key,data)}},{key:"setData",value:function setData(opt){var _this4=this;Object.keys(opt).forEach(function(key){if(typeof opt[key]!=="function"){_this4.data[key]=opt[key]}})}},{key:"loadData",value:function loadData(key){var data=JSON.parse(localStorage.getItem(key));if(data){this.setData(data)}}},{key:"getRand",value:function getRand(a,b){return~~(Math.random()*(b-a+1))+a}},{key:"getRandText",value:function getRandText(limit){var ret="";var strings="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";var length=strings.length;for(var i=0;i<limit;i+=1){ret+=strings.charAt(Math.floor(this.getRand(0,length)))}return ret}},{key:"getDataFromObj",value:function getDataFromObj(s,o){s=s.replace(/\[([\w\-\.ぁ-んァ-ヶ亜-熙]+)\]/g,".$1");s=s.replace(/^\./,"");var a=s.split(".");while(a.length){var n=a.shift();if(n in o){o=o[n]}else{return null}}return o}},{key:"getDataByString",value:function getDataByString(s){var o=this.data;return this.getDataFromObj(s,o)}},{key:"updateDataByString",value:function updateDataByString(path,newValue){var object=this.data;var stack=path.split(".");while(stack.length>1){object=object[stack.shift()]}object[stack.shift()]=newValue}},{key:"removeDataByString",value:function removeDataByString(path){var object=this.data;var stack=path.split(".");while(stack.length>1){object=object[stack.shift()]}var shift=stack.shift();if(shift.match(/^\d+$/)){object.splice(Number(shift),1)}else{delete object[shift]}}},{key:"resolveBlock",value:function resolveBlock(html,item,i){var that=this;var touchs=html.match(/<!-- BEGIN ([\w\-\.ぁ-んァ-ヶ亜-熙]+):touch#([\w\-\.ぁ-んァ-ヶ亜-熙]+) -->/g);var touchnots=html.match(/<!-- BEGIN ([\w\-\.ぁ-んァ-ヶ亜-熙]+):touchnot#([\w\-\.ぁ-んァ-ヶ亜-熙]+) -->/g);var exists=html.match(/<!-- BEGIN ([\w\-\.ぁ-んァ-ヶ亜-熙]+):exist -->/g);var empties=html.match(/<!-- BEGIN ([\w\-\.ぁ-んァ-ヶ亜-熙]+):empty -->/g);if(touchs){for(var k=0,n=touchs.length;k<n;k+=1){var start=touchs[k];start=start.replace(/([\w\-\.ぁ-んァ-ヶ亜-熙]+):touch#([\w\-\.ぁ-んァ-ヶ亜-熙]+)/,"($1):touch#($2)");var end=start.replace(/BEGIN/,"END");var reg=new RegExp(start+"(([\\n\\r\\t]|.)*?)"+end,"g");html=html.replace(reg,function(m,key2,val,next){var itemkey=typeof item[key2]==="function"?item[key2].apply(that):that.getDataFromObj(key2,item);if(""+itemkey===val){return next}return""})}}if(touchnots){for(var _k=0,_n=touchnots.length;_k<_n;_k+=1){var _start=touchnots[_k];_start=_start.replace(/([\w\-\.ぁ-んァ-ヶ亜-熙]+):touchnot#([\w\-\.ぁ-んァ-ヶ亜-熙]+)/,"($1):touchnot#($2)");var _end=_start.replace(/BEGIN/,"END");var _reg=new RegExp(_start+"(([\\n\\r\\t]|.)*?)"+_end,"g");html=html.replace(_reg,function(m,key2,val,next){var itemkey=typeof item[key2]==="function"?item[key2].apply(that):that.getDataFromObj(key2,item);if(""+itemkey!==val){return next}return""})}}if(exists){for(var _k2=0,_n2=exists.length;_k2<_n2;_k2+=1){var _start2=exists[_k2];_start2=_start2.replace(/([\w\-\.ぁ-んァ-ヶ亜-熙]+):exist/,"($1):exist");var _end2=_start2.replace(/BEGIN/,"END");var _reg2=new RegExp(_start2+"(([\\n\\r\\t]|.)*?)"+_end2,"g");html=html.replace(_reg2,function(m,key2,next){var itemkey=typeof item[key2]==="function"?item[key2].apply(that):that.getDataFromObj(key2,item);if(itemkey||itemkey===0){return next}return""})}}if(empties){for(var _k3=0,_n3=empties.length;_k3<_n3;_k3+=1){var _start3=empties[_k3];_start3=_start3.replace(/([\w\-\.ぁ-んァ-ヶ亜-熙]+):empty/,"($1):empty");var _end3=_start3.replace(/BEGIN/,"END");var empty=new RegExp(_start3+"(([\\n\\r\\t]|.)*?)"+_end3,"g");html=html.replace(empty,function(m,key2,next){var itemkey=typeof item[key2]==="function"?item[key2].apply(that):that.getDataFromObj(key2,item);if(!itemkey&&itemkey!==0){return next}return""})}}html=html.replace(/{([\w\-\.ぁ-んァ-ヶ亜-熙]+)}(\[([\w\-\.ぁ-んァ-ヶ亜-熙]+)\])*/g,function(n,key3,key4,converter){var data=void 0;if(""+key3==="i"){data=i}else if(item[key3]||item[key3]===0){if(typeof item[key3]==="function"){data=item[key3].apply(that)}else{data=item[key3]}}else{if(converter&&that.convert&&that.convert[converter]){return that.convert[converter].call(that,"")}return""}if(converter&&that.convert&&that.convert[converter]){return that.convert[converter].call(that,data)}return data});return html}},{key:"resolveAbsBlock",value:function resolveAbsBlock(html){var that=this;html=html.replace(/{(.*?)}/g,function(n,key3){var data=that.getDataByString(key3);if(typeof data!=="undefined"){if(typeof data==="function"){return data.apply(that)}return data}return n});return html}},{key:"resolveInclude",value:function resolveInclude(html){var include=/<!-- #include id="(.*?)" -->/g;html=html.replace(include,function(m,key){return(0,_util.selector)("#"+key).innerHTML});return html}},{key:"resolveWith",value:function resolveWith(html){var width=/<!-- BEGIN ([\w\-\.ぁ-んァ-ヶ亜-熙]+):with -->(([\n\r\t]|.)*?)<!-- END ([\w\-\.ぁ-んァ-ヶ亜-熙]+):with -->/g;html=html.replace(width,function(m,key){m=m.replace(/data\-bind=['"](.*?)['"]/g,"data-bind='"+key+".$1'");return m});return html}},{key:"resolveLoop",value:function resolveLoop(html){var loop=/<!-- BEGIN ([\w\-\.ぁ-んァ-ヶ亜-熙]+?):loop -->(([\n\r\t]|.)*?)<!-- END ([\w\-\.ぁ-んァ-ヶ亜-熙]+?):loop -->/g;var that=this;html=html.replace(loop,function(m,key,val){var keyItem=that.getDataByString(key);var keys=[];if(typeof keyItem==="function"){keys=keyItem.apply(that)}else{keys=keyItem}var ret="";if(keys instanceof Array){for(var i=0,n=keys.length;i<n;i+=1){ret+=that.resolveBlock(val,keys[i],i)}}ret=ret.replace(/\\([^\\])/g,"$1");return ret});return html}},{key:"removeData",value:function removeData(arr){var data=this.data;Object.keys(data).forEach(function(i){for(var t=0,n=arr.length;t<n;t+=1){if(i===arr[t]){delete data[i]}}});return this}},{key:"hasLoop",value:function hasLoop(txt){var loop=/<!-- BEGIN ([\w\-\.ぁ-んァ-ヶ亜-熙]+?):loop -->(([\n\r\t]|.)*?)<!-- END ([\w\-\.ぁ-んァ-ヶ亜-熙]+?):loop -->/g;if(txt.match(loop)){return true}return false}},{key:"getHtml",value:function getHtml(query,row){var template=this.atemplate.find(function(item){return item.id===query});var html="";if(template&&template.html){html=template.html}if(row){html=query}if(!html){return""}var data=this.data;html=this.resolveInclude(html);html=this.resolveWith(html);while(this.hasLoop(html)){html=this.resolveLoop(html)}html=this.resolveBlock(html,data);html=html.replace(/\\([^\\])/g,"$1");html=this.resolveAbsBlock(html);return html.replace(/^([\t ])*\n/gm,"")}},{key:"update",value:function update(){var _this5=this;var renderWay=arguments.length>0&&arguments[0]!==undefined?arguments[0]:"html";var part=arguments[1];var templates=this.templates;if(this.beforeUpdated){this.beforeUpdated()}var _loop=function _loop(i,n){var tem=templates[i];var query="#"+tem;var html=_this5.getHtml(tem);var target=(0,_util.selector)("[data-id='"+tem+"']");if(!target){(0,_util.selector)(query).insertAdjacentHTML("afterend",'<div data-id="'+tem+'"></div>');if(renderWay==="text"){(0,_util.selector)("[data-id='"+tem+"']").innerText=html}else{(0,_util.selector)("[data-id='"+tem+"']").innerHTML=html}}else if(renderWay==="text"){target.innerText=html}else if(part){var doc=document.createElement("div");doc.innerHTML=html;var partHtml=doc.querySelector(part).outerHTML;(0,_morphdom2.default)(target.querySelector(part),partHtml)}else{(0,_morphdom2.default)(target,"<div data-id='"+tem+"'>"+html+"</div>")}var template=_this5.atemplate.find(function(item){return item.id===tem});if(!template.binded){template.binded=true;_this5.addDataBind((0,_util.selector)("[data-id='"+tem+"']"));_this5.addActionBind((0,_util.selector)("[data-id='"+tem+"']"))}};for(var i=0,n=templates.length;i<n;i+=1){_loop(i,n)}this.updateBindingData(part);if(this.onUpdated){this.onUpdated(part)}return this}},{key:"updateBindingData",value:function updateBindingData(part){var _this6=this;var templates=this.templates;for(var i=0,n=templates.length;i<n;i+=1){var temp=templates[i];var _template=(0,_util.selector)("[data-id='"+temp+"']");if(part){_template=_template.querySelector(part)}var binds=_template.querySelectorAll("[data-bind]");[].forEach.call(binds,function(item){var data=_this6.getDataByString(item.getAttribute("data-bind"));if(item.getAttribute("type")==="checkbox"||item.getAttribute("type")==="radio"){if(data===item.value){item.checked=true}}else{item.value=data}});var onewaybinds=_template.querySelectorAll("[data-bind-oneway]");[].forEach.call(onewaybinds,function(item){var data=_this6.getDataByString(item.getAttribute("data-bind-oneway"));if(item.getAttribute("type")==="checkbox"||item.getAttribute("type")==="radio"){if(data===item.value){item.checked=true}}else{item.value=data}})}return this}},{key:"applyMethod",value:function applyMethod(method){var _method2;for(var _len=arguments.length,args=Array(_len>1?_len-1:0),_key=1;_key<_len;_key++){args[_key-1]=arguments[_key]}return(_method2=this.method)[method].apply(_method2,args)}},{key:"getComputedProp",value:function getComputedProp(prop){return this.data[prop].apply(this)}},{key:"remove",value:function remove(path){var object=this.data;var stack=path.split(".");while(stack.length>1){object=object[stack.shift()]}var shift=stack.shift();if(shift.match(/^\d+$/)){object.splice(Number(shift),1)}else{delete object[shift]}return this}}]);return aTemplate}();exports.default=aTemplate;module.exports=exports["default"]},{"./util":4,"ie-array-find-polyfill":1,morphdom:2}],4:[function(require,module,exports){"use strict";Object.defineProperty(exports,"__esModule",{value:true});var matches=exports.matches=function matches(element,query){var matches=(element.document||element.ownerDocument).querySelectorAll(query);var i=matches.length;while(--i>=0&&matches.item(i)!==element){}return i>-1};var selector=exports.selector=function selector(_selector){return document.querySelector(_selector)};var findAncestor=exports.findAncestor=function findAncestor(element,selector){if(typeof element.closest==="function"){return element.closest(selector)||null}while(element&&element!==document){if(matches(element,selector)){return element}element=element.parentElement}return null};var listenerList=[];var on=exports.on=function on(element,query,eventNames,fn){var capture=arguments.length>4&&arguments[4]!==undefined?arguments[4]:false;var events=eventNames.split(" ");events.forEach(function(event){var listener=function listener(e){var delegateTarget=findAncestor(e.target,query);if(delegateTarget){e.delegateTarget=delegateTarget;fn(e)}};listenerList.push({listener:listener,element:element,query:query,event:event,capture:capture});element.addEventListener(event,listener,capture)})};var off=exports.off=function off(element,query,eventNames){var events=eventNames.split(" ");events.forEach(function(event){listenerList.forEach(function(item,index){if(item.element===element&&item.query===query&&item.event===event){element.removeEventListener(event,item.listener,item.capture);listenerList.splice(index,1)}})})}},{}]},{},[3])(3)});
{
"name": "a-template",
"version": "0.5.5",
"version": "0.6.0",
"author": "steelydylan",

@@ -5,0 +5,0 @@ "description": "Simple Template Engine",

import 'ie-array-find-polyfill';
import morphdom from 'morphdom';
import { selector, on } from './util';
import { selector, on, off } from './util';

@@ -13,2 +13,3 @@ const eventType = 'input paste copy click change keydown keyup keypress contextmenu mouseup mousedown mousemove touchstart touchend touchmove compositionstart compositionend focus';

this.atemplate = [];
this.events = [];
if (opt) {

@@ -55,2 +56,7 @@ Object.keys(opt).forEach((key) => {

});
this.events.push({
element: ele,
selector: '[data-bind]',
event: bindType
});
}

@@ -84,4 +90,15 @@

});
this.events.push({
element: ele,
selector: dataAction,
event: bindType
});
}
removeTemplateEvents() {
this.events.forEach((event) => {
off(event.element, event.selector, event.event);
});
}
addTemplate(id, html) {

@@ -88,0 +105,0 @@ this.atemplate.push({ id, html, binded: false });

@@ -7,7 +7,5 @@

return i > -1;
}
};
export const selector = (selector) => {
return document.querySelector(selector);
}
export const selector = selector => document.querySelector(selector);

@@ -25,16 +23,31 @@ export const findAncestor = (element, selector) => {

return null;
}
};
export const on = (element, query, eventNames, fn) => {
const listenerList = [];
export const on = (element, query, eventNames, fn, capture = false) => {
const events = eventNames.split(' ');
events.forEach((event) => {
element.addEventListener(event, (e) => {
let target = e.target;
const listener = (e) => {
const delegateTarget = findAncestor(e.target, query);
if(delegateTarget) {
if (delegateTarget) {
e.delegateTarget = delegateTarget;
fn(e);
}
};
listenerList.push({ listener, element, query, event, capture });
element.addEventListener(event, listener, capture);
});
};
export const off = (element, query, eventNames) => {
const events = eventNames.split(' ');
events.forEach((event) => {
listenerList.forEach((item, index) => {
if (item.element === element && item.query === query && item.event === event) {
element.removeEventListener(event, item.listener, item.capture);
listenerList.splice(index, 1);
}
});
});
};

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc