Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

elements-lite

Package Overview
Dependencies
Maintainers
1
Versions
64
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

elements-lite - npm Package Compare versions

Comparing version 0.2.4 to 0.3.1

.npmignore

14

dist/elements-min.js

@@ -1,6 +0,8 @@

!function(l,e,m){function d(a,b){var c,d={};a=a.replace(n,function(a,b,c,h,e){d["."==b?(b="class",d[b]&&(c=d[b]+" "+c),b):"#"==b?"id":c]=(e?h.slice(1,-1):h)||c;return""})||"div";c=(f[a]||(f[a]=e.createElement(a))).cloneNode(!0).set(d);return g[a]&&g[a].call(c,b)||c.set(b)}function k(a,b){if(a)for(b in c)a[b]=c[b];return a}var f={},g={},c=(l.HTMLElement||l.Element||d)[m],n=/([.#:[])([-\w]+)(?:=((["'\/])(?:\\.|.)*?\4|[-\w]+)])?]?/g;c.append=function(a,b){if(a){if("string"==typeof a||"number"==typeof a)a=
d.text(a);else if(!("nodeType"in a)&&"length"in a){for(var h=a.length,f=0,g=e.createDocumentFragment();f<h;)c.append.call(g,a[f++]);a=g}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.append_hook&&a.append_hook()}return this};c.after=function(a,b){c.append.call(a.parentNode,this,b?a:a.nextSibling);return this};c.to=function(a,b){c.append.call(a,this,b);return this};c.hasClass=function(a){return RegExp("\\b"+a+
"\\b").test(this.className)};c.addClass=function(a){this.className+=this.className?this.hasClass(a)?"":" "+a:a;return this};c.rmClass=function(a){this.className=(" "+this.className+" ").replace(" "+a+" "," ").trim();return this};c.toggleClass=function(a,b){1==arguments.length&&(b=!this.hasClass(a));this[b?"addClass":"rmClass"](a);return b};c.empty=function(){for(var a;a=this.firstChild;)this.kill.call(a);return this};c.kill=function(){this.parentNode&&this.parentNode.removeChild(this);Event.removeAll&&
Event.removeAll(this);this.kill_hook&&this.kill_hook();this.empty&&this.empty();return this};c.on=function(a,b){Event.add(this,a,b);return this};c.non=function(a,b){Event.remove(this,a,b);return this};c.set=function(a){var b,c=typeof a;if(!a)return this;if("string"==c||"number"==c||a.nodeType||"length"in a)this.append(a);else for(c in a)b=a[c],"class"==c?this.addClass(b):b?"string"==typeof b?(this.setAttribute(c,b),"id"!=c&&"name"!=c||"\v"!="v"||this.mergeAttributes(e.createElement("<INPUT "+c+'="'+
b+'"/>'),!1)):this[c]=b:this.removeAttribute(c);return this};c.txt=function(a){var b="textContent"in this?"textContent":"innerText";return arguments.length?this[b]=a:this[b]};c._find=function(a){var b=0,c=["_"];a=a.replace(n,function(a,b,d,e){c.push("."==b?"(' '+_.className+' ').indexOf(' "+d+" ')>-1":"#"==b?"_.id=='"+d+"'":"_.getAttribute('"+d+"')"+(e?"=='"+e+"'":""));return""})||"*";for(var d=this.getElementsByTagName(a),e=Function("_","return "+c.join("&&"));a=d[b++];)if(e(a))return a.to?a:k(a)};
c.find=e.querySelector?function(a){return this.querySelector(a)}:c._find;if(c===d[m]){var p=e.createElement;e.createElement=function(a){return k(p(a))};k(e.body)}d[m]=c;d.get=function(a){"string"==typeof a&&(a=e.getElementById(a));return a&&a.to?a:k(a)};d.cache=function(a,b,c){f[a]="string"==typeof b?d(b):b;c&&(g[a]=c)};d.cache.el=f;d.cache.fn=g;d.text=function(a){return e.createTextNode(a)};l.El=d}(window,document,"prototype");
!function(m,f,n){function e(a,b){var c,g={};a=a.replace(v,function(a,b,c,d,e){g["."==b?(b="class",g[b]&&(c=g[b]+" "+c),b):"#"==b?"id":c]=(e?d.slice(1,-1):d)||c;return""})||"div";c=(k[a]||(k[a]=f.createElement(a))).cloneNode(!0).set(g);return l[a]&&l[a].call(c,b)||c.set(b)}function h(a,b){if(a){if("string"==typeof a||"number"==typeof a)a=e.text(a);else if(!("nodeType"in a)&&"length"in a){for(var c=a.length,g=0,d=f.createDocumentFragment();g<c;)h.call(d,a[g++]);a=d}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 p(a){return RegExp("\\b"+a+"\\b").test(this.className)}function q(a){this.className+=this.className?p.call(this,a)?"":" "+a:a;return this}function w(a){this.className=(" "+this.className+" ").replace(" "+a+" "," ").trim();return this}function x(){this.parentNode&&this.parentNode.removeChild(this);Event.removeAll&&Event.removeAll(this);this.killHook&&this.killHook();
this.empty&&this.empty();return this}function z(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-bind"))if(d.getAttribute("lang"),c="n d p r->d&&("+c.replace(A,"(p['$1']?(r=p['$1'](n,d,$2)||r):(n['$1']=$2.format(d))),")+"r)",c.fn()(d,a,B))return d;for(d=d.firstChild;d;d=d.nextSibling)1==d.nodeType&&r.call(d,a);return this}function y(a,b,c){var d=0,e=[],f=["_"];b=b.replace(v,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 h=Fn(f.join("&&"));a=b[d++];)if(h(a)){if(c)return a;e.push(a)}return c?null:e}function s(a){this._nodes=a}function t(a,b){if(a)for(b in d)a[b]=d[b];return a}function u(a,b,c){k[a]="string"==typeof b?e(b):b;c&&(l[a]=c)}var k={},l={},d=(m.HTMLElement||m.Element||e)[n],v=/([.#:[])([-\w]+)(?:=((["'\/])(?:\\.|.)*?\4|[-\w]+)])?]?/g,A=/[;\s]*(\w+)(?:\s*\:((?:(["'\/])(?:\\.|.)*?\3|[-,\s\w])*))?/g,
B=e.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=z(a);c&&a.empty().append(c.map(function(a){return d.map(function(b){return r.call(b.cloneNode(!0),a)})}));return a}};d.append=h;d.after=function(a,b){h.call(a.parentNode,this,b?a:a.nextSibling);return this};d.to=function(a,b){h.call(a,this,b);return this};d.hasClass=p;d.addClass=q;d.rmClass=w;d.toggleClass=function(a,
b){1==arguments.length&&(b=!p.call(this,a));return(b?q:w).call(this,a),b};d.empty=function(){for(var a;a=this.firstChild;)x.call(a);return this};d.kill=x;d.on=function(a,b){Event.add(this,a,b);return this};d.non=function(a,b){Event.remove(this,a,b);return this};d.set=function(a){var b,c=typeof a;if(!a)return this;if("string"==c||"number"==c||a.nodeType||"length"in a)h.call(this,a);else for(c in a)b=a[c],"class"==c?q.call(this,b):b?"string"==typeof b?(this.setAttribute(c,b),"id"!=c&&"name"!=c||"\v"!=
"v"||this.mergeAttributes(f.createElement("<INPUT "+c+'="'+b+'"/>'),!1)):this[c]=b:this.removeAttribute(c);return this};d.render=r;d.txt=function(a){var b="textContent"in this?"textContent":"innerText";return arguments.length?this[b]=a:this[b]};d.find="\v"!=="v"&&d.querySelector||function(a){return y(this,a,!0)};d.findAll=d.querySelectorAll?function(a){return new s(this.querySelectorAll(a))}:function(a){return new s(y(this,a))};s.prototype=Object.keys(d).reduce(function(a,b){a[b]=function(){for(var a=
this._nodes,e=0,f=a.length;e<f;)d[b].apply(a[e++],arguments);return this};return a},{});if(d===e[n]){var C=f.createElement;f.createElement=function(a){return t(C(a))};t(f.body)}m.El=e;e[n]=d;e.get=function(a){"string"==typeof a&&(a=f.getElementById(a));return a&&a.to?a:t(a)};u._el=k;u._fn=l;e.cache=u;e.text=function(a){return f.createTextNode(a)}}(window,document,"prototype");

