transparency
Advanced tools
Comparing version 0.7.7 to 0.7.9
@@ -88,3 +88,3 @@ // Generated by CoffeeScript 1.4.0 | ||
}; | ||
expected = $("<div id=\"template\">\n <h1 class=\"title\">Some widgets</h1>\n <div class=\"widgets\">\n <div class=\"widget\">\n <div>First</div>\n </div>\n <div class=\"widget\">\n <div>Second</div>\n </div> \n </div>\n</div>"); | ||
expected = $("<div id=\"template\">\n <h1 class=\"title\">Some widgets</h1>\n <div class=\"widgets\">\n <div class=\"widget\">\n <div>First</div>\n </div>\n <div class=\"widget\">\n <div>Second</div>\n </div>\n </div>\n</div>"); | ||
template.render(data); | ||
@@ -128,3 +128,3 @@ return expect(template).toBeEqual(expected); | ||
}); | ||
return it("should render empty string, zero and other falsy values", function() { | ||
it("should render empty string, zero and other falsy values", function() { | ||
var data, expected, template; | ||
@@ -142,4 +142,32 @@ template = $("<div id=\"root\">\n <span id=\"number\">234</span>\n <span id=\"bool\">foo</span>\n <span id=\"dec\">1.234</span>\n <span id=\"str\">abc</span>\n</div>"); | ||
}); | ||
return it("should not render text content to img tags and other void elements", function() { | ||
var data, directives, expected, template; | ||
template = $("<div id=\"gallery\">\n <b data-bind=\"name\"></b>\n <img data-bind=\"image\" src=\"\" alt=\"\" />\n</div>"); | ||
data = [ | ||
{ | ||
name: 'gal1', | ||
image: 'http://example.com/image_name_1' | ||
}, { | ||
name: 'gal2', | ||
image: 'http://example.com/image_name_2' | ||
} | ||
]; | ||
directives = { | ||
name: { | ||
text: function() { | ||
return this.name; | ||
} | ||
}, | ||
image: { | ||
src: function() { | ||
return this.image; | ||
} | ||
} | ||
}; | ||
expected = $("<div id=\"gallery\">\n <b data-bind=\"name\">gal1</b>\n <img data-bind=\"image\" src=\"http://example.com/image_name_1\" alt=\"\" />\n <b data-bind=\"name\">gal2</b>\n <img data-bind=\"image\" src=\"http://example.com/image_name_2\" alt=\"\" />\n</div>"); | ||
template.render(data, directives); | ||
return expect(template).toBeEqual(expected); | ||
}); | ||
}); | ||
}).call(this); |
{ | ||
"name": "transparency", | ||
"version": "0.7.7", | ||
"version": "0.7.9", | ||
"main": "./lib/transparency.js" | ||
} |
@@ -15,3 +15,3 @@ // Generated by CoffeeScript 1.4.0 | ||
})(this, function() { | ||
var $, ELEMENT_NODE, Instance, TEXT_NODE, attr, cloneNode, consoleLogger, data, empty, expando, exports, getElementsAndChildNodes, getText, html5Clone, isBoolean, isDate, isDomElement, isPlainValue, log, matcher, matchingElements, nullLogger, prepareContext, register, render, renderDirectives, setHtml, setSelected, setText, _base, _ref, _ref1; | ||
var $, ELEMENT_NODE, Instance, TEXT_NODE, VOID_ELEMENTS, attr, cloneNode, consoleLogger, data, empty, expando, exports, getElementsAndChildNodes, getText, html5Clone, isBoolean, isDate, isDomElement, isPlainValue, isVoidElement, log, matcher, matchingElements, nullLogger, prepareContext, register, render, renderDirectives, setHtml, setSelected, setText, _base, _ref, _ref1; | ||
register = function($) { | ||
@@ -315,9 +315,11 @@ return $.fn.render = function(models, directives, config) { | ||
case 'text': | ||
if ((value != null) && typeof value !== 'string') { | ||
value = value.toString(); | ||
if (!isVoidElement(element)) { | ||
if ((value != null) && typeof value !== 'string') { | ||
value = value.toString(); | ||
} | ||
(_base = elementData.originalAttributes)['text'] || (_base['text'] = getText(element)); | ||
if (value != null) { | ||
setText(element, value); | ||
} | ||
} | ||
(_base = elementData.originalAttributes)['text'] || (_base['text'] = getText(element)); | ||
if (value != null) { | ||
setText(element, value); | ||
} | ||
break; | ||
@@ -341,7 +343,7 @@ case 'html': | ||
(_base3 = elementData.originalAttributes)[attribute] || (_base3[attribute] = element.getAttribute(attribute)); | ||
if (isBoolean(value)) { | ||
element[attribute] = value; | ||
} else { | ||
if (value != null) { | ||
if (value != null) { | ||
if (attribute.match(/^data-.*/)) { | ||
element.setAttribute(attribute, value); | ||
} else { | ||
element[attribute] = value; | ||
} | ||
@@ -386,2 +388,3 @@ } | ||
TEXT_NODE = 3; | ||
VOID_ELEMENTS = ["area", "base", "br", "col", "command", "embed", "hr", "img", "input", "keygen", "link", "meta", "param", "source", "track", "wbr"]; | ||
html5Clone = function() { | ||
@@ -421,2 +424,5 @@ return document.createElement("nav").cloneNode(true).outerHTML !== "<:nav></:nav>"; | ||
}; | ||
isVoidElement = function(el) { | ||
return VOID_ELEMENTS.indexOf(el.nodeName.toLowerCase()) > -1; | ||
}; | ||
isPlainValue = function(obj) { | ||
@@ -423,0 +429,0 @@ return isDate(obj) || typeof obj !== 'object' && typeof obj !== 'function'; |
// Generated by CoffeeScript 1.4.0 | ||
(function(){var e=[].slice,t={}.hasOwnProperty;(function(e,t){return(typeof define!="undefined"&&define!==null?define.amd:void 0)?define(t):(typeof module!="undefined"&&module!==null?module.exports:void 0)?module.exports=t():e.Transparency=t()})(this,function(){var n,r,i,s,o,u,a,f,l,c,h,p,d,v,m,g,y,b,w,E,S,x,T,N,C,k,L,A,O,M,_,D;N=function(e){return e.fn.render=function(e,t,n){var r,i,s;for(i=0,s=this.length;i<s;i++)r=this[i],C(r,e,t,n);return this}};if(this.jQuery!=null||this.Zepto!=null)n=this.jQuery||this.Zepto,N(n);return c="transparency",f=function(e){return e[c]||(e[c]={})},x=function(){},a=function(){var t;return t=1<=arguments.length?e.call(arguments,0):[],console.log.apply(console,t)},w=x,C=function(e,n,r,i){var s,u,c,h,p,d,v,m,g,E,N,L,A,O,M,_,D,P,H,B,j,F,I,q,R;w=(i!=null?i.debug:void 0)&&typeof console!="undefined"&&console!==null?a:x,w("Context:",e,"Models:",n,"Directives:",r,"Config:",i);if(!e)return;n||(n=[]),r||(r={}),Array.isArray(n)||(n=[n]),E=e.parentNode,E&&(N=e.nextSibling,E.removeChild(e)),T(e,n),u=f(e);for(p=A=0,D=n.length;A<D;p=++A){m=n[p],s=[],d=u.instances[p],w("Model:",m,"Template instance for the model:",d),I=d.elements;for(O=0,P=I.length;O<P;O++)c=I[O],f(c).model=m;if(y(m)&&(h=d.elements[0]))l(h).appendChild(m);else if(typeof m=="object")for(v in m){if(!t.call(m,v))continue;L=m[v];if(L!=null)if(b(L)){q=S(d,v);for(M=0,H=q.length;M<H;M++)h=q[M],g=h.nodeName.toLowerCase(),g==="input"?o(h,"value",L):g==="select"?o(h,"selected",L):o(h,"text",L)}else typeof L=="object"&&s.push(v)}k(d,m,p,r);for(_=0,B=s.length;_<B;_++){v=s[_],R=S(d,v);for(F=0,j=R.length;F<j;F++)h=R[F],C(h,m[v],r[v],i)}}return E&&(N?E.insertBefore(e,N):E.appendChild(e)),e},T=function(e,t){var n,r,s,o,a,l,c;n=f(e),n.template||(n.template=u(e),n.instanceCache=[],n.instances=[new i(e)]),w("Template",n.template);while(t.length>n.instances.length){r=n.instanceCache.pop()||new i(u(n.template)),l=r.childNodes;for(o=0,a=l.length;o<a;o++)s=l[o],e.appendChild(s);n.instances.push(r)}c=[];while(t.length<n.instances.length)n.instanceCache.push(r=n.instances.pop()),c.push(function(){var e,t,n,i;n=r.childNodes,i=[];for(e=0,t=n.length;e<t;e++)s=n[e],i.push(s.parentNode.removeChild(s));return i}());return c},i=function(){function e(e){this.template=e,this.queryCache={},this.elements=[],this.childNodes=[],p(this.template,this.elements,this.childNodes)}return e}(),p=function(e,t,n){var i,s;i=e.firstChild,s=[];while(i)n!=null&&n.push(i),i.nodeType===r&&(t.push(i),p(i,t)),s.push(i=i.nextSibling);return s},k=function(e,n,r,i){var s,u,a,f,l,c,h;if(!i)return;n=typeof n=="object"?n:{value:n},h=[];for(l in i){if(!t.call(i,l))continue;u=i[l],typeof u=="object"&&h.push(function(){var t,i,h,p;h=S(e,l),p=[];for(t=0,i=h.length;t<i;t++)f=h[t],p.push(function(){var e;e=[];for(s in u){a=u[s];if(typeof a!="function")continue;c=a.call(n,{element:f,index:r,value:o(f,s)}),e.push(o(f,s,c))}return e}());return p}())}return h},L=function(e,t){var n,i,s,o,u,a,c;i=f(e);if(i.html===t)return;i.html=t,i.children||(i.children=function(){var t,n,i,o;i=e.childNodes,o=[];for(t=0,n=i.length;t<n;t++)s=i[t],s.nodeType===r&&o.push(s);return o}()),l(e),e.innerHTML=t,a=i.children,c=[];for(o=0,u=a.length;o<u;o++)n=a[o],c.push(e.appendChild(n));return c},O=function(e,t){var n,r;n=f(e);if(t==null||n.text===t)return;return n.text=t,r=e.firstChild,r?r.nodeType!==s?e.insertBefore(e.ownerDocument.createTextNode(t),r):r.nodeValue=t:e.appendChild(e.ownerDocument.createTextNode(t))},d=function(e){var t;return function(){var n,r,i,o;i=e.childNodes,o=[];for(n=0,r=i.length;n<r;n++)t=i[n],t.nodeType===s&&o.push(t.nodeValue);return o}().join("")},A=function(e,t){var n,r,i,s,o;r=[],p(e,r),o=[];for(i=0,s=r.length;i<s;i++)n=r[i],n.nodeName.toLowerCase()==="option"?n.value===t?o.push(n.selected=!0):o.push(n.selected=!1):o.push(void 0);return o},o=function(e,t,n){var r,i,s,o,u;r=f(e),r.originalAttributes||(r.originalAttributes={});if(e.nodeName.toLowerCase()==="select"&&t==="selected")n!=null&&typeof n!="string"&&(n=n.toString()),n!=null&&A(e,n);else switch(t){case"text":n!=null&&typeof n!="string"&&(n=n.toString()),(i=r.originalAttributes).text||(i.text=d(e)),n!=null&&O(e,n);break;case"html":n!=null&&typeof n!="string"&&(n=n.toString()),(s=r.originalAttributes).html||(s.html=e.innerHTML),n!=null&&L(e,n);break;case"class":(o=r.originalAttributes)["class"]||(o["class"]=e.className),n!=null&&(e.className=n);break;default:(u=r.originalAttributes)[t]||(u[t]=e.getAttribute(t)),m(n)?e[t]=n:n!=null&&e.setAttribute(t,n)}return n!=null?n:r.originalAttributes[t]},S=function(e,t){var n,r,i;return r=(i=e.queryCache)[t]||(i[t]=function(){var r,i,s,o;s=e.elements,o=[];for(r=0,i=s.length;r<i;r++)n=s[r],h.matcher(n,t)&&o.push(n);return o}()),w("Matching elements for '"+t+"':",r),r},E=function(e,t){return e.id===t||e.className.split(" ").indexOf(t)>-1||e.name===t||e.getAttribute("data-bind")===t},l=function(e){var t;while(t=e.firstChild)e.removeChild(t);return e},r=1,s=3,v=function(){return document.createElement("nav").cloneNode(!0).outerHTML!=="<:nav></:nav>"},u=typeof document=="undefined"||document===null||v()?function(e){return e.cloneNode(!0)}:function(e){var t,i,s,o,u;t=n(e).clone()[0];if(t.nodeType===r){t.removeAttribute(c),u=t.getElementsByTagName("*");for(s=0,o=u.length;s<o;s++)i=u[s],i.removeAttribute(c)}return t},(_=Array.isArray)==null&&(Array.isArray=function(e){return n.isArray(e)}),(D=(M=Array.prototype).indexOf)==null&&(M.indexOf=function(e){return n.inArray(e,this)}),g=function(e){return Object.prototype.toString.call(e)==="[object Date]"},y=function(e){return(e!=null?e.nodeType:void 0)===r},b=function(e){return g(e)||typeof e!="object"&&typeof e!="function"},m=function(e){return e===!0||e===!1},h={render:C,register:N,matcher:E}})}).call(this); | ||
(function(){var e=[].slice,t={}.hasOwnProperty;(function(e,t){return(typeof define!="undefined"&&define!==null?define.amd:void 0)?define(t):(typeof module!="undefined"&&module!==null?module.exports:void 0)?module.exports=t():e.Transparency=t()})(this,function(){var n,r,i,s,o,u,a,f,l,c,h,p,d,v,m,g,y,b,w,E,S,x,T,N,C,k,L,A,O,M,_,D,P,H;k=function(e){return e.fn.render=function(e,t,n){var r,i,s;for(i=0,s=this.length;i<s;i++)r=this[i],L(r,e,t,n);return this}};if(this.jQuery!=null||this.Zepto!=null)n=this.jQuery||this.Zepto,k(n);return h="transparency",l=function(e){return e[h]||(e[h]={})},N=function(){},f=function(){var t;return t=1<=arguments.length?e.call(arguments,0):[],console.log.apply(console,t)},S=N,L=function(e,n,r,i){var s,o,a,h,p,d,v,m,g,y,E,x,k,O,M,_,D,P,H,B,j,F,I,q,R;S=(i!=null?i.debug:void 0)&&typeof console!="undefined"&&console!==null?f:N,S("Context:",e,"Models:",n,"Directives:",r,"Config:",i);if(!e)return;n||(n=[]),r||(r={}),Array.isArray(n)||(n=[n]),y=e.parentNode,y&&(E=e.nextSibling,y.removeChild(e)),C(e,n),o=l(e);for(p=k=0,D=n.length;k<D;p=++k){m=n[p],s=[],d=o.instances[p],S("Model:",m,"Template instance for the model:",d),I=d.elements;for(O=0,P=I.length;O<P;O++)a=I[O],l(a).model=m;if(b(m)&&(h=d.elements[0]))c(h).appendChild(m);else if(typeof m=="object")for(v in m){if(!t.call(m,v))continue;x=m[v];if(x!=null)if(w(x)){q=T(d,v);for(M=0,H=q.length;M<H;M++)h=q[M],g=h.nodeName.toLowerCase(),g==="input"?u(h,"value",x):g==="select"?u(h,"selected",x):u(h,"text",x)}else typeof x=="object"&&s.push(v)}A(d,m,p,r);for(_=0,B=s.length;_<B;_++){v=s[_],R=T(d,v);for(F=0,j=R.length;F<j;F++)h=R[F],L(h,m[v],r[v],i)}}return y&&(E?y.insertBefore(e,E):y.appendChild(e)),e},C=function(e,t){var n,r,s,o,u,f,c;n=l(e),n.template||(n.template=a(e),n.instanceCache=[],n.instances=[new i(e)]),S("Template",n.template);while(t.length>n.instances.length){r=n.instanceCache.pop()||new i(a(n.template)),f=r.childNodes;for(o=0,u=f.length;o<u;o++)s=f[o],e.appendChild(s);n.instances.push(r)}c=[];while(t.length<n.instances.length)n.instanceCache.push(r=n.instances.pop()),c.push(function(){var e,t,n,i;n=r.childNodes,i=[];for(e=0,t=n.length;e<t;e++)s=n[e],i.push(s.parentNode.removeChild(s));return i}());return c},i=function(){function e(e){this.template=e,this.queryCache={},this.elements=[],this.childNodes=[],d(this.template,this.elements,this.childNodes)}return e}(),d=function(e,t,n){var i,s;i=e.firstChild,s=[];while(i)n!=null&&n.push(i),i.nodeType===r&&(t.push(i),d(i,t)),s.push(i=i.nextSibling);return s},A=function(e,n,r,i){var s,o,a,f,l,c,h;if(!i)return;n=typeof n=="object"?n:{value:n},h=[];for(l in i){if(!t.call(i,l))continue;o=i[l],typeof o=="object"&&h.push(function(){var t,i,h,p;h=T(e,l),p=[];for(t=0,i=h.length;t<i;t++)f=h[t],p.push(function(){var e;e=[];for(s in o){a=o[s];if(typeof a!="function")continue;c=a.call(n,{element:f,index:r,value:u(f,s)}),e.push(u(f,s,c))}return e}());return p}())}return h},O=function(e,t){var n,i,s,o,u,a,f;i=l(e);if(i.html===t)return;i.html=t,i.children||(i.children=function(){var t,n,i,o;i=e.childNodes,o=[];for(t=0,n=i.length;t<n;t++)s=i[t],s.nodeType===r&&o.push(s);return o}()),c(e),e.innerHTML=t,a=i.children,f=[];for(o=0,u=a.length;o<u;o++)n=a[o],f.push(e.appendChild(n));return f},_=function(e,t){var n,r;n=l(e);if(t==null||n.text===t)return;return n.text=t,r=e.firstChild,r?r.nodeType!==s?e.insertBefore(e.ownerDocument.createTextNode(t),r):r.nodeValue=t:e.appendChild(e.ownerDocument.createTextNode(t))},v=function(e){var t;return function(){var n,r,i,o;i=e.childNodes,o=[];for(n=0,r=i.length;n<r;n++)t=i[n],t.nodeType===s&&o.push(t.nodeValue);return o}().join("")},M=function(e,t){var n,r,i,s,o;r=[],d(e,r),o=[];for(i=0,s=r.length;i<s;i++)n=r[i],n.nodeName.toLowerCase()==="option"?n.value===t?o.push(n.selected=!0):o.push(n.selected=!1):o.push(void 0);return o},u=function(e,t,n){var r,i,s,o,u;r=l(e),r.originalAttributes||(r.originalAttributes={});if(e.nodeName.toLowerCase()==="select"&&t==="selected")n!=null&&typeof n!="string"&&(n=n.toString()),n!=null&&M(e,n);else switch(t){case"text":E(e)||(n!=null&&typeof n!="string"&&(n=n.toString()),(i=r.originalAttributes).text||(i.text=v(e)),n!=null&&_(e,n));break;case"html":n!=null&&typeof n!="string"&&(n=n.toString()),(s=r.originalAttributes).html||(s.html=e.innerHTML),n!=null&&O(e,n);break;case"class":(o=r.originalAttributes)["class"]||(o["class"]=e.className),n!=null&&(e.className=n);break;default:(u=r.originalAttributes)[t]||(u[t]=e.getAttribute(t)),n!=null&&(t.match(/^data-.*/)?e.setAttribute(t,n):e[t]=n)}return n!=null?n:r.originalAttributes[t]},T=function(e,t){var n,r,i;return r=(i=e.queryCache)[t]||(i[t]=function(){var r,i,s,o;s=e.elements,o=[];for(r=0,i=s.length;r<i;r++)n=s[r],p.matcher(n,t)&&o.push(n);return o}()),S("Matching elements for '"+t+"':",r),r},x=function(e,t){return e.id===t||e.className.split(" ").indexOf(t)>-1||e.name===t||e.getAttribute("data-bind")===t},c=function(e){var t;while(t=e.firstChild)e.removeChild(t);return e},r=1,s=3,o=["area","base","br","col","command","embed","hr","img","input","keygen","link","meta","param","source","track","wbr"],m=function(){return document.createElement("nav").cloneNode(!0).outerHTML!=="<:nav></:nav>"},a=typeof document=="undefined"||document===null||m()?function(e){return e.cloneNode(!0)}:function(e){var t,i,s,o,u;t=n(e).clone()[0];if(t.nodeType===r){t.removeAttribute(h),u=t.getElementsByTagName("*");for(s=0,o=u.length;s<o;s++)i=u[s],i.removeAttribute(h)}return t},(P=Array.isArray)==null&&(Array.isArray=function(e){return n.isArray(e)}),(H=(D=Array.prototype).indexOf)==null&&(D.indexOf=function(e){return n.inArray(e,this)}),y=function(e){return Object.prototype.toString.call(e)==="[object Date]"},b=function(e){return(e!=null?e.nodeType:void 0)===r},E=function(e){return o.indexOf(e.nodeName.toLowerCase())>-1},w=function(e){return y(e)||typeof e!="object"&&typeof e!="function"},g=function(e){return e===!0||e===!1},p={render:L,register:k,matcher:x}})}).call(this); |
{ | ||
"name" : "transparency", | ||
"version" : "0.7.7", | ||
"version" : "0.7.9", | ||
"main" : "lib/transparency", | ||
@@ -5,0 +5,0 @@ "description" : "Transparency is a minimal template engine for browsers. It maps JSON objects to DOM elements with zero configuration.", |
Sorry, the diff of this file is not supported yet
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
4127274
15173