diff --git a/.publish b/.publish index d98021b..36264ac 160000 --- a/.publish +++ b/.publish @@ -1 +1 @@ -Subproject commit d98021b8b49b6b688deeee44415289dd2a7bb72a +Subproject commit 36264ac3d7caa8d08f5ec7da0ca686df70859508 diff --git a/dist/murk.js b/dist/murk.js index 39e46c5..42837d0 100644 --- a/dist/murk.js +++ b/dist/murk.js @@ -1 +1 @@ -!function(e,t){"undefined"!=typeof module&&module.exports?module.exports=t:window[e]=t}("murk",function e(t){function r(e,t,r){return"boolean"==typeof t&&"undefined"==typeof r&&(r=t,t=r),r="undefined"!=typeof r?r:!0,"undefined"!=typeof t&&"string"==typeof e?(x.model[e]=t,x.elems.hasOwnProperty(e)&&l(x.elems[e]),this):(r?P(x.model,e):x.model=e,n(),this)}function o(e){return"undefined"!=typeof e?x.model.hasOwnProperty(e)?x.model[e]:null:x.model}function n(){var e=x.dom.length?x.dom:i();Array.prototype.forEach.call(e,l)}function s(e){e="undefined"==typeof e?document:e;var t=i(e);Array.prototype.forEach.call(t,l)}function i(e){return e="undefined"==typeof e?document:e,e.getElementsByTagName("*")}function l(e){var t,r;t=b(e),r=t(v.selectorPrefix),r&&(t(v.selectorPrefix+"-id")||t(v.selectorPrefix+"-id",v.id),t(v.selectorPrefix+"-id")==v.id&&(x.elems.hasOwnProperty(r)||(x.elems[r]=e,~x.keys.indexOf(r)||(x.keys.push(r),x.dom.push(e)),e.innerHTML&&!x.model.hasOwnProperty(r)&&(x.model[r]=e.innerHTML)),x.model.hasOwnProperty(r)&&(a(r),++x.totalCount)))}function a(e){x.subscribers.hasOwnProperty(e)||(x.subscribers[e]=Array.prototype.slice.call(v.defaultSubscribers));for(var t,r=Array.prototype.slice.call(x.subscribers[e]);t=r.shift();)t.call(x.elems[e],e)}function f(e,t){function r(e){x.subscribers.hasOwnProperty(e)||(x.subscribers[e]=Array.prototype.slice.call(v.defaultSubscribers)),x.subscribers[e].push(t)}return e instanceof Array||(e=[e]),Array.prototype.forEach.call(e,r),this}function c(e){var t,r,o=b(e);if(o&&(t=o(v.selectorPrefix+"-repeat-key"),r=o(v.selectorPrefix+"-repeat-bind"),t&&this.hasOwnProperty(t)&&(e.innerHTML!=this[t]&&m(e,this[t]),r))){var n=this.$key+"."+t;o(v.selectorPrefix)||o(v.selectorPrefix,n),l(e)}}function d(e){var t,r,o,n,s;if(x.model[e]instanceof Array){if("none"!=this.style.display&&(this.style.display="none"),t=x.model[e],r=b(this),x.repeats.hasOwnProperty(e)||(x.repeats[e]={}),n=document.createDocumentFragment(),o=Object.keys(x.repeats[e]),o.length>t.length)for(var i=t.length;it.length)for(var s=t.length;s
-
embedded example
+
embedded example
diff --git a/examples/build/templates/repeat-example.tmpl b/examples/build/templates/repeat-example.tmpl index 931b251..530dbb1 100644 --- a/examples/build/templates/repeat-example.tmpl +++ b/examples/build/templates/repeat-example.tmpl @@ -28,7 +28,7 @@
- Name: + Name:
Age: diff --git a/examples/index.html b/examples/index.html index f804848..0a7e109 100644 --- a/examples/index.html +++ b/examples/index.html @@ -21,7 +21,7 @@

Basic Example:

-
embedded example
+
embedded example
@@ -149,7 +149,7 @@

Repeat Example:

- Name: + Name:
Age: diff --git a/examples/js/murk.js b/examples/js/murk.js index 69d258f..637e48d 100644 --- a/examples/js/murk.js +++ b/examples/js/murk.js @@ -191,12 +191,11 @@ // as well as the current key being processed. it tries to be extremely // light by only doing reads, and saving writes until the end. function handleRepeat(key) { - var repeatModel, attrs, repeatElKeys, frag, processRepeats; + var repeatModel, repeatElKeys, frag, processRepeats; if (state.model[key] instanceof Array) { // hide our first elem, so we can use it later if (this.style.display != 'none') this.style.display = 'none'; repeatModel = state.model[key]; - attrs = attr(this); // we keep reference of all of our repeats // inside of state.repeats, so we always @@ -223,7 +222,7 @@ // processes each repeat individually processRepeats = function(repeat, i) { - var el, atts, $key = (key + '.$' + i), newEl = false; + var el, $key = (key + '.$' + i), newEl = false; // we make a new key, out of our current key // and setup any new elems that we might need @@ -239,14 +238,13 @@ // are fresh, and non object things // can be check simply like this if (el.innerHTML != repeatModel) { - atts = attr(el); // new els get sanitized if (newEl) { - atts(opts.selectorPrefix, 'rm'); - atts(opts.selectorPrefix + '-count', 'rm'); - atts(opts.selectorPrefix + '-bound', 'rm'); - atts(opts.selectorPrefix + '-repeat', $key); + delete el.dataset.murk; + delete el.dataset.murkCount; + delete el.dataset.murkBound; + el.dataset.murkRepeat = $key; } if (typeof repeat == 'object') { // allows us to keep ref of new $key, @@ -255,7 +253,7 @@ repeat.$key = $key; Array.prototype.forEach.call(el.getElementsByTagName('*'), processNodes, repeat); } else { - el.innerHTML = repeat; + setupTextNode(el, repeat); } // let their be light XD if (el.style.display == 'none') el.style.display = ''; @@ -273,26 +271,19 @@ // proccesses the filters added to any // given bound elem function processFiltersEvent(key) { - var attrs, filters, filterMutate, processFilter; - attrs = attr(this); - if (attrs) { - filters = attrs(opts.selectorPrefix + '-filter'); - filterMutate = attrs(opts.selectorPrefix + '-filter-mutate'); - if (filters) { - processFilter = function(filter) { - if (state.filters.hasOwnProperty(filter) && - state.model.hasOwnProperty(key)) { - var val = state.filters[filter].call(this, state.model[key]); - if (typeof val != 'undefined' && filterMutate) { - state.model[key] = val; - } - setupTextNode(this, val); - } - }; - if (filters.indexOf(',') != -1) filters = filters.split(','); - if (!(filters instanceof Array)) filters = [filters]; - Array.prototype.forEach.call(filters, processFilter, this); - } + var filters, processFilter; + if ('murkFilter' in this.dataset) { + filters = this.dataset.murkFilter; + processFilter = function(filter) { + if (state.filters.hasOwnProperty(filter) && + state.model.hasOwnProperty(key)) { + var val = state.filters[filter].call(this, state.model[key]); + setupTextNode(this, val); + } + }; + if (filters.indexOf(',') != -1) filters = filters.split(','); + if (!(filters instanceof Array)) filters = [filters]; + Array.prototype.forEach.call(filters, processFilter, this); } } @@ -325,9 +316,8 @@ // times we're interacting with our // elems function trackCountEvent() { - var count, attrs = attr(this); - count = attrs(opts.selectorPrefix + '-count'); - attrs(opts.selectorPrefix + '-count', (count ? parseInt(count,0)+1 : 1)); + var count = ('murkCount' in this.dataset ? this.dataset.murkCount : null); + this.dataset.murkCount = (count ? parseInt(count,0)+1 : 1); } // handles dom manipulation diff --git a/src/murk.js b/src/murk.js index 69d258f..637e48d 100644 --- a/src/murk.js +++ b/src/murk.js @@ -191,12 +191,11 @@ // as well as the current key being processed. it tries to be extremely // light by only doing reads, and saving writes until the end. function handleRepeat(key) { - var repeatModel, attrs, repeatElKeys, frag, processRepeats; + var repeatModel, repeatElKeys, frag, processRepeats; if (state.model[key] instanceof Array) { // hide our first elem, so we can use it later if (this.style.display != 'none') this.style.display = 'none'; repeatModel = state.model[key]; - attrs = attr(this); // we keep reference of all of our repeats // inside of state.repeats, so we always @@ -223,7 +222,7 @@ // processes each repeat individually processRepeats = function(repeat, i) { - var el, atts, $key = (key + '.$' + i), newEl = false; + var el, $key = (key + '.$' + i), newEl = false; // we make a new key, out of our current key // and setup any new elems that we might need @@ -239,14 +238,13 @@ // are fresh, and non object things // can be check simply like this if (el.innerHTML != repeatModel) { - atts = attr(el); // new els get sanitized if (newEl) { - atts(opts.selectorPrefix, 'rm'); - atts(opts.selectorPrefix + '-count', 'rm'); - atts(opts.selectorPrefix + '-bound', 'rm'); - atts(opts.selectorPrefix + '-repeat', $key); + delete el.dataset.murk; + delete el.dataset.murkCount; + delete el.dataset.murkBound; + el.dataset.murkRepeat = $key; } if (typeof repeat == 'object') { // allows us to keep ref of new $key, @@ -255,7 +253,7 @@ repeat.$key = $key; Array.prototype.forEach.call(el.getElementsByTagName('*'), processNodes, repeat); } else { - el.innerHTML = repeat; + setupTextNode(el, repeat); } // let their be light XD if (el.style.display == 'none') el.style.display = ''; @@ -273,26 +271,19 @@ // proccesses the filters added to any // given bound elem function processFiltersEvent(key) { - var attrs, filters, filterMutate, processFilter; - attrs = attr(this); - if (attrs) { - filters = attrs(opts.selectorPrefix + '-filter'); - filterMutate = attrs(opts.selectorPrefix + '-filter-mutate'); - if (filters) { - processFilter = function(filter) { - if (state.filters.hasOwnProperty(filter) && - state.model.hasOwnProperty(key)) { - var val = state.filters[filter].call(this, state.model[key]); - if (typeof val != 'undefined' && filterMutate) { - state.model[key] = val; - } - setupTextNode(this, val); - } - }; - if (filters.indexOf(',') != -1) filters = filters.split(','); - if (!(filters instanceof Array)) filters = [filters]; - Array.prototype.forEach.call(filters, processFilter, this); - } + var filters, processFilter; + if ('murkFilter' in this.dataset) { + filters = this.dataset.murkFilter; + processFilter = function(filter) { + if (state.filters.hasOwnProperty(filter) && + state.model.hasOwnProperty(key)) { + var val = state.filters[filter].call(this, state.model[key]); + setupTextNode(this, val); + } + }; + if (filters.indexOf(',') != -1) filters = filters.split(','); + if (!(filters instanceof Array)) filters = [filters]; + Array.prototype.forEach.call(filters, processFilter, this); } } @@ -325,9 +316,8 @@ // times we're interacting with our // elems function trackCountEvent() { - var count, attrs = attr(this); - count = attrs(opts.selectorPrefix + '-count'); - attrs(opts.selectorPrefix + '-count', (count ? parseInt(count,0)+1 : 1)); + var count = ('murkCount' in this.dataset ? this.dataset.murkCount : null); + this.dataset.murkCount = (count ? parseInt(count,0)+1 : 1); } // handles dom manipulation