diff --git a/mithril.js b/mithril.js index 777a957a..a70355a7 100644 --- a/mithril.js +++ b/mithril.js @@ -17,6 +17,10 @@ Vnode.normalizeChildren = function normalizeChildren(children) { var selectorParser = /(?:(^|#|\.)([^#\.\[\]]+))|(\[(.+?)(?:\s*=\s*("|'|)((?:\\["'\]]|.)*?)\5)?\])/g var selectorCache = {} var hasOwn = {}.hasOwnProperty +function isEmpty(object) { + for (var key in object) if (hasOwn.call(object, key)) return false + return true +} function compileSelector(selector) { var match, tag = "div", classes = [], attrs = {} while (match = selectorParser.exec(selector)) { @@ -37,6 +41,15 @@ function compileSelector(selector) { function execSelector(state, attrs, children) { var hasAttrs = false, childList, text var className = attrs.className || attrs.class + if (!isEmpty(state.attrs) && !isEmpty(attrs)) { + var newAttrs = {} + for(var key in attrs) { + if (hasOwn.call(attrs, key)) { + newAttrs[key] = attrs[key] + } + } + attrs = newAttrs + } for (var key in state.attrs) { if (hasOwn.call(state.attrs, key)) { attrs[key] = state.attrs[key] @@ -805,9 +818,10 @@ var coreRenderer = function($window) { } function onremove(vnode) { if (vnode.attrs && typeof vnode.attrs.onremove === "function") vnode.attrs.onremove.call(vnode.state, vnode) - if (typeof vnode.tag !== "string" && typeof vnode._state.onremove === "function") vnode._state.onremove.call(vnode.state, vnode) - if (vnode.instance != null) onremove(vnode.instance) - else { + if (typeof vnode.tag !== "string") { + if (typeof vnode._state.onremove === "function") vnode._state.onremove.call(vnode.state, vnode) + if (vnode.instance != null) onremove(vnode.instance) + } else { var children = vnode.children if (Array.isArray(children)) { for (var i = 0; i < children.length; i++) { @@ -968,9 +982,9 @@ var coreRenderer = function($window) { if (!Array.isArray(vnodes)) vnodes = [vnodes] updateNodes(dom, dom.vnodes, Vnode.normalizeChildren(vnodes), false, hooks, null, namespace === "http://www.w3.org/1999/xhtml" ? undefined : namespace) dom.vnodes = vnodes - for (var i = 0; i < hooks.length; i++) hooks[i]() // document.activeElement can return null in IE https://developer.mozilla.org/en-US/docs/Web/API/Document/activeElement if (active != null && $doc.activeElement !== active) active.focus() + for (var i = 0; i < hooks.length; i++) hooks[i]() } return {render: render, setEventCallback: setEventCallback} } @@ -1236,7 +1250,7 @@ m.request = requestService.request m.jsonp = requestService.jsonp m.parseQueryString = parseQueryString m.buildQueryString = buildQueryString -m.version = "1.1.5" +m.version = "1.1.6" m.vnode = Vnode if (typeof module !== "undefined") module["exports"] = m else window.m = m diff --git a/mithril.min.js b/mithril.min.js index 0e24f0e5..5595651b 100644 --- a/mithril.min.js +++ b/mithril.min.js @@ -1,44 +1,44 @@ -(function(){function B(a,d,e,g,f,p){return{tag:a,key:d,attrs:e,children:g,text:f,dom:p,domSize:void 0,state:void 0,_state:void 0,events:void 0,instance:void 0,skip:!1}}function D(a){var d=arguments[1],e=2;if(null==a||"string"!==typeof a&&"function"!==typeof a&&"function"!==typeof a.view)throw Error("The selector must be either a string or a component.");if("string"===typeof a){var g;if(!(g=M[a])){var f="div";for(var p=[],k={};g=P.exec(a);){var q=g[1],m=g[2];""===q&&""!==m?f=m:"#"===q?k.id=m:"."=== -q?p.push(m):"["===g[3][0]&&((q=g[6])&&(q=q.replace(/\\(["'])/g,"$1").replace(/\\\\/g,"\\")),"class"===g[4]?p.push(q):k[g[4]]=""===q?q:q||!0)}0