This commit is contained in:
Leo Horie 2016-11-04 12:34:39 -04:00
parent ff7ce37476
commit 85eed94172
2 changed files with 13 additions and 12 deletions

View file

@ -912,7 +912,7 @@ var _14 = function($window) {
if (typeof onevent === "function") onevent.call(element, e)
return result
}
if (key1 in element) element[key1] = callback
if (key1 in element) element[key1] = typeof value2 === "function" ? callback : null
else {
var eventName = key1.slice(2)
if (vnode.events === undefined) vnode.events = {}

23
mithril.min.js vendored
View file

@ -30,14 +30,15 @@ if(0<a){for(b=b.dom;--a;)d.appendChild(b.nextSibling);d.insertBefore(b,d.firstCh
a,d,c,e){for(;d<c;d++){var f=a[d];null!=f&&(f.skip?f.skip=!1:x(b,f,e))}}function r(b){var a=!1;return function(){a||(a=!0,b())}}function x(b,a,d){function c(){if(++f===e&&(u(a),a.dom)){var c=a.domSize||1;if(1<c)for(var g=a.dom;--c;)b.removeChild(g.nextSibling);null!=a.dom.parentNode&&b.removeChild(a.dom);if(c=null!=d&&null==a.domSize)c=a.attrs,c=!(null!=c&&(c.oncreate||c.onupdate||c.onbeforeremove||c.onremove));c&&"string"===typeof a.tag&&(d.pool?d.pool.push(a):d.pool=[a])}}var e=1,f=0;a.attrs&&a.attrs.onbeforeremove&&
(e++,a.attrs.onbeforeremove.call(a.state,a,r(c)));"string"!==typeof a.tag&&a.tag.onbeforeremove&&(e++,a.tag.onbeforeremove.call(a.state,a,r(c)));c()}function u(b){b.attrs&&b.attrs.onremove&&b.attrs.onremove.call(b.state,b);"string"!==typeof b.tag&&b.tag.onremove&&b.tag.onremove.call(b.state,b);if(null!=b.instance)u(b.instance);else if(b=b.children,b instanceof Array)for(var a=0;a<b.length;a++){var d=b[a];null!=d&&u(d)}}function t(b,a,d,c,e){var f=b.dom;if("key"!==a&&(d!==c||"value"===a||"checked"===
a||"selectedIndex"===a||"selected"===a&&b.dom===B.activeElement||"object"===typeof c)&&"undefined"!==typeof c&&!G(a)){var g=a.indexOf(":");if(-1<g&&"xlink"===a.substr(0,g))f.setAttributeNS("http://www.w3.org/1999/xlink",a.slice(g+1),c);else if("o"===a[0]&&"n"===a[1]&&"function"===typeof c)v(b,a,c);else if("style"===a)if(b=d,b===c&&(f.style.cssText="",b=null),null==c)f.style.cssText="";else if("string"===typeof c)f.style.cssText=c;else{"string"===typeof b&&(f.style.cssText="");for(var h in c)f.style[h]=
c[h];if(null!=b&&"string"!==typeof b)for(h in b)h in c||(f.style[h]="")}else if(a in f&&"href"!==a&&"list"!==a&&"form"!==a&&"width"!==a&&"height"!==a&&void 0===e){if("input"!==b.tag||"value"!==a||b.dom.value!==c||b.dom!==B.activeElement)f[a]=c}else"boolean"===typeof c?c?f.setAttribute(a,""):f.removeAttribute(a):f.setAttribute("className"===a?"class":a,c)}}function G(b){return"oninit"===b||"oncreate"===b||"onupdate"===b||"onremove"===b||"onbeforeremove"===b||"onbeforeupdate"===b}function v(b,a,c){var d=
b.dom,e=function(a){var b=c.call(d,a);"function"===typeof F&&F.call(d,a);return b};if(a in d)d[a]=e;else{var f=a.slice(2);void 0===b.events&&(b.events={});null!=b.events[a]&&d.removeEventListener(f,b.events[a],!1);"function"===typeof c&&(b.events[a]=e,d.addEventListener(f,b.events[a],!1))}}function D(b,a,d){"function"===typeof b.oninit&&b.oninit.call(a.state,a);"function"===typeof b.oncreate&&d.push(b.oncreate.bind(a.state,a))}function O(b,a,d,c){c?D(b,a,d):"function"===typeof b.onupdate&&d.push(b.onupdate.bind(a.state,
a))}function H(b,a){Object.keys(a).forEach(function(c){b[c]=a[c]})}var B=c.document,I=B.createDocumentFragment(),F;return{render:function(b,a){if(!b)throw Error("Ensure the DOM element being passed to m.route/m.mount/m.render is not undefined.");var c=[],e=B.activeElement;null==b.vnodes&&(b.textContent="");a instanceof Array||(a=[a]);k(b,b.vnodes,q.normalizeChildren(a),c,null,void 0);b.vnodes=a;for(var f=0;f<c.length;f++)c[f]();B.activeElement!==e&&e.focus()},setEventCallback:function(b){return F=
b}}}(window),U=function(c){var f=0,p=null,g="function"===typeof requestAnimationFrame?requestAnimationFrame:setTimeout;return function(k){var h=Date.now();!0===k||0===f||16<=h-f?(f=h,c()):null===p&&(p=g(function(){p=null;c();f=Date.now()},16-(h-f)))}},V=function(c,f,p,g){g=U(g);null!=f&&f.setEventCallback(function(c){!1!==c.redraw&&p.publish()});null!=p&&(c.redraw&&p.unsubscribe(c.redraw),p.subscribe(g));return c.redraw=g};v.mount=function(c,f){return function(p,g){if(null===g)c.render(p,[]),f.unsubscribe(p.redraw),
delete p.redraw;else{if(null==g.view)throw Error("m.mount(element, component) expects a component, not a vnode");V(p,c,f,function(){c.render(p,q(g,void 0,void 0,void 0,void 0,void 0))})()}}}(Q,M);var N=function(c){if(""===c||null==c)return{};"?"===c.charAt(0)&&(c=c.slice(1));c=c.split("&");for(var f={},p={},g=0;g<c.length;g++){var k=c[g].split("="),h=decodeURIComponent(k[0]),k=2===k.length?decodeURIComponent(k[1]):"";"true"===k?k=!0:"false"===k&&(k=!1);var y=h.split(/\]\[?|\[/),q=f;-1<h.indexOf("[")&&
y.pop();for(var n=0;n<y.length;n++){var h=y[n],e=y[n+1],e=""==e||!isNaN(parseInt(e,10)),l=n===y.length-1;""===h&&(h=y.slice(0,n).join(),null==p[h]&&(p[h]=0),h=p[h]++);null==q[h]&&(q[h]=l?k:e?[]:{});q=q[h]}}return f},W=function(c){function f(e){var f=c.location[e].replace(/(?:%[a-f89][a-f0-9])+/gim,decodeURIComponent);"pathname"===e&&"/"!==f[0]&&(f="/"+f);return f}function p(c){return function(){null==e&&(e=v(function(){e=null;c()}))}}function g(c,e,f){var g=c.indexOf("?"),h=c.indexOf("#"),k=-1<g?
g:-1<h?h:c.length;if(-1<g){var g=N(c.slice(g+1,-1<h?h:c.length)),l;for(l in g)e[l]=g[l]}if(-1<h)for(l in e=N(c.slice(h+1)),e)f[l]=e[l];return c.slice(0,k)}function k(){switch(n.charAt(0)){case "#":return f("hash").slice(n.length);case "?":return f("search").slice(n.length)+f("hash");default:return f("pathname").slice(n.length)+f("search")+f("hash")}}function h(e,f,h){var k={},l={};e=g(e,k,l);if(null!=f){for(var r in f)k[r]=f[r];e=e.replace(/:([^\/]+)/g,function(c,e){delete k[e];return f[e]})}(r=J(k))&&
(e+="?"+r);(l=J(l))&&(e+="#"+l);q?(h&&h.replace?c.history.replaceState(null,null,n+e):c.history.pushState(null,null,n+e),c.onpopstate()):c.location.href=n+e}var q="function"===typeof c.history.pushState,v="function"===typeof setImmediate?setImmediate:setTimeout,n="#!",e;return{setPrefix:function(c){n=c},getPath:k,setPath:h,defineRoutes:function(e,f,h){function l(){var c=k(),l={},r=g(c,l,l),n;for(n in e){var p=new RegExp("^"+n.replace(/:[^\/]+?\.{3}/g,"(.*?)").replace(/:[^\/]+/g,"([^\\/]+)")+"/?$");
if(p.test(r)){r.replace(p,function(){for(var g=n.match(/:[^\/]+/g)||[],h=[].slice.call(arguments,1,-2),k=0;k<g.length;k++)l[g[k].replace(/:|\./g,"")]=decodeURIComponent(h[k]);f(e[n],l,c,n)});return}}h(c,l)}q?c.onpopstate=p(l):"#"===n.charAt(0)&&(c.onhashchange=l);l();return l},link:function(c){c.dom.setAttribute("href",n+c.attrs.href);c.dom.onclick=function(c){c.ctrlKey||c.metaKey||c.shiftKey||2===c.which||(c.preventDefault(),c.redraw=!1,c=this.getAttribute("href"),0===c.indexOf(n)&&(c=c.slice(n.length)),
h(c,void 0,void 0))}}}};v.route=function(c,f){function p(c){return c}var g=W(c),k,h,v,z,n,e={view:function(){return[v(q(h,null,z,void 0,void 0,void 0))]}},l=function(c,l,q){h="div";v=p;z=null;f(c,e);g.defineRoutes(q,function(e,f,g){var l="function"!==typeof e.view,q=p,r=k=function(p){r===k&&(k=null,h=null!=p?p:l?"div":e,v=q,z=f,n=g,c.redraw(!0))},t=function(){r()};l&&("function"===typeof e.render&&(q=e.render.bind(e)),"function"===typeof e.onmatch&&(t=e.onmatch));t.call(e,r,f,g)},function(){g.setPath(l,
null,{replace:!0})})};l.link=g.link;l.prefix=g.setPrefix;l.set=g.setPath;l.get=function(){return n};return l}(window,v.mount);v.withAttr=function(c,f,p){return function(g){return f.call(p||this,c in g.currentTarget?g.currentTarget[c]:g.currentTarget.getAttribute(c))}};v.prop=P;v.render=Q.render;v.redraw=M.publish;v.request=L.request;v.jsonp=L.jsonp;v.parseQueryString=N;v.buildQueryString=J;v.version="1.0.0-rc.2";"undefined"!==typeof module?module.exports=v:window.m=v};
c[h];if(null!=b&&"string"!==typeof b)for(h in b)h in c||(f.style[h]="")}else if(a in f&&"href"!==a&&"list"!==a&&"form"!==a&&"width"!==a&&"height"!==a&&void 0===e){if("input"!==b.tag||"value"!==a||b.dom.value!==c||b.dom!==B.activeElement)f[a]=c}else"boolean"===typeof c?c?f.setAttribute(a,""):f.removeAttribute(a):f.setAttribute("className"===a?"class":a,c)}}function G(b){return"oninit"===b||"oncreate"===b||"onupdate"===b||"onremove"===b||"onbeforeremove"===b||"onbeforeupdate"===b}function v(b,a,d){var c=
b.dom,e=function(a){var b=d.call(c,a);"function"===typeof F&&F.call(c,a);return b};if(a in c)c[a]="function"===typeof d?e:null;else{var f=a.slice(2);void 0===b.events&&(b.events={});null!=b.events[a]&&c.removeEventListener(f,b.events[a],!1);"function"===typeof d&&(b.events[a]=e,c.addEventListener(f,b.events[a],!1))}}function D(b,a,c){"function"===typeof b.oninit&&b.oninit.call(a.state,a);"function"===typeof b.oncreate&&c.push(b.oncreate.bind(a.state,a))}function O(b,a,c,e){e?D(b,a,c):"function"===
typeof b.onupdate&&c.push(b.onupdate.bind(a.state,a))}function H(b,a){Object.keys(a).forEach(function(c){b[c]=a[c]})}var B=c.document,I=B.createDocumentFragment(),F;return{render:function(b,a){if(!b)throw Error("Ensure the DOM element being passed to m.route/m.mount/m.render is not undefined.");var c=[],e=B.activeElement;null==b.vnodes&&(b.textContent="");a instanceof Array||(a=[a]);k(b,b.vnodes,q.normalizeChildren(a),c,null,void 0);b.vnodes=a;for(var f=0;f<c.length;f++)c[f]();B.activeElement!==e&&
e.focus()},setEventCallback:function(b){return F=b}}}(window),U=function(c){var f=0,p=null,g="function"===typeof requestAnimationFrame?requestAnimationFrame:setTimeout;return function(k){var h=Date.now();!0===k||0===f||16<=h-f?(f=h,c()):null===p&&(p=g(function(){p=null;c();f=Date.now()},16-(h-f)))}},V=function(c,f,p,g){g=U(g);null!=f&&f.setEventCallback(function(c){!1!==c.redraw&&p.publish()});null!=p&&(c.redraw&&p.unsubscribe(c.redraw),p.subscribe(g));return c.redraw=g};v.mount=function(c,f){return function(p,
g){if(null===g)c.render(p,[]),f.unsubscribe(p.redraw),delete p.redraw;else{if(null==g.view)throw Error("m.mount(element, component) expects a component, not a vnode");V(p,c,f,function(){c.render(p,q(g,void 0,void 0,void 0,void 0,void 0))})()}}}(Q,M);var N=function(c){if(""===c||null==c)return{};"?"===c.charAt(0)&&(c=c.slice(1));c=c.split("&");for(var f={},p={},g=0;g<c.length;g++){var k=c[g].split("="),h=decodeURIComponent(k[0]),k=2===k.length?decodeURIComponent(k[1]):"";"true"===k?k=!0:"false"===
k&&(k=!1);var y=h.split(/\]\[?|\[/),q=f;-1<h.indexOf("[")&&y.pop();for(var n=0;n<y.length;n++){var h=y[n],e=y[n+1],e=""==e||!isNaN(parseInt(e,10)),l=n===y.length-1;""===h&&(h=y.slice(0,n).join(),null==p[h]&&(p[h]=0),h=p[h]++);null==q[h]&&(q[h]=l?k:e?[]:{});q=q[h]}}return f},W=function(c){function f(e){var f=c.location[e].replace(/(?:%[a-f89][a-f0-9])+/gim,decodeURIComponent);"pathname"===e&&"/"!==f[0]&&(f="/"+f);return f}function p(c){return function(){null==e&&(e=v(function(){e=null;c()}))}}function g(c,
e,f){var g=c.indexOf("?"),h=c.indexOf("#"),k=-1<g?g:-1<h?h:c.length;if(-1<g){var g=N(c.slice(g+1,-1<h?h:c.length)),l;for(l in g)e[l]=g[l]}if(-1<h)for(l in e=N(c.slice(h+1)),e)f[l]=e[l];return c.slice(0,k)}function k(){switch(n.charAt(0)){case "#":return f("hash").slice(n.length);case "?":return f("search").slice(n.length)+f("hash");default:return f("pathname").slice(n.length)+f("search")+f("hash")}}function h(e,f,h){var k={},l={};e=g(e,k,l);if(null!=f){for(var r in f)k[r]=f[r];e=e.replace(/:([^\/]+)/g,
function(c,e){delete k[e];return f[e]})}(r=J(k))&&(e+="?"+r);(l=J(l))&&(e+="#"+l);q?(h&&h.replace?c.history.replaceState(null,null,n+e):c.history.pushState(null,null,n+e),c.onpopstate()):c.location.href=n+e}var q="function"===typeof c.history.pushState,v="function"===typeof setImmediate?setImmediate:setTimeout,n="#!",e;return{setPrefix:function(c){n=c},getPath:k,setPath:h,defineRoutes:function(e,f,h){function l(){var c=k(),l={},r=g(c,l,l),n;for(n in e){var p=new RegExp("^"+n.replace(/:[^\/]+?\.{3}/g,
"(.*?)").replace(/:[^\/]+/g,"([^\\/]+)")+"/?$");if(p.test(r)){r.replace(p,function(){for(var g=n.match(/:[^\/]+/g)||[],h=[].slice.call(arguments,1,-2),k=0;k<g.length;k++)l[g[k].replace(/:|\./g,"")]=decodeURIComponent(h[k]);f(e[n],l,c,n)});return}}h(c,l)}q?c.onpopstate=p(l):"#"===n.charAt(0)&&(c.onhashchange=l);l();return l},link:function(c){c.dom.setAttribute("href",n+c.attrs.href);c.dom.onclick=function(c){c.ctrlKey||c.metaKey||c.shiftKey||2===c.which||(c.preventDefault(),c.redraw=!1,c=this.getAttribute("href"),
0===c.indexOf(n)&&(c=c.slice(n.length)),h(c,void 0,void 0))}}}};v.route=function(c,f){function p(c){return c}var g=W(c),k,h,v,z,n,e={view:function(){return[v(q(h,null,z,void 0,void 0,void 0))]}},l=function(c,l,q){h="div";v=p;z=null;f(c,e);g.defineRoutes(q,function(e,f,g){var l="function"!==typeof e.view,q=p,r=k=function(p){r===k&&(k=null,h=null!=p?p:l?"div":e,v=q,z=f,n=g,c.redraw(!0))},t=function(){r()};l&&("function"===typeof e.render&&(q=e.render.bind(e)),"function"===typeof e.onmatch&&(t=e.onmatch));
t.call(e,r,f,g)},function(){g.setPath(l,null,{replace:!0})})};l.link=g.link;l.prefix=g.setPrefix;l.set=g.setPath;l.get=function(){return n};return l}(window,v.mount);v.withAttr=function(c,f,p){return function(g){return f.call(p||this,c in g.currentTarget?g.currentTarget[c]:g.currentTarget.getAttribute(c))}};v.prop=P;v.render=Q.render;v.redraw=M.publish;v.request=L.request;v.jsonp=L.jsonp;v.parseQueryString=N;v.buildQueryString=J;v.version="1.0.0-rc.2";"undefined"!==typeof module?module.exports=v:
window.m=v};