elements-lite
Advanced tools
Comparing version 0.5.0 to 0.5.1
/* | ||
MIT License | ||
*/ | ||
!function(u,h,v){function f(a,b,c){var d,e={};a=a.replace(E,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 F(a){this.className=(" "+this.className+" ").replace(" "+a+" "," ").trim();return this}function G(a,b){1==arguments.length&&(b=!w.call(this,a));return(b?x:F).call(this, | ||
a),b}function H(){this.parentNode&&this.parentNode.removeChild(this);Event.removeAll&&Event.removeAll(this);this.killHook&&this.killHook();this.empty&&this.empty();return this}function y(a,b){var c=this;if(1==arguments.length){if(a&&a.constructor===Object){Object.each(a,function(a,b){y.call(c,b,a)});return}return c.getAttribute(a)}"id"!=a&&"name"!=a&&"type"!=a||"\v"!="v"?c.setAttribute(a,b):c.mergeAttributes(I("<INPUT "+a+'="'+b+'">'),!1)}function z(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(O,"(p['$1']?(r=p['$1'](n,d,$2)||r):(n['$1']=$2.format(d))),")+"r)",c.fn()(d,a,P))return d;for(d=d.firstChild;d;d=d.nextSibling)1==d.nodeType&&z.call(d,a);return this}function J(a,b,c){var d=0,e=[],f=["_"];b=b.replace(E,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 r(a){this._nodes=a}function A(a,b){if(a)for(b in e)a[b]=e[b];return a}function B(a,b,c){q[a]="string"==typeof b?f(b):b;c&&(m[a]=c)}function t(a){function b(a,c,g,h,k,l){for(k=c.length;k<=e[0];)e.shift(),d=d.plugin?d.plugin.done():d.parentNode;g?t.plugins[h]?(d=(new t.plugins[h](d,l)).el,e.unshift(k)):d.append(f.text("text"==h?l:a)):(h&& | ||
(d=f(h,0,1).to(d),e.unshift(k)),l&&(k=l.charAt(0),">"==k?(c+" "+l.slice(1)).replace(K,b):"="==k?d.set({"data-bind":l.slice(1)}):d.append(l.replace(/\\([=>:])/g,"$1"))))}var c=h.createDocumentFragment(),d=c,e=[-1];a.replace(K,b);c=c.childNodes;if(1==c.length)return c[0];e=[];for(d=c.length;d--;)e[d]=c[d];return e}function C(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?D(b):p][a]||a}function D(a){if(!a)return p;a=(a||"").toLowerCase();return g[a]? | ||
a:(a=a.split("-")[0],g[a])?a:p}function L(a,b){Object.merge(g[a]||(g[a]={}),b)}var p,M=h.body,I=h.createElement,N="textContent"in M?"textContent":"innerText",q={},m={},e=(u.HTMLElement||u.Element||f)[v],E=/([.#:[])([-\w]+)(?:=((["'\/])(?:\\?.)*?\4|[-\w]+)])?]?/g,K=/^([ \t]*)(@?)((?:(["'\/])(?:\\?.)*?\4|[-\w\:.#\[\]=])+)[ \t]*(.*)$/gm,O=/[;\s]*(\w+)(?:\s*\:((?:(["'\/])(?:\\?.)*?\3|[-,\s\w])*))?/g,P=f.bindings={"class":function(a,b,c,d){G.call(a,c,d.fn("_")(b))},html:function(a,b,c){a.innerHTML=c.format(b)}, | ||
txt:function(a,b,c){a.txt(c.format(b))},val:function(a,b,c){a.val(c.format(b))}};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=F;e.toggleClass=G;e.empty=function(){for(var a;a=this.firstChild;)H.call(a);return this};e.kill=H;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.attr=y;e.set=function(a,b,c){if(a)if("object"== | ||
typeof a)for(b in a)c=a[b],"class"==b?x.call(this,c):"string"==typeof c?y.call(this,b,c):c||this.removeAttribute(b);else n.call(this,a);return this};e.render=z;e.txt=function(a){return arguments.length?this[N]=a:this[N]};e.val=function(a){var b=this,c=b.type,d=b.options;if(arguments.length)return b.value=a;if("select-multiple"==c){a=[];for(c=0;b=d[c++];)!b.selected||b.disabled||b.parentNode.disabled||a.push(b.value);return a}return"checkbox"!=c&&"radio"!=c||b.checked?b.value||options&&options[b.selectedIndex].value|| | ||
"on":""};e.find="\v"!=="v"&&e.querySelector||function(a){return J(this,a,!0)};e.findAll=e.querySelectorAll?function(a){return new r(this.querySelectorAll(a))}:function(a){return new r(J(this,a))};f.wrap=r;r.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 A(I(a))},A(M));f[v]=e;f.get=function(a){"string"==typeof a&&(a=h.getElementById(a));return a&& | ||
a.to?a:A(a)};B._el=q;B._fn=m;f.cache=B;f.text=function(a){return h.createTextNode(a)};C.prototype.done=function(){f.cache(this.name,this.el.removeChild(this.el.firstChild),z);this.el.plugin=null;return this.parent};t.plugins={template:C};f.create=f.tpl=function(a){return t(a).render()};f.include=function(a,b,c){b=f.get(a);(new C(null,a)).el.append(f.tpl(b.innerHTML)).plugin.done();b.kill()};f.i18n=g;g.get=D;g.use=function(a){a=D(a);p!=(p=a)&&(g[a]=g[a]||{});return h.documentElement.lang=a};g.add= | ||
L;g.def=function(a){Object.each(a,function(b,c){L(c,a)})}}(window,document,"prototype"); | ||
!function(w,g,x){function f(a,b,c){var d,l={};a=a.replace(G,function(a,b,c,d,e,f){l["."==b?(l[b="class"]&&(c=l[b]+" "+c),b):"#"==b?"id":c]=f?e.slice(1,-1):e||c;return""})||"div";d=(t[a]||(t[a]=g.createElement(a))).cloneNode(!0).set(l);return c?(p[a]&&d.setAttribute("data-call",a),d):p[a]&&p[a].call(d,b)||d.set(b)}function q(a,b){var c,d=0,l=typeof a;if(a){if("string"==l||"number"==l)a=f.text(a);else if(!("nodeType"in a)&&"length"in a){l=a.length;for(c=g.createDocumentFragment();d<l;)q.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 y(a){return-1<(" "+this.className+" ").indexOf(" "+a+" ")}function z(a){this.className+=this.className?y.call(this,a)?"":" "+a:a;return this}function H(a){this.className=(" "+this.className+" ").replace(" "+a+" "," ").trim();return this}function I(a,b){1==arguments.length&&(b=!y.call(this,a));return(b?z:H).call(this, | ||
a),b}function J(){this.parentNode&&this.parentNode.removeChild(this);Event.removeAll&&Event.removeAll(this);this.killHook&&this.killHook();this.empty&&this.empty();return this}function A(a,b){var c=this;if(1==arguments.length){if(a&&a.constructor===Object){Object.each(a,function(a,b){A.call(c,b,a)});return}return c.getAttribute(a)}"id"!=a&&"name"!=a&&"type"!=a||"\v"!="v"?c.setAttribute(a,b):c.mergeAttributes(K("<INPUT "+a+'="'+b+'">'),!1)}function B(a,b){var c,d=this;if(c=!b&&d.getAttribute("data-call"))d.removeAttribute("data-call"), | ||
p[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(S,"(p['$1']?(r=p['$1'](n,d,$2)||r):(n['$1']=$2.format(d))),")+"r)",Fn(c)(d,a,T))return d;for(d=d.firstChild;d;d=d.nextSibling)1==d.nodeType&&B.call(d,a);return this}function L(a,b,c){var d=0,l=[];a=a.getElementsByTagName("*");for(var e=M(b.split(/\s*,\s*/).map(function(a){return"_.matches('"+a+"')"}).join("||"));b=a[d++];)if(e(b)){if(c)return b; | ||
l.push(b)}return c?null:l}function U(a){var b=["_"];(a=a.replace(G,function(a,d,e,f,k,h,m){h&&(k=k.slice(1,-1));k&&(m=k.length,k=k.replace(/'/g,"\\'"));b.push("."==d?"(' '+_.className+' ').indexOf(' "+e+" ')>-1":"#"==d?"_.id=='"+e+"'":":"==d&&V[e]||"(a=_.getAttribute('"+e+"'))"+(!f&&k?"=='"+k+"'":""));f&&b.push("^"==f?"a.slice(0,"+m+")=='"+k+"'":"|"==f?"a.split('-')[0]=='"+k+"'":"$"==f?"a.slice(-"+m+")=='"+k+"'":"~"==f?"(' '+a+' ').indexOf(' "+k+" ')>-1":"a.indexOf('"+k+"')>-1");return""}))&&"*"!= | ||
a&&b.unshift("_.nodeName=='"+a.toUpperCase()+"'");return b.join("&&")}function M(a){return N[a]||(N[a]=Function("_,a","return "+a))}function u(a){this._nodes=a}function C(a,b){if(a)for(b in e)a[b]=e[b];return a}function D(a,b,c){t[a]="string"==typeof b?f(b):b;c&&(p[a]=c)}function v(a){function b(a,c,h,m,g,n){for(g=c.length;g<=e[0];)e.shift(),d=d.plugin?d.plugin.done():d.parentNode;h?v.plugins[m]?(d=(new v.plugins[m](d,n)).el,e.unshift(g)):d.append(f.text("text"==m?n:a)):(m&&(d=f(m,0,1).to(d),e.unshift(g)), | ||
n&&(g=n.charAt(0),">"==g?(c+" "+n.slice(1)).replace(O,b):"="==g?d.set({"data-bind":n.slice(1)}):d.append(n.replace(/\\([=>:])/g,"$1"))))}var c=g.createDocumentFragment(),d=c,e=[-1];a.replace(O,b);c=c.childNodes;if(1==c.length)return c[0];e=[];for(d=c.length;d--;)e[d]=c[d];return e}function E(a,b){this.name=b;this.parent=a;this.el=f("div");this.el.plugin=this;return this}function h(a,b){return h[b?F(b):r][a]||a}function F(a){if(!a)return r;a=(a||"").toLowerCase();return h[a]?a:(a=a.split("-")[0],h[a])? | ||
a:r}function P(a,b){Object.merge(h[a]||(h[a]={}),b)}var r,Q=g.body,K=g.createElement,R="textContent"in Q?"textContent":"innerText",t={},p={},e=(w.HTMLElement||w.Element||f)[x],N={},G=/([.#:[])([-\w]+)(?:([~^$*|]?)=((["'\/])(?:\\?.)*?\5|[-\w]+)])?]?/g,W=/(\s*[>+]?\s*)((["'\/])(?:\\?.)*?\2|[^\s+>])+$/,V={empty:"!_.hasChildNodes()","first-child":"_.parentNode&&_.parentNode.firstChild==_","last-child":"_.parentNode&&_.parentNode.lastChild==_",link:"_.nodeName=='A'&&_.getAttribute('href')"},O=/^([ \t]*)(@?)((?:(["'\/])(?:\\?.)*?\4|[-\w\:.#\[\]=])+)[ \t]*(.*)$/gm, | ||
S=/[;\s]*(\w+)(?:\s*\:((?:(["'\/])(?:\\?.)*?\3|[-,\s\w])*))?/g,T=f.bindings={"class":function(a,b,c,d){I.call(a,c,d.fn("_")(b))},html:function(a,b,c){a.innerHTML=c.format(b)},txt:function(a,b,c){a.txt(c.format(b))},val:function(a,b,c){a.val(c.format(b))}};w.El=f;e.append=q;e.after=function(a,b){q.call(a.parentNode,this,b?a:a.nextSibling);return this};e.to=function(a,b){q.call(a,this,b);return this};e.hasClass=y;e.addClass=z;e.rmClass=H;e.toggleClass=I;e.empty=function(){for(var a;a=this.firstChild;)J.call(a); | ||
return this};e.kill=J;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.attr=A;e.set=function(a,b,c){if(a)if("object"==typeof a)for(b in a)c=a[b],"class"==b?z.call(this,c):"string"==typeof c?A.call(this,b,c):c||this.removeAttribute(b);else q.call(this,a);return this};e.render=B;e.txt=function(a){return arguments.length?this[R]=a:this[R]};e.val=function(a){var b=this,c=b.type,d=b.options;if(arguments.length)return b.value=a;if("select-multiple"== | ||
c){a=[];for(c=0;b=d[c++];)!b.selected||b.disabled||b.parentNode.disabled||a.push(b.value);return a}return"checkbox"!=c&&"radio"!=c||b.checked?b.value||options&&options[b.selectedIndex].value||"on":""};e.matches=e.matches||function(a){var b,c,d=a.replace(W,function(a,d,e,f,g){c=g+d.length;b=d.trim();return""}),e="+"==b?this.previousSibling:this.parentNode;return M(U(a.slice(c)))(this)?d?b?e&&e.matches&&e.matches(d)||!1:!!(e&&e.closest&&e.closest(d)):!0:!1};e.closest=e.closest||function(a){for(var b= | ||
this;b;b=b.parentNode)if(b.matches&&b.matches(a))return b;return null};e.find="\v"!=="v"&&e.querySelector||function(a){return L(this,a,!0)};e.findAll=e.querySelectorAll?function(a){return new u(this.querySelectorAll(a))}:function(a){return new u(L(this,a))};f.wrap=u;u.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[x]&&(g.createElement=function(a){return C(K(a))},C(Q));f[x]=e;f.get= | ||
function(a){"string"==typeof a&&(a=g.getElementById(a));return a&&a.to?a:C(a)};D._el=t;D._fn=p;f.cache=D;f.text=function(a){return g.createTextNode(a)};E.prototype.done=function(){f.cache(this.name,this.el.removeChild(this.el.firstChild),B);this.el.plugin=null;return this.parent};v.plugins={template:E};f.create=f.tpl=function(a){return v(a).render()};f.include=function(a,b,c){b=f.get(a);(new E(null,a)).el.append(f.tpl(b.innerHTML)).plugin.done();b.kill()};f.i18n=h;h.get=F;h.use=function(a){a=F(a); | ||
r!=(r=a)&&(h[a]=h[a]||{});return g.documentElement.lang=a};h.add=P;h.def=function(a){Object.each(a,function(b,c){P(c,a)})}}(window,document,"prototype"); |
127
index.js
@@ -5,4 +5,4 @@ | ||
/** | ||
* @version 0.5.0 | ||
* @date 2015-01-13 | ||
* @version 0.5.1 | ||
* @date 2015-02-02 | ||
* @stability 1 - Experimental | ||
@@ -23,4 +23,12 @@ * @author Lauri Rooden <lauri@rooden.ee> | ||
, proto = (window.HTMLElement || window.Element || El)[protoStr] | ||
, elRe = /([.#:[])([-\w]+)(?:=((["'\/])(?:\\?.)*?\4|[-\w]+)])?]?/g | ||
, tplRe = /^([ \t]*)(@?)((?:(["'\/])(?:\\?.)*?\4|[-\w\:.#\[\]=])+)[ \t]*(.*)$/gm | ||
, selectorCache = {} | ||
, selectorRe = /([.#:[])([-\w]+)(?:([~^$*|]?)=((["'\/])(?:\\?.)*?\5|[-\w]+)])?]?/g | ||
, lastSelectorRe = /(\s*[>+]?\s*)((["'\/])(?:\\?.)*?\2|[^\s+>])+$/ | ||
, pseudoClasses = { | ||
"empty": "!_.hasChildNodes()", | ||
"first-child": "_.parentNode&&_.parentNode.firstChild==_", | ||
"last-child" : "_.parentNode&&_.parentNode.lastChild==_", | ||
"link": "_.nodeName=='A'&&_.getAttribute('href')" | ||
} | ||
, templateRe = /^([ \t]*)(@?)((?:(["'\/])(?:\\?.)*?\4|[-\w\:.#\[\]=])+)[ \t]*(.*)$/gm | ||
, renderRe = /[;\s]*(\w+)(?:\s*\:((?:(["'\/])(?:\\?.)*?\3|[-,\s\w])*))?/g | ||
@@ -55,3 +63,3 @@ , bindings = El.bindings = { | ||
, pre = {} | ||
name = name.replace(elRe, function(_, op, key, val, quotation) { | ||
name = name.replace(selectorRe, function(_, op, key, fn, val, quotation) { | ||
pre[ | ||
@@ -196,2 +204,3 @@ op == "." ? | ||
//** modernBrowser | ||
if ((key == "id" || key == "name" || key == "type") && "\v" == "v") { | ||
@@ -202,2 +211,5 @@ el.mergeAttributes(createElement('<INPUT '+key+'="' + val + '">'), false) | ||
} | ||
/*/ | ||
el.setAttribute(key, val) | ||
//*/ | ||
} | ||
@@ -241,3 +253,3 @@ | ||
if (fn.fn()(node, data, bindings)) return node | ||
if (Fn(fn)(node, data, bindings)) return node | ||
} | ||
@@ -293,15 +305,8 @@ | ||
, out = [] | ||
, rules = ["_"] | ||
, tag = sel.replace(elRe, function(_, o, s, v) { | ||
rules.push( | ||
o == "." ? "(' '+_.className+' ').indexOf(' "+s+" ')>-1" : | ||
o == "#" ? "_.id=='"+s+"'" : | ||
"_.getAttribute('"+s+"')"+(v?"=='"+v+"'":"") | ||
) | ||
return "" | ||
}) || "*" | ||
, els = node.getElementsByTagName(tag) | ||
, fn = Fn(rules.join("&&")) | ||
, els = node.getElementsByTagName("*") | ||
, fn = selectorFn(sel.split(/\s*,\s*/).map(function(sel) { | ||
return "_.matches('" + sel + "')" | ||
}).join("||")) | ||
for (; el = els[i++]; ) if (fn(el)) { | ||
for (; (el = els[i++]); ) if (fn(el)) { | ||
if (first) return el | ||
@@ -313,2 +318,61 @@ out.push(el) | ||
function selectorFnStr(sel) { | ||
var rules = ["_"] | ||
, tag = sel.replace(selectorRe, function(_, op, key, fn, val, quotation, len) { | ||
if (quotation) val = val.slice(1, -1) | ||
if (val) { | ||
len = val.length | ||
val = val.replace(/'/g, "\\'") | ||
} | ||
rules.push( | ||
op == "." ? "(' '+_.className+' ').indexOf(' " + key + " ')>-1" : | ||
op == "#" ? "_.id=='" + key + "'" : | ||
op == ":" && pseudoClasses[key] || | ||
"(a=_.getAttribute('" + key + "'))" + (!fn && val ? "=='" + val + "'" : "") | ||
) | ||
if (fn) rules.push( | ||
fn == "^" ? "a.slice(0," + len + ")=='" + val + "'" : | ||
fn == "|" ? "a.split('-')[0]=='" + val + "'" : | ||
fn == "$" ? "a.slice(-" + len + ")=='" + val + "'" : | ||
fn == "~" ? "(' '+a+' ').indexOf(' " + val + " ')>-1" : | ||
"a.indexOf('" + val + "')>-1" // fn == "*" | ||
) | ||
return "" | ||
}) | ||
if (tag && tag != "*") rules.unshift("_.nodeName=='" + tag.toUpperCase() + "'") | ||
return rules.join("&&") | ||
} | ||
function selectorFn(str) { | ||
// jshint evil:true | ||
return selectorCache[str] || | ||
(selectorCache[str] = Function("_,a", "return " + str)) | ||
} | ||
proto.matches = proto.matches || function(sel) { | ||
var relation, from | ||
, parentSel = sel.replace(lastSelectorRe, function(_, _rel, a, b, start) { | ||
from = start + _rel.length | ||
relation = _rel.trim() | ||
return "" | ||
}) | ||
, next = relation == "+" ? this.previousSibling : this.parentNode | ||
, fn = selectorFn(selectorFnStr(sel.slice(from))) | ||
if (!fn(this)) return false | ||
if (parentSel) { | ||
if (!relation) return !!(next && next.closest && next.closest(parentSel)) | ||
return next && next.matches && next.matches(parentSel) || false | ||
} | ||
return true | ||
} | ||
proto.closest = proto.closest || function(sel) { | ||
for (var el = this; el; el = el.parentNode) if (el.matches && el.matches(sel)) return el | ||
return null | ||
} | ||
//** modernBrowser | ||
// Note: IE8 don't support :disabled | ||
@@ -326,3 +390,10 @@ proto.find = "\v" !== "v" && proto.querySelector || function(sel) { | ||
} | ||
/*/ | ||
proto.find = proto.querySelector | ||
proto.findAll = function(sel) { | ||
return new ElWrap(this.querySelectorAll(sel)) | ||
} | ||
//*/ | ||
function ElWrap(nodes) { | ||
@@ -346,2 +417,3 @@ this._nodes = nodes | ||
//** modernBrowser | ||
function extend(node, key) { | ||
@@ -354,13 +426,10 @@ if (node) for (key in proto) node[key] = proto[key] | ||
if (proto === El[protoStr]) { | ||
document.createElement = function(name) {return extend(createElement(name))} | ||
document.createElement = function(name) { | ||
return extend(createElement(name)) | ||
} | ||
// NOTE: document.body will not get extended with later added extensions | ||
extend(body) | ||
// Remove background image flickers on hover in IE6 | ||
// | ||
// You could also use CSS | ||
// html { filter: expression(document.execCommand("BackgroundImageCache", false, true)); } | ||
/*@cc_on try{document.execCommand('BackgroundImageCache',false,true)}catch(e){}@*/ | ||
} | ||
//*/ | ||
@@ -371,3 +440,7 @@ El[protoStr] = proto | ||
if (typeof id == "string") id = document.getElementById(id) | ||
//** modernBrowser | ||
return id && id.to ? id : extend(id) | ||
/*/ | ||
return id | ||
//*/ | ||
} | ||
@@ -418,3 +491,3 @@ | ||
if (q == ">") { | ||
(indent +" "+ text.slice(1)).replace(tplRe, work) | ||
(indent +" "+ text.slice(1)).replace(templateRe, work) | ||
} else if (q == "=") { | ||
@@ -428,3 +501,3 @@ parent.set({"data-bind": text.slice(1)}) | ||
} | ||
str.replace(tplRe, work) | ||
str.replace(templateRe, work) | ||
root = root.childNodes | ||
@@ -431,0 +504,0 @@ if (root.length == 1) return root[0] |
{ | ||
"name": "elements-lite", | ||
"version": "0.5.0", | ||
"version": "0.5.1", | ||
"stability": 1, | ||
@@ -35,4 +35,8 @@ "license": "MIT", | ||
"buildman": { | ||
"dist/index-min.js": "index.js" | ||
"dist/index-min.js": "index.js", | ||
"dist/index-modern-min.js": { | ||
"input": "index.js", | ||
"toggle": "modernBrowser" | ||
} | ||
} | ||
} |
@@ -7,4 +7,4 @@ [1]: https://secure.travis-ci.org/litejs/elements-lite.png | ||
@version 0.5.0 | ||
@date 2015-01-13 | ||
@version 0.5.1 | ||
@date 2015-02-02 | ||
@stability 1 - Experimental | ||
@@ -11,0 +11,0 @@ |
@@ -6,4 +6,4 @@ (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);throw new Error("Cannot find module '"+o+"'")}var f=n[o]={exports:{}};t[o][0].call(f.exports,function(e){var n=t[o][1][e];return s(n?n:e)},f,f.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){ | ||
/** | ||
* @version 0.3.6 | ||
* @date 2014-09-19 | ||
* @version 0.5.0 | ||
* @date 2015-02-02 | ||
* @stability 1 - Experimental | ||
@@ -16,21 +16,24 @@ * @author Lauri Rooden <lauri@rooden.ee> | ||
// TODO: find ways for automated testing | ||
// http://www.browserscope.org/user/tests/howto | ||
!function(window, document, protoStr) { | ||
var currentLang | ||
, body = document.body | ||
, createElement = document.createElement | ||
, txtAttr = "textContent" in body ? "textContent" : "innerText" | ||
, elCache = {} | ||
, fnCache = {} | ||
, createElement = document.createElement | ||
, proto = (window.HTMLElement || window.Element || El)[protoStr] | ||
, elRe = /([.#:[])([-\w]+)(?:=((["'\/])(?:\\?.)*?\4|[-\w]+)])?]?/g | ||
, tplRe = /^([ \t]*)(\:?)((?:(["'\/])(?:\\?.)*?\4|[-\w\:.#\[\]=])+)[ \t]*(.*)$/gm | ||
, selectorCache = {} | ||
, selectorRe = /([.#:[])([-\w]+)(?:([~^$*|]?)=((["'\/])(?:\\?.)*?\5|[-\w]+)])?]?/g | ||
, lastSelectorRe = /(\s*[>+]?\s*)((["'\/])(?:\\?.)*?\2|[^\s+>])+$/ | ||
, pseudoClasses = { | ||
"empty": "!_.hasChildNodes()", | ||
"first-child": "_.parentNode&&_.parentNode.firstChild==_", | ||
"last-child" : "_.parentNode&&_.parentNode.lastChild==_", | ||
"link": "_.nodeName=='A'&&_.getAttribute('href')" | ||
} | ||
, templateRe = /^([ \t]*)(@?)((?:(["'\/])(?:\\?.)*?\4|[-\w\:.#\[\]=])+)[ \t]*(.*)$/gm | ||
, renderRe = /[;\s]*(\w+)(?:\s*\:((?:(["'\/])(?:\\?.)*?\3|[-,\s\w])*))?/g | ||
, bindings = El.bindings = { | ||
"txt": function(node, data, text) { | ||
node.txt(text.format(data)) | ||
}, | ||
"class": function(node, data, name, fn) { | ||
node.toggleClass(name, fn.fn("_")(data)) | ||
toggleClass.call(node, name, fn.fn("_")(data)) | ||
}, | ||
@@ -40,19 +43,7 @@ "html": function(node, data, html) { | ||
}, | ||
/** | ||
"with": function(node, data, scope) { | ||
render.call(node, scope, true) | ||
"txt": function(node, data, text) { | ||
node.txt(text.format(data)) | ||
}, | ||
"if": function(node, data, fn) { | ||
var childs = getChilds(node) | ||
node.empty().append( fn.fn("_")(data) && childs ) | ||
}, | ||
//*/ | ||
"each": function(node, data, arr) { | ||
var childs = getChilds(node) | ||
if (arr) node.empty().append(arr.map(function(obj) { | ||
return childs.map(function(el) { | ||
return render.call(el.cloneNode(true), obj) | ||
}) | ||
})) | ||
return node | ||
"val": function(node, data, text) { | ||
node.val(text.format(data)) | ||
} | ||
@@ -64,5 +55,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"> | ||
*/ | ||
@@ -73,8 +66,10 @@ | ||
, pre = {} | ||
name = name.replace(elRe, function(_, op, key, val, quotation) { | ||
name = name.replace(selectorRe, function(_, op, key, fn, val, quotation) { | ||
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 "" | ||
@@ -93,33 +88,9 @@ }) || "div" | ||
// TODO: Extend El api | ||
// add El.siblings( [selector ] ) | ||
// add El.children( [selector ] ) | ||
// add El.invoke | ||
// https://github.com/WebReflection/dom4#dom4 | ||
// | ||
// How elements.js extends the DOM | ||
// ------------------------------- | ||
// http://perfectionkills.com/whats-wrong-with-extending-the-dom/ | ||
// | ||
// All DOM extensions on the element are available by default. | ||
// | ||
// In browsers that does not support adding methods to prototype of native objects | ||
// such as HTMLElement or Element, document.createElement will be overrided | ||
// to extend created elements. El.get() and element.find will extend | ||
// returned elements. | ||
// ### element.append( content, [ before ] ) -> element | ||
// | ||
// - **content** `element || Array || String || Number` | ||
// - **before** `optional` | ||
// - true - Insert content to the beginning of element | ||
// - element - Insert content before specified element | ||
// - Number - Insert content before nth child | ||
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 ) { | ||
@@ -129,6 +100,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 | ||
@@ -181,6 +151,7 @@ } | ||
proto.toggleClass = function(name, force) { | ||
function toggleClass(name, force) { | ||
if (arguments.length == 1) force = !hasClass.call(this, name) | ||
return ( force ? addClass : rmClass ).call(this, name), force | ||
} | ||
proto.toggleClass = toggleClass | ||
@@ -212,51 +183,56 @@ proto.empty = function() { | ||
proto.set = function(args) { | ||
var val | ||
, el = this | ||
, key = typeof args | ||
proto.attr = attr | ||
function attr(key, val) { | ||
var el = this | ||
if (arguments.length == 1) { | ||
if (key && key.constructor === Object) { | ||
Object.each(key, function(val, key) { | ||
attr.call(el, key, val) | ||
}) | ||
return | ||
} | ||
return el.getAttribute(key) | ||
} | ||
// Note: IE5-7 doesn't set styles and removes events when you try to set them. | ||
// | ||
// in IE6, a label with a for attribute linked to a select list | ||
// will cause a re-selection of the first option instead of just giving focus. | ||
// http://webbugtrack.blogspot.com/2007/09/bug-116-for-attribute-woes-in-ie6.html | ||
if (!args) return el | ||
if (key == "string" || key == "number" || args.nodeType || "length" in args) append.call(el, args) | ||
else for (key in args) { | ||
val = args[key] | ||
// El uses class | ||
if (key == "class") addClass.call(el, val) | ||
else if (!val) el.removeAttribute(key) | ||
else if (typeof val == "string") { | ||
// Note: IE5-7 doesn't set styles and removes events when you try to set them. | ||
// | ||
// in IE6, a label with a for attribute linked to a select list | ||
// will cause a re-selection of the first option instead of just giving focus. | ||
// http://webbugtrack.blogspot.com/2007/09/bug-116-for-attribute-woes-in-ie6.html | ||
el.setAttribute(key, val) | ||
// there are bug in IE<9 where changed 'name' param not accepted on form submit | ||
// The JScript engine used in IE doesn't recognize vertical tabulation character | ||
// oldIE = "\v" == "v" | ||
// | ||
// IE8 and below also support document.createElement('<P>') | ||
// | ||
// http://www.matts411.com/post/setting_the_name_attribute_in_ie_dom/ | ||
// http://msdn.microsoft.com/en-us/library/ms536614(VS.85).aspx | ||
// there are bug in IE<9 where changed 'name' param not accepted on form submit | ||
// The JScript engine used in IE doesn't recognize vertical tabulation character | ||
// oldIE = "\v" == "v" | ||
// | ||
// IE8 and below also support document.createElement('<P>') | ||
// | ||
// http://www.matts411.com/post/setting_the_name_attribute_in_ie_dom/ | ||
// http://msdn.microsoft.com/en-us/library/ms536614(VS.85).aspx | ||
if ((key == "id" || key == "name") && "\v" == "v") { | ||
el.mergeAttributes(createElement('<INPUT '+key+'="' + val + '"/>'), false) | ||
} | ||
} else el[key] = val | ||
//** modernBrowser | ||
if ((key == "id" || key == "name" || key == "type") && "\v" == "v") { | ||
el.mergeAttributes(createElement('<INPUT '+key+'="' + val + '">'), false) | ||
} else { | ||
el.setAttribute(key, val) | ||
} | ||
return el | ||
/*/ | ||
el.setAttribute(key, val) | ||
//*/ | ||
} | ||
// Save node initial content for later use | ||
function getChilds(node) { | ||
var child | ||
, childs = node._childs | ||
if (!childs) { | ||
node._childs = childs = [] | ||
for (; child = node.firstChild;) { | ||
childs.push(child); | ||
node.removeChild(child) | ||
proto.set = set | ||
function set(args, key, val) { | ||
var el = this | ||
if (args) { | ||
if (typeof args == "object") for (key in args) { | ||
val = args[key] | ||
// El uses class | ||
if (key == "class") addClass.call(el, val) | ||
else if (typeof val == "string") { | ||
attr.call(el, key, val) | ||
} | ||
else if (!val) el.removeAttribute(key) | ||
} | ||
else append.call(el, args) | ||
} | ||
return childs | ||
return el | ||
} | ||
@@ -282,7 +258,9 @@ | ||
if (fn.fn()(node, data, bindings)) return node | ||
if (Fn(fn)(node, data, bindings)) return node | ||
} | ||
for (node = node.firstChild; node; node = node.nextSibling) { | ||
if (node.nodeType == 1) render.call(node, data) | ||
if (node.nodeType == 1) { | ||
render.call(node, data) | ||
} | ||
} | ||
@@ -300,14 +278,30 @@ return this | ||
// textContent is suported from IE9 | ||
// | ||
// Opera 9-10 have Node.text, Node.textContent | ||
// Opera 9-10 have Node.text so we use Node.txt | ||
proto.txt = function(newText) { | ||
return arguments.length ? (this[txtAttr] = newText) : this[txtAttr] | ||
} | ||
proto.val = function(val) { | ||
var el = this | ||
, attr = "textContent" in el ? "textContent" : "innerText" | ||
return arguments.length ? (el[attr] = newText) : el[attr] | ||
, type = el.type | ||
, opts = el.options | ||
if (arguments.length) { | ||
return el.value = val | ||
} | ||
if (type == "select-multiple") { | ||
for (val = [], type = 0; el = opts[type++];) { | ||
if (el.selected && !el.disabled && !el.parentNode.disabled) val.push(el.value) | ||
} | ||
return val | ||
} | ||
return (type == "checkbox" || type == "radio") && !el.checked ? "" : | ||
el.value || | ||
options && options[el.selectedIndex].value || | ||
"on" | ||
} | ||
// NOTE: fast selectors for IE | ||
// http://ajaxian.com/archives/creating-a-queryselector-for-ie-that-runs-at-native-speed | ||
function findEl(node, sel, first) { | ||
@@ -317,15 +311,8 @@ var el | ||
, out = [] | ||
, rules = ["_"] | ||
, tag = sel.replace(elRe, function(_, o, s, v) { | ||
rules.push( | ||
o == "." ? "(' '+_.className+' ').indexOf(' "+s+" ')>-1" : | ||
o == "#" ? "_.id=='"+s+"'" : | ||
"_.getAttribute('"+s+"')"+(v?"=='"+v+"'":"") | ||
) | ||
return "" | ||
}) || "*" | ||
, els = node.getElementsByTagName(tag) | ||
, fn = Fn(rules.join("&&")) | ||
, els = node.getElementsByTagName("*") | ||
, fn = selectorFn(sel.split(/\s*,\s*/).map(function(sel) { | ||
return "_.matches('" + sel + "')" | ||
}).join("||")) | ||
for (; el = els[i++]; ) if (fn(el)) { | ||
for (; (el = els[i++]); ) if (fn(el)) { | ||
if (first) return el | ||
@@ -337,2 +324,61 @@ out.push(el) | ||
function selectorFnStr(sel) { | ||
var rules = ["_"] | ||
, tag = sel.replace(selectorRe, function(_, op, key, fn, val, quotation, len) { | ||
if (quotation) val = val.slice(1, -1) | ||
if (val) { | ||
len = val.length | ||
val = val.replace(/'/g, "\\'") | ||
} | ||
rules.push( | ||
op == "." ? "(' '+_.className+' ').indexOf(' " + key + " ')>-1" : | ||
op == "#" ? "_.id=='" + key + "'" : | ||
op == ":" && pseudoClasses[key] || | ||
"(a=_.getAttribute('" + key + "'))" + (!fn && val ? "=='" + val + "'" : "") | ||
) | ||
if (fn) rules.push( | ||
fn == "^" ? "a.slice(0," + len + ")=='" + val + "'" : | ||
fn == "|" ? "a.split('-')[0]=='" + val + "'" : | ||
fn == "$" ? "a.slice(-" + len + ")=='" + val + "'" : | ||
fn == "~" ? "(' '+a+' ').indexOf(' " + val + " ')>-1" : | ||
"a.indexOf('" + val + "')>-1" // fn == "*" | ||
) | ||
return "" | ||
}) | ||
if (tag && tag != "*") rules.unshift("_.nodeName=='" + tag.toUpperCase() + "'") | ||
return rules.join("&&") | ||
} | ||
function selectorFn(str) { | ||
// jshint evil:true | ||
return selectorCache[str] || | ||
(selectorCache[str] = Function("_,a", "return " + str)) | ||
} | ||
proto.matches = proto.matches || function(sel) { | ||
var relation, from | ||
, parentSel = sel.replace(lastSelectorRe, function(_, _rel, a, b, start) { | ||
from = start + _rel.length | ||
relation = _rel.trim() | ||
return "" | ||
}) | ||
, next = relation == "+" ? this.previousSibling : this.parentNode | ||
, fn = selectorFn(selectorFnStr(sel.slice(from))) | ||
if (!fn(this)) return false | ||
if (parentSel) { | ||
if (!relation) return !!(next && next.closest && next.closest(parentSel)) | ||
return next && next.matches && next.matches(parentSel) || false | ||
} | ||
return true | ||
} | ||
proto.closest = proto.closest || function(sel) { | ||
for (var el = this; el; el = el.parentNode) if (el.matches && el.matches(sel)) return el | ||
return null | ||
} | ||
//** modernBrowser | ||
// Note: IE8 don't support :disabled | ||
@@ -350,3 +396,10 @@ proto.find = "\v" !== "v" && proto.querySelector || function(sel) { | ||
} | ||
/*/ | ||
proto.find = proto.querySelector | ||
proto.findAll = function(sel) { | ||
return new ElWrap(this.querySelectorAll(sel)) | ||
} | ||
//*/ | ||
function ElWrap(nodes) { | ||
@@ -359,4 +412,3 @@ this._nodes = nodes | ||
memo[key] = function() { | ||
var elWrap = this | ||
, nodes = elWrap._nodes | ||
var nodes = this._nodes | ||
, i = 0 | ||
@@ -367,3 +419,3 @@ , len = nodes.length | ||
} | ||
return elWrap | ||
return this | ||
} | ||
@@ -373,3 +425,3 @@ return memo | ||
//** modernBrowser | ||
function extend(node, key) { | ||
@@ -380,16 +432,12 @@ if (node) for (key in proto) node[key] = proto[key] | ||
// IE 6-7 | ||
if (proto === El[protoStr]) { | ||
document.createElement = function(name) {return extend(createElement(name))} | ||
document.createElement = function(name) { | ||
return extend(createElement(name)) | ||
} | ||
// NOTE: document.body will not get extended with later added extensions | ||
extend(document.body) | ||
// Remove background image flickers on hover in IE6 | ||
// | ||
// You could also use CSS | ||
// html { filter: expression(document.execCommand("BackgroundImageCache", false, true)); } | ||
/*@cc_on try{document.execCommand('BackgroundImageCache',false,true)}catch(e){}@*/ | ||
extend(body) | ||
} | ||
//*/ | ||
@@ -400,3 +448,7 @@ El[protoStr] = proto | ||
if (typeof id == "string") id = document.getElementById(id) | ||
//** modernBrowser | ||
return id && id.to ? id : extend(id) | ||
/*/ | ||
return id | ||
//*/ | ||
} | ||
@@ -419,2 +471,3 @@ | ||
//** templates | ||
@@ -447,3 +500,3 @@ function tpl(str) { | ||
if (q == ">") { | ||
(indent +" "+ text.slice(1)).replace(tplRe, work) | ||
(indent +" "+ text.slice(1)).replace(templateRe, work) | ||
} else if (q == "=") { | ||
@@ -457,3 +510,3 @@ parent.set({"data-bind": text.slice(1)}) | ||
} | ||
str.replace(tplRe, work) | ||
str.replace(templateRe, work) | ||
root = root.childNodes | ||
@@ -477,7 +530,4 @@ if (root.length == 1) return root[0] | ||
var t = this | ||
El.cache(t.name, t.el.removeChild(t.el.firstChild), render) | ||
t.el.plugin = null | ||
return t.parent | ||
@@ -487,20 +537,6 @@ } | ||
tpl.plugins = { | ||
/* | ||
* - Declaration | ||
* mixin list | ||
* | ||
* mixin link(href, name) | ||
* a(class!=attributes.class, href=href)= name | ||
* | ||
* +link('/foo', 'foo')(class="btn") | ||
* | ||
* :include | ||
* :doctype | ||
* - http://stackoverflow.com/questions/8227612/how-to-create-document-objects-with-javascript | ||
*/ | ||
"template": template | ||
} | ||
// El.create | ||
El.tpl = function(str) { | ||
El.create = El.tpl = function(str) { | ||
return tpl(str).render() | ||
@@ -513,6 +549,6 @@ } | ||
} | ||
//*/ | ||
//** i18n | ||
function i18n(text, lang) { | ||
@@ -526,3 +562,3 @@ return i18n[ lang ? getLang(lang) : currentLang ][text] || text | ||
lang = (lang || "").toLowerCase() | ||
return i18n[lang] ? lang : (lang = lang.split("-")[0]), i18n[lang] ? lang : currentLang | ||
return i18n[lang] ? lang : ((lang = lang.split("-")[0]), i18n[lang]) ? lang : currentLang | ||
} | ||
@@ -544,4 +580,2 @@ | ||
//setLang("en") | ||
i18n.get = getLang | ||
@@ -555,2 +589,6 @@ i18n.use = setLang | ||
} | ||
// navigator.userLanguage for IE, navigator.language for others | ||
// var lang = navigator.language || navigator.userLanguage; | ||
// setLang("en") | ||
//*/ | ||
@@ -691,4 +729,4 @@ }(window, document, "prototype") | ||
/** | ||
* @version 0.2.8 | ||
* @date 2014-08-24 | ||
* @version 0.3.0 | ||
* @date 2014-12-08 | ||
* @stability 2 - Unstable | ||
@@ -816,22 +854,2 @@ * @author Lauri Rooden <lauri@rooden.ee> | ||
/* | ||
Object.values = function(obj) { | ||
return Object.keys(obj).map(function(e) { | ||
return obj[e] | ||
}) | ||
} | ||
Object.values({a:1, b:2, c:3}); //[1, 2, 3] | ||
Array.prototype.flatten = function(){ | ||
var arr = this, i = arr.length; | ||
while (i--) if (arr[i] instanceof Array) | ||
arr[i].unshift(i,1) && arr.splice.apply(arr,arr[i].flatten() ) | ||
return arr | ||
} | ||
function argsToArray(){ | ||
return Array.apply(null, arguments).flatten() | ||
} | ||
argsToArray([[1],3,[4,5]],2) | ||
*/ | ||
// Note: use for Object literals only, | ||
@@ -855,19 +873,2 @@ // as it returns false for custom objects, | ||
O.deepMerge = O.deepCopy = function(target, source, path, changed, key, val) { | ||
path = path || "" | ||
changed = changed || [] | ||
for (key in source) if (hasOwn.call(source, key) && target[key] !== source[key]) { | ||
val = source[key] | ||
changed.push(path + key) | ||
if (val === null) delete target[key] | ||
else if (isObject(val)) { | ||
if (!isObject(target[key])) target[key] = {} | ||
O.deepMerge(target[key], val, path + key + ".", changed) | ||
} | ||
else target[key] = val | ||
} | ||
return changed | ||
} | ||
O.zip = function(keys, vals) { | ||
@@ -904,4 +905,6 @@ return keys.fold(function(_, key, i) { | ||
// uniq | ||
// last item preserved | ||
A.uniq = A.filter.partial(function(s,i,a){return i == a.lastIndexOf(s)}) | ||
// first item preserved | ||
A.uniq = A.filter.partial(function(elem, i, arr) { | ||
return i == arr.indexOf(elem) | ||
}) | ||
@@ -1568,2 +1571,4 @@ A.pushUniq = function(item) { | ||
, '<select id=id2 class=cl2 disabled></select>' | ||
, '<select disabled id=id2 class=cl2></select>' | ||
, '<select disabled class=cl2 id=id2></select>' | ||
]). | ||
@@ -1676,11 +1681,11 @@ it ("should get element by id"). | ||
it ("supports templates"). | ||
anyOf(getString(El.tpl(":template t1\n .temp1 t123\nt1")), | ||
anyOf(getString(El.tpl("@template t1\n .temp1 t123\nt1")), | ||
[ '<div class=temp1>t123</div>' | ||
, '<div class="temp1">t123</div>' | ||
]). | ||
anyOf(getString(El.tpl(":template t2\n .temp2>b t123\nt2")), | ||
anyOf(getString(El.tpl("@template t2\n .temp2>b t123\nt2")), | ||
[ '<div class=temp2><b>t123</b></div>' | ||
, '<div class="temp2"><b>t123</b></div>' | ||
]). | ||
anyOf(getString(El.tpl(":template t3\n .temp3\n b t123\nt3")), | ||
anyOf(getString(El.tpl("@template t3\n .temp3\n b t123\nt3")), | ||
[ '<div class=temp3><b>t123</b></div>' | ||
@@ -1700,5 +1705,6 @@ , '<div class="temp3"><b>t123</b></div>' | ||
, "<a><b class=\"red\" data-bind=\"class:'red','i>1'\"><i data-bind=\"txt:'hello {name}'\">hello moon</i></b></a>" | ||
, "<a><b class=red data-bind=\"class:'red','i>1'\"><i data-bind=\"txt:'hello {name}'\">hello moon</i></b></a>" | ||
]). | ||
it ( "should show set DOM propperty when plugin not found" , {skip: "Browsers does not show attrs set by node.unknown_plugin = '123', should use node.set()"}). | ||
it ( "should show set DOM propperty when plugin not found" , {skip: "Browsers does not show attrs set by node.unknown_plugin = '123', should use node.set()"}). | ||
equal(getString(t1 = El.tpl("a =unknown_plugin:\'hello {name}\'")), '<a data-bind="unknown_plugin:\'hello {name}\'"></a>'). | ||
@@ -1708,2 +1714,20 @@ equal(getString(t1.render({name:"world"})), '<a data-bind="unknown_plugin:\'hello {name}\'" unknown_plugin="hello world"></a>'). | ||
/* | ||
it ("supports declaring a leaf node"). | ||
run(function() { | ||
t1 = El.tpl(["" | ||
, "@template leaf1" | ||
, " a" | ||
, " b[data-leaf]" | ||
, "div" | ||
, " leaf1" | ||
, " i 1" | ||
, " leaf1" | ||
, " i 2" | ||
].join("\n")) | ||
}). | ||
equal(getString(t1), '<div><a><b data-leaf="data-leaf"><i>1</i></b></a><a><b data-leaf="data-leaf"><i>2</i></b></a></div>'). | ||
*/ | ||
it ("supports IF binding"). | ||
done() | ||
@@ -1710,0 +1734,0 @@ |
@@ -165,2 +165,4 @@ require("browser-upgrade-lite") | ||
, '<select id=id2 class=cl2 disabled></select>' | ||
, '<select disabled id=id2 class=cl2></select>' | ||
, '<select disabled class=cl2 id=id2></select>' | ||
]). | ||
@@ -273,11 +275,11 @@ it ("should get element by id"). | ||
it ("supports templates"). | ||
anyOf(getString(El.tpl(":template t1\n .temp1 t123\nt1")), | ||
anyOf(getString(El.tpl("@template t1\n .temp1 t123\nt1")), | ||
[ '<div class=temp1>t123</div>' | ||
, '<div class="temp1">t123</div>' | ||
]). | ||
anyOf(getString(El.tpl(":template t2\n .temp2>b t123\nt2")), | ||
anyOf(getString(El.tpl("@template t2\n .temp2>b t123\nt2")), | ||
[ '<div class=temp2><b>t123</b></div>' | ||
, '<div class="temp2"><b>t123</b></div>' | ||
]). | ||
anyOf(getString(El.tpl(":template t3\n .temp3\n b t123\nt3")), | ||
anyOf(getString(El.tpl("@template t3\n .temp3\n b t123\nt3")), | ||
[ '<div class=temp3><b>t123</b></div>' | ||
@@ -297,5 +299,6 @@ , '<div class="temp3"><b>t123</b></div>' | ||
, "<a><b class=\"red\" data-bind=\"class:'red','i>1'\"><i data-bind=\"txt:'hello {name}'\">hello moon</i></b></a>" | ||
, "<a><b class=red data-bind=\"class:'red','i>1'\"><i data-bind=\"txt:'hello {name}'\">hello moon</i></b></a>" | ||
]). | ||
it ( "should show set DOM propperty when plugin not found" , {skip: "Browsers does not show attrs set by node.unknown_plugin = '123', should use node.set()"}). | ||
it ( "should show set DOM propperty when plugin not found" , {skip: "Browsers does not show attrs set by node.unknown_plugin = '123', should use node.set()"}). | ||
equal(getString(t1 = El.tpl("a =unknown_plugin:\'hello {name}\'")), '<a data-bind="unknown_plugin:\'hello {name}\'"></a>'). | ||
@@ -309,3 +312,3 @@ equal(getString(t1.render({name:"world"})), '<a data-bind="unknown_plugin:\'hello {name}\'" unknown_plugin="hello world"></a>'). | ||
t1 = El.tpl(["" | ||
, ":template leaf1" | ||
, "@template leaf1" | ||
, " a" | ||
@@ -312,0 +315,0 @@ , " b[data-leaf]" |
Sorry, the diff of this file is not supported yet
Uses eval
Supply chain riskPackage uses dynamic code execution (e.g., eval()), which is a dangerous practice. This can prevent the code from running in certain environments and increases the risk that the code may contain exploits or malicious behavior.
Found 1 instance in 1 package
115118
20
2607
2