@@ -1,4 +0,3 @@

!function(m,n){function s(b){for(var a=[],c=b.length;c--;)a[c]=b[c];return a}function k(b){function a(b,c,h,f,l,g){for(l=c.length;l<=d[0];)d.shift(),e=e.plugin?e.plugin.done():e.parentNode;h?k.plugins[f]?(e=(new k.plugins[f](e,g)).el,d.unshift(l)):e.append(El.text(b)):(f&&(e=El(f).to(e),d.unshift(l)),g&&(">"==g.charAt(0)?(c+" "+g.slice(1)).replace(p,a):"="==g.charAt(0)?e.set({"data-bind":g.slice(1)}):e.append(g.replace(/\\([=>:])/g,"$1"))))}var c=n.createDocumentFragment(),e=c,d=[-1];b.replace(p,
a);d=c.childNodes;return 1==d.length?d[0]:s(d)}function f(b,a){this.name=a;this.parent=b;this.el=El("div");this.el.plugin=this;return this}function q(b){var a=b._template;if(!a){b._template=a=[];for(var c;c=b.firstChild;)a.push(c),b.removeChild(c);console.log(b,"TEMP",a)}return a}function h(b){var a,c,e,d=this;if(c=d.getAttribute("data-bind")){e=d.getAttribute("lang")||e;if(a=c.match(/(\w+)\:/))c=c.slice(a[0].length),a=r[a[1]]||a[1];if("function"==typeof a)return a(d,b,c),d;d[a||r.txt]=i18n(c,e).format(b)}for(d=
d.firstChild;d;d=d.nextSibling)1==d.nodeType&&h.call(d,b);return this}var p=/^([ \t]*)(\:?)((?:(["'\/])(?:\\.|.)*?\4|[-\w\:.#\[\]=])+)[ \t]*(.*)$/gm;f.prototype.done=function(){El.cache(this.name,this.el.removeChild(this.el.firstChild),h);this.el.plugin=null;return this.parent};var t=f.extend({done:function(){El.cache(this.name,this.el.firstChild,h);this.el.plugin=null;return this.parent}});k.plugins={template:f,"if":t,"for":function(b,a,c){}};m.haml=k;m.include=function(b,a,c){a=El.get(b);(new f(null,
b)).el.append(El.haml(a.innerHTML)).plugin.done();a.kill()};var r={txt:"textContent"in n?"textContent":"innerText",toggleClass:function(){},html:"innerHTML","if":function(b,a,c){q(b);var e=a&&a[c];e&&b.empty().append(Fn(c)(a)&&e)},each:function(b,a,c){var e=q(b);(a=a&&a[c])&&b.empty().append(a.map(function(a){return e.map(function(b){return h.call(b.cloneNode(!0),a)})}))}};m.prototype.render=h}(window.El||this,window.document);
!function(m){function k(a){function e(a,c,h,g,l,f){for(l=c.length;l<=d[0];)d.shift(),b=b.plugin?b.plugin.done():b.parentNode;h?k.plugins[g]?(b=(new k.plugins[g](b,f)).el,d.unshift(l)):b.append(El.text("text"==g?f:a)):(g&&(b=El(g).to(b),d.unshift(l)),f&&(">"==f.charAt(0)?(c+" "+f.slice(1)).replace(n,e):"="==f.charAt(0)?b.set({"data-bind":f.slice(1)}):b.append(f.replace(/\\([=>:])/g,"$1"))))}var c=document.createDocumentFragment(),b=c,d=[-1];a.replace(n,e);d=c.childNodes;if(1==d.length)return d[0];
a=[];for(c=d.length;c--;)a[c]=d[c];return a}function h(a,e){this.name=e;this.parent=a;this.el=El("div");this.el.plugin=this;return this}var n=/^([ \t]*)(\:?)((?:(["'\/])(?:\\.|.)*?\4|[-\w\:.#\[\]=])+)[ \t]*(.*)$/gm;h.prototype.done=function(){El.cache(this.name,this.el.removeChild(this.el.firstChild),El.prototype.render);this.el.plugin=null;return this.parent};k.plugins={template:h};m.haml=k;m.include=function(a,e,c){e=El.get(a);(new h(null,a)).el.append(El.haml(e.innerHTML)).plugin.done();e.kill()}}(window.El||
this);

@@ -1,1 +0,1 @@

!function(d){function a(){var a=c.offsetWidth,b=601>a?"s-mob":1025>a?"s-tab":"s-full";b!=e&&(c.addClass(b).rmClass(e),e=b);b=a>c.offsetHeight?"s-land":"s-port";b!=f&&(c.addClass(b).rmClass(f),f=b);g()}var e,f,c=document.body,g=function(){d.M&&M.emit("resize")}.rate(200,!0);a();Event.add(d,"resize",a);Event.add(c,"orientationchange",a);Event.add(d,"load",a)}(this);
!function(d){function a(){var a=c.offsetWidth,b=601>a?"s-mob":1025>a?"s-tab":"s-full";b!=e&&(c.addClass(b).rmClass(e),e=b);b=a>c.offsetHeight?"s-land":"s-port";b!=f&&(c.addClass(b).rmClass(f),f=b);g()}var e,f,c=document.body,g=function(){d.M&&M.emit("resize")}.rate(200,!0);a();Event.add(d,"resize",a);Event.add(c,"orientationchange",a);Event.add(d,"load",a)}(this);

@@ -5,14 +5,13 @@

/*
* @version 0.2.4
* @date 2014-06-28
* @stability 1 - Experimental
* @author Lauri Rooden <lauri@rooden.ee>
* @license MIT License
*/
* @version 0.3.1
* @date 2014-08-27
* @stability 1 - Experimental
* @author Lauri Rooden <lauri@rooden.ee>
* @license MIT License
*/
/* TODO: find ways for automated testing
* http://www.browserscope.org/user/tests/howto
*/
// TODO: find ways for automated testing
// http://www.browserscope.org/user/tests/howto

@@ -25,7 +24,38 @@

, elRe = /([.#:[])([-\w]+)(?:=((["'\/])(?:\\.|.)*?\4|[-\w]+)])?]?/g
, 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))
},
"html": function(node, data, html) {
node.innerHTML = html.format(data)
},
/**
"with": function(node, data, scope) {
render.call(node, scope, true)
},
"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
}
}
/*
* Examples:
* - El("input#123.nice[type=checkbox]:checked:disabled[data-lang=en]")
*/
* Examples:
* - El("input#123.nice[type=checkbox]:checked:disabled[data-lang=en]")
*/

@@ -44,3 +74,3 @@ function El(name, args) {

// NOTE: IE’s cloneNode operation consolidates the two text nodes together as one
// NOTE: IE-s cloneNode consolidates the two text nodes together as one
// http://brooknovak.wordpress.com/2009/08/23/ies-clonenode-doesnt-actually-clone/

@@ -53,34 +83,30 @@ el = (elCache[name] || (elCache[name] = doc.createElement(name))).cloneNode(true).set(pre)

/* TODO: Extend El api
* add El.siblings( [selector ] )
* add El.children( [selector ] )
* add El.invoke
* https://github.com/WebReflection/dom4#dom4
*/
// 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
* -------------------------------
*
* 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.
*/
//
// How elements.js extends 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
*/
// ### 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
proto.append = function(child, before) {
var el = this
if (child) {
function append(child, before) {
var el = this
if (child) {
if (typeof child == "string" || typeof child == "number") child = El.text(child)

@@ -94,3 +120,3 @@ else if ( !("nodeType" in child) && "length" in child ) {

, fragment = doc.createDocumentFragment();
i < len; ) proto.append.call(fragment, child[i++]);
i < len; ) append.call(fragment, child[i++]);
child = fragment

@@ -105,11 +131,12 @@ }

)
if (child.append_hook) child.append_hook()
//"child_hook" in el && el.child_hook()
if (child.appendHook) child.appendHook()
//"childHook" in el && el.childHook()
}
return el
}
proto.append = append
proto.after = function(silbing, before) {
// call append from proto so it works with DocumentFragment
proto.append.call(silbing.parentNode, this, before ? silbing : silbing.nextSibling)
// call append so it works with DocumentFragment
append.call(silbing.parentNode, this, before ? silbing : silbing.nextSibling)
return this

@@ -119,7 +146,7 @@ }

proto.to = function(parent, before) {
proto.append.call(parent, this, before)
append.call(parent, this, before)
return this
}
proto.hasClass = function(name) {
function hasClass(name) {
// http://jsperf.com/regexp-indexof-perf/32

@@ -129,10 +156,12 @@ // return (" "+this.className+" ").indexOf(" "+name+" ") > -1

}
proto.hasClass = hasClass
proto.addClass = function(name) {
function addClass(name) {
var el = this
el.className += !el.className ? name : el.hasClass(name) ? "" : " " + name
el.className += !el.className ? name : hasClass.call(el, name) ? "" : " " + name
return el
}
proto.addClass = addClass
proto.rmClass = function(name) {
function rmClass(name) {
var el = this

@@ -142,22 +171,23 @@ el.className = (" "+el.className+" ").replace(" "+name+" "," ").trim()

}
proto.rmClass = rmClass
proto.toggleClass = function(name, force) {
if (arguments.length == 1) force = !this.hasClass(name)
this[ force ? "addClass" : "rmClass" ](name)
return force
if (arguments.length == 1) force = !hasClass.call(this, name)
return ( force ? addClass : rmClass ).call(this, name), force
}
proto.empty = function() {
for (var node, el = this; node = el.firstChild; ) el.kill.call(node)
for (var node, el = this; node = el.firstChild; ) kill.call(node)
return el
}
proto.kill = function() {
function kill() {
var el = this
if (el.parentNode) el.parentNode.removeChild(el)
if (Event.removeAll) Event.removeAll(el)
if (el.kill_hook) el.kill_hook()
if (el.killHook) el.killHook()
if (el.empty) el.empty()
return el
}
proto.kill = kill

@@ -180,11 +210,7 @@ proto.on = function(ev, fn) {

if (!args) return el
if (key == "string" || key == "number" || args.nodeType || "length" in args) el.append(args)
else for (key in args)
/** hasOwnProperty
if (args.hasOwnProperty(arg))
//*/
{
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") el.addClass(val)
if (key == "class") addClass.call(el, val)
else if (!val) el.removeAttribute(key)

@@ -216,2 +242,39 @@ else if (typeof val == "string") {

// 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)
}
}
return childs
}
function render(data, skipSelf) {
var bind, fn, lang
, node = this
if (bind = !skipSelf && node.getAttribute("data-bind")) {
lang = node.getAttribute("lang") || lang
// i18n(bind, lang).format(data)
// document.documentElement.lang
// document.getElementsByTagName('html')[0].getAttribute('lang')
fn = "n d p r->d&&(" + bind.replace(renderRe, "(p['$1']?(r=p['$1'](n,d,$2)||r):(n['$1']=$2.format(d))),") + "r)"
if (fn.fn()(node, data, bindings)) return node
}
for (node = node.firstChild; node; node = node.nextSibling) {
if (node.nodeType == 1) render.call(node, data)
}
return this
}
proto.render = render
// In Safari 2.x, innerText functions properly only

@@ -232,36 +295,61 @@ // if an element is neither hidden (via style.display == "none")

// Expose slow find for testing
//
// TODO: look another way
// NOTE: fast selectors for IE
// http://ajaxian.com/archives/creating-a-queryselector-for-ie-that-runs-at-native-speed
proto._find = function(sel) {
function findEl(node, sel, first) {
var el
, i = 0
, 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 = this.getElementsByTagName(tag)
, fn = Function("_", "return " + rules.join("&&"))
rules.push(
o == "." ? "(' '+_.className+' ').indexOf(' "+s+" ')>-1" :
o == "#" ? "_.id=='"+s+"'" :
"_.getAttribute('"+s+"')"+(v?"=='"+v+"'":"")
)
return ""
}) || "*"
, els = node.getElementsByTagName(tag)
, fn = Fn(rules.join("&&"))
while (el = els[i++]) {
if (fn(el)) {
return el.to ? el : extend(el)
}
for (; el = els[i++]; ) if (fn(el)) {
if (first) return el
out.push(el)
}
return first ? null : out
}
proto.find = doc.querySelector ?
// Note: IE8 don't support :disabled
// TODO: test with IE, should it be proto.querySelector or body.querySelector
proto.find = "\v" !== "v" && proto.querySelector || function(sel) {
return findEl(this, sel, true)
}
proto.findAll = proto.querySelectorAll ?
function(sel) {
// Note: IE8 don't support :disabled
return this.querySelector(sel)
} : proto._find
return new ElAll(this.querySelectorAll(sel))
} :
function(sel) {
return new ElAll(findEl(this, sel))
}
function ElAll(nodes) {
this._nodes = nodes
}
ElAll.prototype = Object.keys(proto).reduce(function(memo, key) {
memo[key] = function() {
var elAll = this
, nodes = elAll._nodes
, i = 0
, len = nodes.length
for (; i < len; ) {
proto[key].apply(nodes[i++], arguments)
}
return elAll
}
return memo
}, {})
function extend(node, key) {

@@ -278,2 +366,3 @@ if (node) for (key in proto) node[key] = proto[key]

// NOTE: document.body will not get extended with later added extensions
extend(doc.body)

@@ -287,2 +376,3 @@

}
root.El = El

@@ -296,3 +386,3 @@ El[protoStr] = proto

El.cache = function(name, el, custom) {
function elCacheFn(name, el, custom) {
elCache[name] = typeof el == "string" ? El(el) : el

@@ -303,10 +393,13 @@ if (custom) {

}
El.cache.el = elCache
El.cache.fn = fnCache
elCacheFn._el = elCache
elCacheFn._fn = fnCache
El.cache = elCacheFn
El.text = function(str) {
return doc.createTextNode(str)
}
root.El = El
}(window, document, "prototype")

@@ -13,13 +13,7 @@

!function(root, doc) {
!function(root) {
var hamlRe = /^([ \t]*)(\:?)((?:(["'\/])(?:\\.|.)*?\4|[-\w\:.#\[\]=])+)[ \t]*(.*)$/gm
function to_array(a) {
for (var b=[], c=a.length; c--;) b[c] = a[c]
return b
}
function haml(str) {
var root = doc.createDocumentFragment()
var root = document.createDocumentFragment()
, parent = root

@@ -38,6 +32,5 @@ , stack = [-1]

stack.unshift(i)
} else {
parent.append(El.text( name == "text" ? text : all ))
}
else {
parent.append(El.text( all ))
}
} else {

@@ -49,5 +42,9 @@ if (name) {

if (text) {
if (text.charAt(0)==">") (indent +" "+ text.slice(1)).replace(hamlRe, work)
else if (text.charAt(0)=="=") parent.set({"data-bind": text.slice(1)})
else parent.append(text.replace(/\\([=>:])/g, "$1"))
if (text.charAt(0) == ">") {
(indent +" "+ text.slice(1)).replace(hamlRe, work)
} else if (text.charAt(0) == "=") {
parent.set({"data-bind": text.slice(1)})
} else {
parent.append(text.replace(/\\([=>:])/g, "$1"))
}
}

@@ -58,3 +55,6 @@ }

stack = root.childNodes
return stack.length == 1 ? stack[0] : to_array(stack)
if (stack.length == 1) return stack[0]
for (var arr = [], i = stack.length; i--;) arr[i] = stack[i]
return arr
}

@@ -74,3 +74,3 @@

El.cache(t.name, t.el.removeChild(t.el.firstChild), render)
El.cache(t.name, t.el.removeChild(t.el.firstChild), El.prototype.render)

@@ -82,37 +82,17 @@ t.el.plugin = null

var ifFn = template.extend({
done: function(){
var t = this
El.cache(t.name, t.el.firstChild, render)
t.el.plugin = null
return t.parent
}
})
function toggleClass() {
}
haml.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,
"if": ifFn,
"for": function(parent, name, text) {
}
* - 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
}

@@ -125,71 +105,7 @@

src.kill()
}
// Use node initial content as template
function getTemplate(node) {
var template = node._template
if (!template) {
node._template = template = []
for (var child; child = node.firstChild;) {
template.push(child);
node.removeChild(child)
}
console.log(node, "TEMP", template)
}
return template
}
var attrMap = {
"txt": "textContent" in doc ? "textContent" : "innerText",
"toggleClass": toggleClass,
"html": "innerHTML",
"if": function(node, data, bind) {
var template = getTemplate(node)
var arr = data && data[bind]
if (arr) node.empty().append( Fn(bind)(data) && arr )
},
"each": function(node, data, bind) {
var template = getTemplate(node)
var arr = data && data[bind]
if (arr) node.empty().append(arr.map(function(obj){
return template.map(function(el){
return render.call(el.cloneNode(true), obj)
})
}))
}
}
}(window.El || this)
function render(data) {
var attr, bind, lang
, node = this
//console.log("render", data, node)
if (bind = node.getAttribute("data-bind")) {
lang = node.getAttribute("lang") || lang
if (attr = bind.match(/(\w+)\:/)) {
bind = bind.slice( attr[0].length )
attr = attrMap[attr[1]] || attr[1]
}
if (typeof attr == "function") {
attr(node, data, bind)
return node
}
else {
node[ attr || attrMap.txt ] = i18n(bind, lang).format(data)
}
}
for (node = node.firstChild; node; node = node.nextSibling) {
if (node.nodeType == 1) render.call(node, data)
}
return this
}
root.prototype.render = render
}(window.El || this, window.document)

@@ -59,3 +59,9 @@

}
<meta id="testViewport" name="viewport" content="width = 380">
<script>
if (screen.width > 740) {
var mvp = document.getElementById('testViewport');
mvp.setAttribute('content','width=740');
}
</script>
* */

@@ -62,0 +68,0 @@

{
"name": "elements-lite",
"version": "0.2.4",
"version": "0.3.1",
"stability": 1,

@@ -5,0 +5,0 @@ "license": "MIT",

@@ -9,4 +9,4 @@ [1]: https://secure.travis-ci.org/litejs/elements-lite.png

@version 0.2.4
@date 2014-06-28
@version 0.3.1
@date 2014-08-27
@stability 1 - Experimental

@@ -13,0 +13,0 @@

@@ -248,10 +248,10 @@ global.Event = global.Event || {}

it ( "should render data to elements" ).
equal(getString(t1 = El.haml("a>b>i =txt:hello {name}")), '<a><b><i data-bind="txt:hello {name}"></i></b></a>').
equal(getString(t1.render({name:"world"})), '<a><b><i data-bind="txt:hello {name}">hello world</i></b></a>').
equal(getString(t1.render({name:"moon"})), '<a><b><i data-bind="txt:hello {name}">hello moon</i></b></a>').
equal(getString(t1 = El.haml("a>b[data-bind=\"class:'red','i>1'\"]>i =txt:'hello {name}'")), "<a><b data-bind=\"class:'red','i>1'\"><i data-bind=\"txt:'hello {name}'\"></i></b></a>").
equal(getString(t1.render({i:1,name:"world"})), "<a><b data-bind=\"class:'red','i>1'\"><i data-bind=\"txt:'hello {name}'\">hello world</i></b></a>").
equal(getString(t1.render({i:2,name:"moon"})), "<a><b data-bind=\"class:'red','i>1'\" class=\"red\"><i data-bind=\"txt:'hello {name}'\">hello moon</i></b></a>").
it ( "should show set DOM propperty when plugin not found" ).
equal(getString(t1 = El.haml("a =unknown_plugin:hello {name}")), '<a data-bind="unknown_plugin:hello {name}"></a>').
equal(getString(t1.render({name:"world"})), '<a data-bind="unknown_plugin:hello {name}" unknown_plugin="hello world"></a>').
equal(getString(t1.render({name:"moon"})), '<a data-bind="unknown_plugin:hello {name}" unknown_plugin="hello moon"></a>').
equal(getString(t1 = El.haml("a =unknown_plugin:\'hello {name}\'")), '<a data-bind="unknown_plugin:\'hello {name}\'"></a>').
equal(getString(t1.render({name:"world"})), '<a data-bind="unknown_plugin:\'hello {name}\'" unknown_plugin="hello world"></a>').
equal(getString(t1.render({name:"moon"})), '<a data-bind="unknown_plugin:\'hello {name}\'" unknown_plugin="hello moon"></a>').

@@ -258,0 +258,0 @@ done()

@@ -7,2 +7,3 @@ var dom = require("dom-lite")

global.navigator = {language: "en-US"}
global.Fn = require("functional-lite").Fn

@@ -9,0 +10,0 @@ global.document.querySelector = global.document.querySelectorAll = null

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc