elements-lite
Advanced tools
Comparing version 0.1.9 to 0.1.10
@@ -38,3 +38,3 @@ | ||
if (typeof files == "string") files = [files]; | ||
for (var len = files.length, res = [];len--;) function(i) { | ||
for (var len = files.length, res = [];len--;) !function(i) { | ||
xhr("GET", files[i], function(str) { | ||
@@ -55,3 +55,4 @@ res[i] = str; | ||
*/ | ||
load( Function.prototype.bind ? "m.js" : ["up.js","m.js"]) | ||
Function.prototype.bind || _load.unshift("up.js") | ||
load(_load) | ||
111
elements.js
@@ -5,3 +5,3 @@ | ||
/* | ||
* @version 0.1.9 | ||
* @version 0.1.10 | ||
* @author Lauri Rooden - https://github.com/litejs/elements-lite | ||
@@ -17,6 +17,6 @@ * @license MIT License - http://lauri.rooden.ee/mit-license.txt | ||
!function(win, doc, P) { | ||
!function(root, doc, P) { | ||
var elCache = {} | ||
, fnCache = {} | ||
, proto = (win.HTMLElement || win.Element || El)[P] | ||
, proto = (root.HTMLElement || root.Element || El)[P] | ||
, el_re = /([.#:[])([-\w]+)(?:=([-\w]+)])?/g | ||
@@ -83,4 +83,4 @@ | ||
*/ | ||
var len = e.length, i = 0, f = doc.createDocumentFragment() | ||
while (i<len) t.append.call(f, e[i++]) | ||
for (var len = e.length, i = 0, f = doc.createDocumentFragment(); i<len;) t.append.call(f, e[i++]); | ||
e = f | ||
@@ -289,3 +289,3 @@ } | ||
} | ||
win.El = El | ||
root.El = El | ||
@@ -296,100 +296,1 @@ }(this, document, "prototype") | ||
/** Tests for El | ||
!function(){ | ||
var test_el = new TestCase("El"); | ||
var el = El("div") | ||
, select = El("select#id2.cl2:disabled") | ||
var h1 = El("h1"); | ||
var h2 = El("h2"); | ||
var h3 = El("h3"); | ||
var h4 = El("h4"); | ||
el.append(h2); | ||
test_el.compare(el.innerHTML.toLowerCase(), "<h2></h2>", "El.append"); | ||
h2.append(select) | ||
test_el.compare( | ||
el.find("#id2"), select | ||
, el.find(".cl2"), select | ||
//, el.find("select:disabled"), select | ||
, el.find("#id2.cl2"), select | ||
//, el.find("#id2.cl2:disabled"), select | ||
//, el.find("select#id2.cl2:disabled"), select | ||
, el.find("select#id2.cl2"), select | ||
, el.find("select#id2"), select | ||
, el.find("select"), select | ||
, el.find("h2"), h2 | ||
//, !!el.find("select:enabled"), false | ||
, !!el.find("select.cl3"), false | ||
, "El.find()"); | ||
select.kill(); | ||
el.append(h4, true); | ||
test_el.compare(el.innerHTML.toLowerCase().replace(/[\s\t\n\r]+/g,""), "<h4></h4><h2></h2>", "El.append"); | ||
h4.kill(); | ||
test_el.compare(el.innerHTML.toLowerCase(), "<h2></h2>", "El.kill"); | ||
h1.after(h2, true); | ||
test_el.compare(el.innerHTML.toLowerCase().replace(/[\s\t\n\r]+/g,""), "<h1></h1><h2></h2>", "El.after"); | ||
h3.after(h2); | ||
test_el.compare(el.innerHTML.toLowerCase().replace(/[\s\t\n\r]+/g,""), "<h1></h1><h2></h2><h3></h3>", "El.after"); | ||
el.empty(); | ||
test_el.compare(el.innerHTML.toLowerCase(), "", "El.empty"); | ||
el.append([h3,h4]) | ||
var str = el.innerHTML.toLowerCase().replace(/[\s\t\n\r]+/g,""); | ||
test_el.compare( | ||
str == "<h3></h3><h4></h4>" || str == "<div><h3></h3><h4></h4></div>", true, "El.append array"); | ||
el.addClass("test1"); | ||
test_el.compare(el.className, "test1", "El.addClass"); | ||
el.addClass("test2"); | ||
test_el.compare(el.className, "test1 test2"); | ||
el.addClass("test3"); | ||
test_el.compare(el.className, "test1 test2 test3"); | ||
el.addClass("test4"); | ||
test_el.compare(el.className, "test1 test2 test3 test4"); | ||
el.rmClass("test2"); | ||
test_el.compare(el.className, "test1 test3 test4", "El.rmClass"); | ||
el.rmClass("test1"); | ||
test_el.compare(el.className, "test3 test4"); | ||
el.rmClass("test4"); | ||
test_el.compare(el.className, "test3"); | ||
el.rmClass("c4"); | ||
test_el.compare(el.className, "test3"); | ||
var s; | ||
s = el.toggleClass("test4"); | ||
test_el.compare(el.className, "test3 test4", s, true, "El.toggleClass"); | ||
s = el.toggleClass("test4", true); | ||
test_el.compare(el.className, "test3 test4", s, true); | ||
s = el.toggleClass("test4"); | ||
test_el.compare(el.className, "test3", s, false); | ||
s = el.toggleClass("test4", false); | ||
test_el.compare(el.className, "test3", s, false); | ||
test_el.compare(el.hasClass("test3"), true, el.hasClass("test4"), false, "El.hasClass"); | ||
el.css("left","1px"); | ||
test_el.compare(el.css("left"), "1px", "El.css"); | ||
el.css({"top":"2px","left":"3px"}); | ||
test_el.compare(el.css("top"), "2px", el.css("left"), "3px", "El.css"); | ||
test_el.done(); | ||
}() | ||
//*/ | ||
@@ -1,6 +0,6 @@ | ||
!function(l,f,g){function e(a,b){var d,c={};a=a.replace(m,function(a,b,d,e){c["."==b?(b="class",c[b]&&(d=c[b]+" "+d),b):"#"==b?"id":d]=e||d;return""})||"div";d=(h[a]||(h[a]=f.createElement(a))).cloneNode(!0).set(c);return j[a]&&j[a](d,b)||d.set(b)}function k(a,b,d){if(a)for(d in b=e[g],b)a[d]=b[d];return a}var h={},j={},c=(l.HTMLElement||l.Element||e)[g],m=/([.#:[])([-\w]+)(?:=([-\w]+)])?/g;c.append=function(a,b){if(a){if("string"==typeof a||"number"==typeof a)a=e.text(a);else if(!("nodeType"in a)&& | ||
!function(m,f,g){function e(a,b){var d,c={};a=a.replace(n,function(a,b,d,e){c["."==b?(b="class",c[b]&&(d=c[b]+" "+d),b):"#"==b?"id":d]=e||d;return""})||"div";d=(h[a]||(h[a]=f.createElement(a))).cloneNode(!0).set(c);return k[a]&&k[a](d,b)||d.set(b)}function l(a,b,d){if(a)for(d in b=e[g],b)a[d]=b[d];return a}var h={},k={},c=(m.HTMLElement||m.Element||e)[g],n=/([.#:[])([-\w]+)(?:=([-\w]+)])?/g;c.append=function(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 d=a.length,c=0,g=f.createDocumentFragment();c<d;)this.append.call(g,a[c++]);a=g}a.nodeType&&this.insertBefore(a,(!0===b?this.firstChild:"number"==typeof b?this.childNodes[b]:b)||null);a.append_hook&&a.append_hook()}return this};c.after=function(a,b){a.parentNode.append(this,b?a:a.nextSibling);return this};c.to=function(a,b){a.append(this,b);return this};c.hasClass=function(a){return RegExp("\\b"+a+"\\b").test(this.className)};c.addClass=function(a){this.className+=""==this.className? | ||
a:this.hasClass(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=typeof a,d;if(a)if("string"==b||"number"==b||a.nodeType||"length"in a)this.append(a);else for(b in a)d=a[b],"class"==b?this.addClass(d):"string"==typeof d?(this.setAttribute(b,d),"name"==b&&"\v"=="v"&&this.mergeAttributes(f.createElement("<INPUT name='"+b+"'/>"),!1)):d?this[b]=d:this.removeAttribute(b);return this};c._find=function(a){var b=0,d=["_"];a=a.replace(m, | ||
function(a,b,c,e){d.push("."==b?"(' '+_.className+' ').indexOf(' "+c+" ')>-1":"#"==b?"_.id=='"+c+"'":"_.getAttribute(['"+c+"'])"+(e?"=='"+e+"'":""));return""})||"*";var c=this.getElementsByTagName(a),e=d.join("&&").fn();for(d.join("&&");a=c[b++];)if(e(a))return a.to?a:k(a)};c.find=f.querySelector?function(a){return this.querySelector(a)}:c._find;if(c===e[g]){var n=f.createElement;f.createElement=function(a){return k(n(a))};k(f.body)}e[g]=c;e.get=function(a){"string"==typeof a&&(a=f.getElementById(a)); | ||
return a&&a.to?a:k(a)};e.cache=function(a,b,c){h[a]="string"==typeof b?e(b):b;c&&(j[a]=c)};e.cache.el=h;e.cache.fn=j;e.text=function(a){return f.createTextNode(a)};l.El=e}(this,document,"prototype"); | ||
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=typeof a,d;if(a)if("string"==b||"number"==b||a.nodeType||"length"in a)this.append(a);else for(b in a)d=a[b],"class"==b?this.addClass(d):"string"==typeof d?(this.setAttribute(b,d),"name"==b&&"\v"=="v"&&this.mergeAttributes(f.createElement("<INPUT name='"+b+"'/>"),!1)):d?this[b]=d:this.removeAttribute(b);return this};c._find=function(a){var b=0,d=["_"];a=a.replace(n, | ||
function(a,b,c,e){d.push("."==b?"(' '+_.className+' ').indexOf(' "+c+" ')>-1":"#"==b?"_.id=='"+c+"'":"_.getAttribute(['"+c+"'])"+(e?"=='"+e+"'":""));return""})||"*";var c=this.getElementsByTagName(a),e=d.join("&&").fn();for(d.join("&&");a=c[b++];)if(e(a))return a.to?a:l(a)};c.find=f.querySelector?function(a){return this.querySelector(a)}:c._find;if(c===e[g]){var p=f.createElement;f.createElement=function(a){return l(p(a))};l(f.body)}e[g]=c;e.get=function(a){"string"==typeof a&&(a=f.getElementById(a)); | ||
return a&&a.to?a:l(a)};e.cache=function(a,b,c){h[a]="string"==typeof b?e(b):b;c&&(k[a]=c)};e.cache.el=h;e.cache.fn=k;e.text=function(a){return f.createTextNode(a)};m.El=e}(this,document,"prototype"); |
@@ -1,5 +0,5 @@ | ||
!function(k,j){function g(a){/[^0-9]/.test(a)&&(a='"'+a+'"');return a}function l(a){a=a.replace(/([^&\|\(\)]+)(\)?)(&|\||$)/g,function(a,b,f,c){c=f+c+c;if(~b.indexOf("*"))return'(""+i.'+b.split(".").join("\\.").split("*").join(".*").replace("=",").search(/")+"/i)>-1"+c;if(a=b.match(/^([^\[\{=]+)=?(\[|\{)([^\]\}]+)(\]|\})$/)){var e="i."+a[1];a=a[3].replace(/[^,]+/g,function(a){var b=a.split("-");if(1==b.length)return e+"=="+g(a);a=[];b[0].length&&a.push(e+">="+g(b[0]));b[1].length&&a.push(e+"<="+g(b[1])); | ||
return"("+a.join("&&")+")"});return"("+a.split(",").join("||")+")"+c}a=b.indexOf("=");return~a?"''+i."+b.substr(0,a)+"==''+"+g(b.substr(a+1))+c:~b.indexOf(".")?g(b)+'.split(".").fold(function(a,b){return a && b in a && a[b]}, i)':g(b)+" in i"+c});0<a.length&&(this.str=a,this.test=new Function("i","return i&&"+a))}Array.from=function(a){for(var d=[],b=a.length;b--;)d[b]=a[b];return d};Array.indexFor=function(a,d,b){var f,c=0,e=a.length;if(b&&0<e&&1>b(d,a[e-1]))for(;c<e;)0>b(d,a[f=c+e>>1])?e=f:c=f+ | ||
1;return e};var h=Init.extend(j.Events,{init:function(a){this.data=a;this.previous={};this.lists=[]},set:function(a,d){var b=this.data,f=[],c;for(c in a)a.hasOwnProperty(c)&&b[c]!==a[c]&&(this.previous[c]=b[c],b[c]=a[c],f.push(c));!d&&f.length&&this.emit("change",f);return f},get:function(a){return this.data[a]}}).cache(!0,function(a){return a[0].id});h.merge=function(a,d,b,f){b=b||"";f=f||[];var c,e;for(c in d)d.hasOwnProperty(c)&&a[c]!==d[c]&&(e=d[c],f.push(b+c),null===e?delete a[c]:"object"==typeof e&& | ||
Object.keys(e).length&&"object"==typeof a[c]?h.merge(a[c],e,b+c+".",f):a[c]=e);return f};var m=Init.extend(j.Items,j.Events,{init:function(a){this.name=a;this.items=[]},model:h,add:function(a,d){var b=a;b instanceof this.model||(b=this.model(a),b.set(a,!0));-1==b.lists.indexOf(this)&&(b.lists.push(this),d=void 0!==d?d:Array.indexFor(this.items,b,this.sortFn),this.items.splice(d,0,b),this.emit("add",b,d));return this},set:function(a,d){this.each(function(b){b.set(a,d)})},remove:function(a){-1<a.lists.remove(this)&& | ||
this.emit("remove",a,this.items.remove(a))},removeAll:function(){for(var a=this.items.length;a--;)this.remove(this.items[a])},toString:function(){return"[List: "+this.name+"]"}}).cache(!0);l.prototype={test:True,str:"all",subset:function(a){return"all"==a.str||~this.str.indexOf(a.str)},toString:function(){return"[Filter: "+this.str+"]"}};m.Filter=l.cache(!0);k.Model=h;k.List=m}(this,Fn); | ||
!function(l){function g(a){/[^0-9]/.test(a)&&(a='"'+a+'"');return a}function m(a){a=a.replace(/([^&\|\(\)]+)(\)?)(&|\||$)/g,function(a,b,d,c){c=d+c+c;if(~b.indexOf("*"))return'(""+i.'+b.split(".").join("\\.").split("*").join(".*").replace("=",").search(/")+"/i)>-1"+c;if(a=b.match(/^([^\[\{=]+)=?(\[|\{)([^\]\}]+)(\]|\})$/)){var f="i."+a[1];a=a[3].replace(/[^,]+/g,function(a,b,c){b=a.split("-");if(1==b.length)return f+"=="+g(a);a=[];b[0].length&&a.push(f+">="+g(b[0]));b[1].length&&a.push(f+"<="+g(b[1])); | ||
return"("+a.join("&&")+")"});return"("+a.split(",").join("||")+")"+c}a=b.indexOf("=");return~a?"''+i."+b.substr(0,a)+"==''+"+g(b.substr(a+1))+c:~b.indexOf(".")?g(b)+'.split(".").fold(function(a,b){return a && b in a && a[b]}, i)':g(b)+" in i"+c});0<a.length&&(this.str=a,this.test=new Function("i","return i&&"+a))}var h=Init.extend(Fn.Events,{init:function(a){this.data=a;this.previous={};this.lists=[]},set:function(a,e){var b=this.data,d=[],c;for(c in a)a.hasOwnProperty(c)&&b[c]!==a[c]&&(this.previous[c]= | ||
b[c],b[c]=a[c],d.push(c));!e&&d.length&&this.emit("change",d,e);return d},get:function(a){return this.data[a]},destroy:function(a){for(var e=this.lists,b=e.length;0<b;)e[--b].remove(this);this.trigger("destroy",a)}}).cache(!0,function(a){return a[0].id}),n=Init.extend(Fn.Items,Fn.Events,{init:function(a){this.name=a;this.items=[]},model:h,add:function(a,e){var b=a;b instanceof this.model||(b=this.model(a),b.set(a,!0));if(-1==b.lists.indexOf(this)){b.lists.push(this);var d;if(void 0!==e)d=e;else{d= | ||
this.items;var c=b,f=this.sortFn,g,h=0,k=d.length;if(f&&0<k&&1>f(c,d[k-1]))for(;h<k;)0>f(c,d[g=h+k>>1])?k=g:h=g+1;d=k}e=d;this.items.splice(e,0,b);this.emit("add",b,e)}return this},set:function(a,e){this.each(function(b){b.set(a,e)})},remove:function(a){-1<a.lists.remove(this)&&this.emit("remove",a,this.items.remove(a))},removeAll:function(){for(var a=this.items.length;a--;)this.remove(this.items[a])},toString:function(){return"[List: "+this.name+"]"}}).cache(!0);m.prototype={test:True,str:"all", | ||
subset:function(a){return"all"==a.str||~this.str.indexOf(a.str)},toString:function(){return"[Filter: "+this.str+"]"}};n.Filter=m.cache(!0);l.Model=h;l.List=n;h.merge=function(a,e,b,d){b=b||"";d=d||[];var c,f;for(c in e)e.hasOwnProperty(c)&&a[c]!==e[c]&&(f=e[c],d.push(b+c),null===f?delete a[c]:"object"==typeof f&&Object.keys(f).length&&"object"==typeof a[c]?h.merge(a[c],f,b+c+".",d):a[c]=f);return d}}(this); |
75
mvc.js
@@ -5,3 +5,3 @@ | ||
/* | ||
* @version 0.1.9 | ||
* @version 0.1.10 | ||
* @author Lauri Rooden - https://github.com/litejs/elements-lite | ||
@@ -13,11 +13,7 @@ * @license MIT License - http://lauri.rooden.ee/mit-license.txt | ||
!function(root) { | ||
!function(exports, Fn) { | ||
Array.from = function(a) { | ||
for (var b=[], c=a.length; c--;) b[c] = a[c] | ||
return b | ||
} | ||
Array.indexFor = function(arr, el, fn) { | ||
function indexFor(arr, el, fn) { | ||
var o | ||
@@ -30,5 +26,5 @@ , i = 0 | ||
} | ||
return l | ||
} | ||
var Model = Init.extend(Fn.Events, { | ||
@@ -49,3 +45,3 @@ init: function(data) { | ||
if (!silent && changed.length) { | ||
t.emit("change", changed) | ||
t.emit("change", changed, silent) | ||
} | ||
@@ -56,19 +52,13 @@ return changed | ||
return this.data[name] | ||
} | ||
}).cache(true, function(a){return a[0]["id"]}) | ||
}, | ||
destroy: function(options) { | ||
var t = this | ||
, arr = t.lists | ||
, len = arr.length | ||
Model.merge = function(cur, next, path, changed) { | ||
path = path || "" | ||
changed = changed || [] | ||
for (;len > 0;) arr[--len].remove(t) | ||
var key, val | ||
for (key in next) if (next.hasOwnProperty(key) && cur[key] !== next[key]) { | ||
val = next[key] | ||
changed.push(path+key) | ||
if (val === null) delete cur[key] | ||
else if (typeof val == "object" && Object.keys(val).length && typeof cur[key] == "object") Model.merge(cur[key], val, path+key+".", changed) | ||
else cur[key] = val | ||
t.trigger("destroy", options); | ||
} | ||
return changed | ||
} | ||
}).cache(true, function(a){return a[0]["id"]}) | ||
@@ -87,3 +77,3 @@ var List = Init.extend(Fn.Items, Fn.Events, { | ||
item.lists.push(t) | ||
pos = pos !== void 0 ? pos : Array.indexFor(t.items, item, t.sortFn) | ||
pos = pos !== void 0 ? pos : indexFor(t.items, item, t.sortFn) | ||
t.items.splice(pos , 0, item) | ||
@@ -184,28 +174,23 @@ t.emit("add", item, pos) | ||
exports.Model = Model | ||
exports.List = List | ||
root.Model = Model | ||
root.List = List | ||
}(this, Fn) | ||
Model.merge = function(cur, next, path, changed) { | ||
path = path || "" | ||
changed = changed || [] | ||
var key, val | ||
for (key in next) if (next.hasOwnProperty(key) && cur[key] !== next[key]) { | ||
val = next[key] | ||
changed.push(path+key) | ||
if (val === null) delete cur[key] | ||
else if (typeof val == "object" && Object.keys(val).length && typeof cur[key] == "object") Model.merge(cur[key], val, path+key+".", changed) | ||
else cur[key] = val | ||
} | ||
return changed | ||
} | ||
/** Tests | ||
!function(){ | ||
var test = new TestCase("Model"); | ||
}(this) | ||
var sortedList = List.extend({sortFn: function(a, b){return a.get("id") - b.get("id")}}); | ||
var list = sortedList("test"); | ||
list.add({id:1}) | ||
list.add({id:3}) | ||
list.add({id:2}) | ||
list.add({id:3}) | ||
test.compare( | ||
list.pluck("id").join(",") | ||
, "1,2,3" | ||
, "List.add"); | ||
test.done(); | ||
}() | ||
//*/ | ||
{ | ||
"name": "elements-lite", | ||
"version": "0.1.9", | ||
"license": "MIT", | ||
"description": "DOM buildel for browser", | ||
"main": "elements.js", | ||
"author": "Lauri Rooden <lauri@rooden.ee>", | ||
"repository": { | ||
"type": "git", | ||
"url": "git://github.com/litejs/elements-lite.git" | ||
}, | ||
"bugs": { | ||
"url": "https://github.com/litejs/elements-lite/issues" | ||
}, | ||
"keywords": [ | ||
"browser", | ||
"name": "elements-lite", | ||
"version": "0.1.10", | ||
"license": "MIT", | ||
"description": "DOM buildel for browser", | ||
"main": "elements.js", | ||
"author": "Lauri Rooden <lauri@rooden.ee>", | ||
"repository": { | ||
"type": "git", | ||
"url": "git://github.com/litejs/elements-lite.git" | ||
}, | ||
"bugs": { | ||
"url": "https://github.com/litejs/elements-lite/issues" | ||
}, | ||
"keywords": [ | ||
"browser", | ||
"elements", | ||
"DOM", | ||
"litejs" | ||
], | ||
"readmeFilename": "README.md" | ||
"litejs" | ||
], | ||
"scripts": { | ||
"test": "node tests/run.js" | ||
}, | ||
"readmeFilename": "README.md" | ||
} |
@@ -5,3 +5,3 @@ | ||
/* | ||
* @version 0.1.9 | ||
* @version 0.1.10 | ||
* @author Lauri Rooden - https://github.com/litejs/elements-lite | ||
@@ -8,0 +8,0 @@ * @license MIT License - http://lauri.rooden.ee/mit-license.txt |
Sorry, the diff of this file is not supported yet
39713
20
759