elements-lite
Advanced tools
Comparing version 0.3.8 to 0.3.9
/* | ||
MIT License | ||
*/ | ||
!function(u,h,v){function f(a,b,c){var d,e={};a=a.replace(C,function(a,b,c,d,f){e["."==b?(b="class",e[b]&&(c=e[b]+" "+c),b):"#"==b?"id":c]=(f?d.slice(1,-1):d)||c;return""})||"div";d=(q[a]||(q[a]=h.createElement(a))).cloneNode(!0).set(e);return c?(m[a]&&d.setAttribute("data-call",a),d):m[a]&&m[a].call(d,b)||d.set(b)}function n(a,b){if(a){if("string"==typeof a||"number"==typeof a)a=f.text(a);else if(!("nodeType"in a)&&"length"in a){for(var c=a.length,d=0,e=h.createDocumentFragment();d<c;)n.call(e,a[d++]); | ||
a=e}a.nodeType&&this.insertBefore(a,(!0===b?this.firstChild:"number"==typeof b?this.childNodes[0>b?this.childNodes.length-b-2:b]:b)||null);a.appendHook&&a.appendHook()}return this}function w(a){return-1<(" "+this.className+" ").indexOf(" "+a+" ")}function x(a){this.className+=this.className?w.call(this,a)?"":" "+a:a;return this}function D(a){this.className=(" "+this.className+" ").replace(" "+a+" "," ").trim();return this}function E(){this.parentNode&&this.parentNode.removeChild(this);Event.removeAll&& | ||
!function(u,h,v){function f(a,b,c){var d,e={};a=a.replace(C,function(a,b,c,d,f){e["."==b?(e[b="class"]&&(c=e[b]+" "+c),b):"#"==b?"id":c]=f?d.slice(1,-1):d||c;return""})||"div";d=(q[a]||(q[a]=h.createElement(a))).cloneNode(!0).set(e);return c?(m[a]&&d.setAttribute("data-call",a),d):m[a]&&m[a].call(d,b)||d.set(b)}function n(a,b){var c,d=0,e=typeof a;if(a){if("string"==e||"number"==e)a=f.text(a);else if(!("nodeType"in a)&&"length"in a){e=a.length;for(c=h.createDocumentFragment();d<e;)n.call(c,a[d++]); | ||
a=c}a.nodeType&&this.insertBefore(a,(!0===b?this.firstChild:"number"==typeof b?this.childNodes[0>b?this.childNodes.length-b-2:b]:b)||null);a.appendHook&&a.appendHook()}return this}function w(a){return-1<(" "+this.className+" ").indexOf(" "+a+" ")}function x(a){this.className+=this.className?w.call(this,a)?"":" "+a:a;return this}function D(a){this.className=(" "+this.className+" ").replace(" "+a+" "," ").trim();return this}function E(){this.parentNode&&this.parentNode.removeChild(this);Event.removeAll&& | ||
Event.removeAll(this);this.killHook&&this.killHook();this.empty&&this.empty();return this}function J(a){var b,c=a._childs;if(!c)for(a._childs=c=[];b=a.firstChild;)c.push(b),a.removeChild(b);return c}function r(a,b){var c,d=this;if(c=!b&&d.getAttribute("data-call"))d.removeAttribute("data-call"),m[c].call(d);if(c=!b&&d.getAttribute("data-bind"))if(d.getAttribute("lang"),"{"==c.charAt(0)&&(c='txt:"'+c.replace(/"/g,'\\"')+'"'),c="n d p r->d&&("+c.replace(K,"(p['$1']?(r=p['$1'](n,d,$2)||r):(n['$1']=$2.format(d))),")+ | ||
@@ -10,6 +10,6 @@ "r)",c.fn()(d,a,L))return d;for(d=d.firstChild;d;d=d.nextSibling)1==d.nodeType&&r.call(d,a);return this}function F(a,b,c){var d=0,e=[],f=["_"];b=b.replace(C,function(a,b,c,d){f.push("."==b?"(' '+_.className+' ').indexOf(' "+c+" ')>-1":"#"==b?"_.id=='"+c+"'":"_.getAttribute('"+c+"')"+(d?"=='"+d+"'":""));return""})||"*";b=a.getElementsByTagName(b);for(var g=Fn(f.join("&&"));a=b[d++];)if(g(a)){if(c)return a;e.push(a)}return c?null:e}function s(a){this._nodes=a}function y(a,b){if(a)for(b in e)a[b]=e[b]; | ||
b);c=c.childNodes;if(1==c.length)return c[0];e=[];for(d=c.length;d--;)e[d]=c[d];return e}function A(a,b){this.name=b;this.parent=a;this.el=f("div");this.el.plugin=this;return this}function g(a,b){return g[b?B(b):p][a]||a}function B(a){if(!a)return p;a=(a||"").toLowerCase();return g[a]?a:(a=a.split("-")[0],g[a])?a:p}function H(a,b){Object.merge(g[a]||(g[a]={}),b)}var p,q={},m={},I=h.createElement,e=(u.HTMLElement||u.Element||f)[v],C=/([.#:[])([-\w]+)(?:=((["'\/])(?:\\?.)*?\4|[-\w]+)])?]?/g,G=/^([ \t]*)(\:?)((?:(["'\/])(?:\\?.)*?\4|[-\w\:.#\[\]=])+)[ \t]*(.*)$/gm, | ||
K=/[;\s]*(\w+)(?:\s*\:((?:(["'\/])(?:\\?.)*?\3|[-,\s\w])*))?/g,L=f.bindings={txt:function(a,b,c){a.txt(c.format(b))},"class":function(a,b,c,d){a.toggleClass(c,d.fn("_")(b))},html:function(a,b,c){a.innerHTML=c.format(b)},each:function(a,b,c){var d=J(a);c&&a.empty().append(c.map(function(a){return d.map(function(b){return r.call(b.cloneNode(!0),a)})}));return a}};u.El=f;e.append=n;e.after=function(a,b){n.call(a.parentNode,this,b?a:a.nextSibling);return this};e.to=function(a,b){n.call(a,this,b);return this}; | ||
e.hasClass=w;e.addClass=x;e.rmClass=D;e.toggleClass=function(a,b){1==arguments.length&&(b=!w.call(this,a));return(b?x:D).call(this,a),b};e.empty=function(){for(var a;a=this.firstChild;)E.call(a);return this};e.kill=E;e.on=function(a,b){Event.add(this,a,b);return this};e.non=function(a,b){Event.remove(this,a,b);return this};e.set=function(a){var b,c=typeof a;if(!a)return this;if("string"==c||"number"==c||a.nodeType||"length"in a)n.call(this,a);else for(c in a)b=a[c],"class"==c?x.call(this,b):b?"string"== | ||
typeof b?(this.setAttribute(c,b),"id"!=c&&"name"!=c||"\v"!="v"||this.mergeAttributes(I("<INPUT "+c+'="'+b+'"/>'),!1)):this[c]=b:this.removeAttribute(c);return this};e.render=r;e.txt=function(a){var b="textContent"in this?"textContent":"innerText";return arguments.length?this[b]=a:this[b]};e.find="\v"!=="v"&&e.querySelector||function(a){return F(this,a,!0)};e.findAll=e.querySelectorAll?function(a){return new s(this.querySelectorAll(a))}:function(a){return new s(F(this,a))};f.wrap=s;s.prototype=Object.keys(e).reduce(function(a, | ||
b){a[b]=function(){for(var a=this._nodes,d=0,f=a.length;d<f;)e[b].apply(a[d++],arguments);return this};return a},{});e===f[v]&&(h.createElement=function(a){return y(I(a))},y(h.body));f[v]=e;f.get=function(a){"string"==typeof a&&(a=h.getElementById(a));return a&&a.to?a:y(a)};z._el=q;z._fn=m;f.cache=z;f.text=function(a){return h.createTextNode(a)};A.prototype.done=function(){f.cache(this.name,this.el.removeChild(this.el.firstChild),r);this.el.plugin=null;return this.parent};t.plugins={template:A};f.create= | ||
f.tpl=function(a){return t(a).render()};f.include=function(a,b,c){b=f.get(a);(new A(null,a)).el.append(f.tpl(b.innerHTML)).plugin.done();b.kill()};f.i18n=g;g.get=B;g.use=function(a){a=B(a);p!=(p=a)&&(g[a]=g[a]||{});return h.documentElement.lang=a};g.add=H;g.def=function(a){Object.each(a,function(b,c){H(c,a)})}}(window,document,"prototype"); | ||
K=/[;\s]*(\w+)(?:\s*\:((?:(["'\/])(?:\\?.)*?\3|[-,\s\w])*))?/g,L=f.bindings={txt:function(a,b,c){a.txt(c.format(b))},"class":function(a,b,c,d){a.toggleClass(c,d.fn("_")(b))},html:function(a,b,c){a.innerHTML=c.format(b)},each:function(a,b,c){function d(a){return r.call(a.cloneNode(!0),this)}var e=J(a);c&&a.empty().append(c.map(function(a){return e.map(d,a)}));return a}};u.El=f;e.append=n;e.after=function(a,b){n.call(a.parentNode,this,b?a:a.nextSibling);return this};e.to=function(a,b){n.call(a,this, | ||
b);return this};e.hasClass=w;e.addClass=x;e.rmClass=D;e.toggleClass=function(a,b){1==arguments.length&&(b=!w.call(this,a));return(b?x:D).call(this,a),b};e.empty=function(){for(var a;a=this.firstChild;)E.call(a);return this};e.kill=E;e.on=function(a,b){Event.add(this,a,b);return this};e.non=function(a,b){Event.remove(this,a,b);return this};e.set=function(a){var b,c=typeof a;if(!a)return this;if("string"==c||"number"==c||a.nodeType||"length"in a)n.call(this,a);else for(c in a)b=a[c],"class"==c?x.call(this, | ||
b):b?"string"==typeof b?(this.setAttribute(c,b),"id"!=c&&"name"!=c||"\v"!="v"||this.mergeAttributes(I("<INPUT "+c+'="'+b+'">'),!1)):this[c]=b:this.removeAttribute(c);return this};e.render=r;e.txt=function(a){var b="textContent"in this?"textContent":"innerText";return arguments.length?this[b]=a:this[b]};e.find="\v"!=="v"&&e.querySelector||function(a){return F(this,a,!0)};e.findAll=e.querySelectorAll?function(a){return new s(this.querySelectorAll(a))}:function(a){return new s(F(this,a))};f.wrap=s;s.prototype= | ||
Object.keys(e).reduce(function(a,b){a[b]=function(){for(var a=this._nodes,d=0,f=a.length;d<f;)e[b].apply(a[d++],arguments);return this};return a},{});e===f[v]&&(h.createElement=function(a){return y(I(a))},y(h.body));f[v]=e;f.get=function(a){"string"==typeof a&&(a=h.getElementById(a));return a&&a.to?a:y(a)};z._el=q;z._fn=m;f.cache=z;f.text=function(a){return h.createTextNode(a)};A.prototype.done=function(){f.cache(this.name,this.el.removeChild(this.el.firstChild),r);this.el.plugin=null;return this.parent}; | ||
t.plugins={template:A};f.create=f.tpl=function(a){return t(a).render()};f.include=function(a,b,c){b=f.get(a);(new A(null,a)).el.append(f.tpl(b.innerHTML)).plugin.done();b.kill()};f.i18n=g;g.get=B;g.use=function(a){a=B(a);p!=(p=a)&&(g[a]=g[a]||{});return h.documentElement.lang=a};g.add=H;g.def=function(a){Object.each(a,function(b,c){H(c,a)})}}(window,document,"prototype"); |
43
index.js
@@ -5,4 +5,4 @@ | ||
/** | ||
* @version 0.3.8 | ||
* @date 2014-09-19 | ||
* @version 0.3.9 | ||
* @date 2014-10-16 | ||
* @stability 1 - Experimental | ||
@@ -37,6 +37,7 @@ * @author Lauri Rooden <lauri@rooden.ee> | ||
if (arr) node.empty().append(arr.map(function(obj) { | ||
return childs.map(function(el) { | ||
return render.call(el.cloneNode(true), obj) | ||
}) | ||
return childs.map(renderClone, obj) | ||
})) | ||
function renderClone(el) { | ||
return render.call(el.cloneNode(true), this) | ||
} | ||
return node | ||
@@ -49,5 +50,7 @@ } | ||
* Turns CSS selector like syntax to DOM Node | ||
* @returns {Node} | ||
* | ||
* @example | ||
* El("input#123.nice[type=checkbox]:checked:disabled[data-lang=en]") | ||
* @returns {Node} | ||
* El("input#12.nice[type=checkbox]:checked:disabled[data-lang=en].class") | ||
* <input id="12" class="nice class" type="checkbox" checked="checked" disabled="disabled" data-lang="en"> | ||
*/ | ||
@@ -60,6 +63,8 @@ | ||
pre[ | ||
op == "." ? (op = "class", (pre[op] && (key = pre[op] + " " + key)), op) : | ||
op == "#" ? "id" : | ||
op == "." ? | ||
((pre[op = "class"] && (key = pre[op] + " " + key)), op) : | ||
op == "#" ? | ||
"id" : | ||
key | ||
] = (quotation ? val.slice(1, -1): val) || key | ||
] = quotation ? val.slice(1, -1) : val || key | ||
return "" | ||
@@ -79,5 +84,8 @@ }) || "div" | ||
function append(child, before) { | ||
var el = this | ||
if (child) { | ||
if (typeof child == "string" || typeof child == "number") child = El.text(child) | ||
var fragment | ||
, el = this | ||
, i = 0 | ||
, tmp = typeof child | ||
if (child) { | ||
if (tmp == "string" || tmp == "number") child = El.text(child) | ||
else if ( !("nodeType" in child) && "length" in child ) { | ||
@@ -87,6 +95,5 @@ // document.createDocumentFragment is unsupported in IE5.5 | ||
for ( | ||
var len = child.length | ||
, i = 0 | ||
tmp = child.length | ||
, fragment = document.createDocumentFragment(); | ||
i < len; ) append.call(fragment, child[i++]); | ||
i < tmp; ) append.call(fragment, child[i++]) | ||
child = fragment | ||
@@ -199,3 +206,3 @@ } | ||
if ((key == "id" || key == "name") && "\v" == "v") { | ||
el.mergeAttributes(createElement('<INPUT '+key+'="' + val + '"/>'), false) | ||
el.mergeAttributes(createElement('<INPUT '+key+'="' + val + '">'), false) | ||
} | ||
@@ -469,2 +476,4 @@ } else el[key] = val | ||
} | ||
// navigator.userLanguage for IE, navigator.language for others | ||
// var lang = navigator.language || navigator.userLanguage; | ||
// setLang("en") | ||
@@ -471,0 +480,0 @@ //*/ |
{ | ||
"name": "elements-lite", | ||
"version": "0.3.8", | ||
"version": "0.3.9", | ||
"stability": 1, | ||
@@ -35,4 +35,3 @@ "license": "MIT", | ||
"buildman": { | ||
"dist/index-min.js": "index.js", | ||
"dist/responsive-min.js": "lib/responsive.js" | ||
"dist/index-min.js": "index.js" | ||
}, | ||
@@ -39,0 +38,0 @@ "testling": { |
@@ -9,4 +9,4 @@ [1]: https://secure.travis-ci.org/litejs/elements-lite.png | ||
@version 0.3.8 | ||
@date 2014-09-19 | ||
@version 0.3.9 | ||
@date 2014-10-16 | ||
@stability 1 - Experimental | ||
@@ -44,3 +44,4 @@ | ||
It is a template engine inspired by Haml and implemented with JavaScript for browser. | ||
It is a template engine inspired by Haml | ||
but uses CSS selectors like syntax for describing elements and attributes. | ||
@@ -135,5 +136,5 @@ | ||
Copyright (c) 2012, 2014 Lauri Rooden <lauri@rooden.ee> | ||
Copyright (c) 2012-2014 Lauri Rooden <lauri@rooden.ee> | ||
[The MIT License](http://lauri.rooden.ee/mit-license.txt) | ||
@@ -302,2 +302,4 @@ require("browser-upgrade-lite") | ||
it ("supports IF binding"). | ||
done() | ||
@@ -304,0 +306,0 @@ |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
138
102645
18
2438