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

transparency

Package Overview
Dependencies
Maintainers
1
Versions
50
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

transparency - npm Package Compare versions

Comparing version 0.3.3 to 0.4.0

browser/lib/jasmine-1.1.0/jasmine_favicon.png

253

lib/jquery.transparency.js
(function() {
var matchingElements, renderChildren, renderDirectives, renderForms, renderNode, renderSimple, renderValues;
var ELEMENT_NODE, Transparency, elementMatcher, matchingElements, prepareContext, renderChildren, renderDirectives, renderValues, setText;
jQuery.fn.render = function(data, directives, parentKey) {
var context, contexts, object, template, _i, _j, _len, _len2;
contexts = this;
if (!(data instanceof Array)) data = [data];
jQuery.fn.render = function(objects, directives) {
Transparency.render(this.get(), objects, directives);
return this;
};
Transparency = this.Transparency = {};
Transparency.render = function(contexts, objects, directives) {
var c, context, fragment, i, isArray, n, object, parent, sibling, _i, _j, _len, _len2, _len3, _ref;
contexts = contexts.length != null ? (function() {
var _i, _len, _results;
_results = [];
for (_i = 0, _len = contexts.length; _i < _len; _i++) {
c = contexts[_i];
_results.push(c);
}
return _results;
})() : [contexts];
isArray = objects instanceof Array;
if (!(objects instanceof Array)) objects = [objects];
directives || (directives = {});
for (_i = 0, _len = contexts.length; _i < _len; _i++) {
context = contexts[_i];
context = jQuery(context);
if (!context.data('template')) context.data('template', context.clone());
context.empty();
for (_j = 0, _len2 = data.length; _j < _len2; _j++) {
object = data[_j];
template = context.data('template').clone();
renderSimple(template, object);
renderValues(template, object);
renderForms(template, object, parentKey);
renderDirectives(template, object, directives);
renderChildren(template, object, directives);
context.append(template.children());
sibling = context.nextSibling;
parent = context.parentNode;
if (parent != null) parent.removeChild(context);
prepareContext(context, objects);
for (i = 0, _len2 = objects.length; i < _len2; i++) {
object = objects[i];
fragment = context.transparency.fragment;
_ref = context.transparency.instances[i];
for (_j = 0, _len3 = _ref.length; _j < _len3; _j++) {
n = _ref[_j];
fragment.appendChild(n);
if (isArray && n.nodeType === ELEMENT_NODE) {
n.transparency || (n.transparency = {});
n.transparency.model = object;
}
}
renderValues(fragment, object);
renderDirectives(fragment, object, directives);
renderChildren(fragment, object, directives);
while (n = context.transparency.fragment.firstChild) {
context.appendChild(n);
}
}
if (sibling) {
if (parent != null) parent.insertBefore(context, sibling);
} else {
if (parent != null) parent.appendChild(context);
}
}

@@ -28,52 +59,41 @@ return contexts;

renderSimple = function(template, object) {
var node;
if (typeof object !== 'object') {
node = template.find(".listElement").get(0) || template.children().get(0);
return renderNode(node, object);
}
};
renderValues = function(template, object) {
var e, key, value, _results;
_results = [];
for (key in object) {
value = object[key];
if (typeof value !== 'object') {
_results.push((function() {
var _i, _len, _ref, _results2;
_ref = matchingElements(template, key);
_results2 = [];
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
e = _ref[_i];
_results2.push(renderNode(e, value));
}
return _results2;
})());
prepareContext = function(context, objects) {
var n, template, _base, _base2, _base3, _base4, _results;
context.transparency || (context.transparency = {});
(_base = context.transparency).template || (_base.template = ((function() {
var _results;
_results = [];
while (context.firstChild) {
_results.push(context.removeChild(context.firstChild));
}
return _results;
})()));
(_base2 = context.transparency).templateCache || (_base2.templateCache = []);
(_base3 = context.transparency).instances || (_base3.instances = []);
(_base4 = context.transparency).fragment || (_base4.fragment = context.ownerDocument.createElement('div'));
while (objects.length > context.transparency.instances.length) {
template = context.transparency.templateCache.pop() || ((function() {
var _i, _len, _ref, _results;
_ref = context.transparency.template;
_results = [];
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
n = _ref[_i];
_results.push(n.cloneNode(true));
}
return _results;
})());
context.transparency.instances.push(template);
}
return _results;
};
renderForms = function(template, object, parentKey) {
var inputName, key, node, value, _results;
if (!parentKey) return;
_results = [];
for (key in object) {
value = object[key];
if (!(typeof value !== 'object')) continue;
inputName = "" + parentKey + "\\[" + key + "\\]";
if (template.is('input') && template.attr('name') === inputName && template.attr('type') === 'text') {
renderNode(template, value, 'value');
}
_results.push((function() {
while (objects.length < context.transparency.instances.length) {
_results.push(context.transparency.templateCache.push((function() {
var _i, _len, _ref, _results2;
_ref = template.find("input[name=" + inputName + "]");
_ref = context.transparency.instances.pop();
_results2 = [];
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
node = _ref[_i];
_results2.push(renderNode(node, value, 'value'));
n = _ref[_i];
_results2.push(context.removeChild(n));
}
return _results2;
})());
})()));
}

@@ -83,4 +103,30 @@ return _results;

renderValues = function(template, object) {
var e, element, k, v, _results;
if (typeof object === 'object') {
_results = [];
for (k in object) {
v = object[k];
if (typeof v !== 'object') {
_results.push((function() {
var _i, _len, _ref, _results2;
_ref = matchingElements(template, k);
_results2 = [];
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
e = _ref[_i];
_results2.push(setText(e, v));
}
return _results2;
})());
}
}
return _results;
} else {
element = matchingElements(template, 'listElement')[0] || template.getElementsByTagName('*')[0];
if (element) return setText(element, object);
}
};
renderDirectives = function(template, object, directives) {
var attribute, directive, key, node, _ref, _results;
var attr, directive, e, key, v, _ref, _results;
_results = [];

@@ -90,3 +136,3 @@ for (key in directives) {

if (!(typeof directive === 'function')) continue;
_ref = key.split('@'), key = _ref[0], attribute = _ref[1];
_ref = key.split('@'), key = _ref[0], attr = _ref[1];
_results.push((function() {

@@ -97,4 +143,9 @@ var _i, _len, _ref2, _results2;

for (_i = 0, _len = _ref2.length; _i < _len; _i++) {
node = _ref2[_i];
_results2.push(renderNode(node, directive.call(object, node), attribute));
e = _ref2[_i];
v = directive.call(object, e);
if (attr) {
_results2.push(e.setAttribute(attr, v));
} else {
_results2.push(setText(e, v));
}
}

@@ -108,8 +159,8 @@ return _results2;

renderChildren = function(template, object, directives) {
var key, value, _results;
var k, v, _results;
_results = [];
for (key in object) {
value = object[key];
if (typeof value === 'object') {
_results.push(matchingElements(template, key).render(value, directives[key], key));
for (k in object) {
v = object[k];
if (typeof v === 'object') {
_results.push(Transparency.render(matchingElements(template, k), v, directives[k]));
}

@@ -120,29 +171,53 @@ }

renderNode = function(element, value, attribute) {
var n, t, _i, _len, _ref;
if (attribute) {
return element.setAttribute(attribute, value);
} else {
_ref = (function() {
var _j, _len, _ref, _results;
_ref = element.childNodes;
_results = [];
for (_j = 0, _len = _ref.length; _j < _len; _j++) {
n = _ref[_j];
if (n.nodeType === 3) _results.push(n);
}
return _results;
})();
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
t = _ref[_i];
element.removeChild(t);
}
return element.insertBefore(document.createTextNode(value), element.firstChild);
setText = function(e, text) {
var c, children, textNode, _i, _len, _ref, _results;
if ((e != null ? (_ref = e.transparency) != null ? _ref.text : void 0 : void 0) === text) {
return;
}
e.transparency || (e.transparency = {});
e.transparency.text = text;
textNode = e.ownerDocument.createTextNode(text);
children = filter((function(n) {
return n.nodeType === ELEMENT_NODE;
}), e.childNodes);
while (e.firstChild) {
e.removeChild(e.firstChild);
}
e.appendChild(textNode);
_results = [];
for (_i = 0, _len = children.length; _i < _len; _i++) {
c = children[_i];
_results.push(e.appendChild(c));
}
return _results;
};
matchingElements = function(template, key) {
return template.find("#" + key + ", " + key + ", ." + key + ", [data-bind='" + key + "']");
var firstChild, _base, _base2;
if (!(firstChild = template.firstChild)) return [];
firstChild.transparency || (firstChild.transparency = {});
(_base = firstChild.transparency).queryCache || (_base.queryCache = {});
return (_base2 = firstChild.transparency.queryCache)[key] || (_base2[key] = template.querySelectorAll ? template.querySelectorAll("#" + key + ", " + key + ", ." + key + ", [data-bind='" + key + "']") : filter(elementMatcher(key), template.getElementsByTagName('*')));
};
elementMatcher = function(key) {
return function(element) {
return element.className.indexOf(key) > -1 || element.id === key || element.tagName.toLowerCase() === key.toLowerCase() || element.getAttribute('data-bind') === key;
};
};
ELEMENT_NODE = 1;
if (typeof filter === "undefined" || filter === null) {
filter = function(p, xs) {
var x, _i, _len, _results;
_results = [];
for (_i = 0, _len = xs.length; _i < _len; _i++) {
x = xs[_i];
if (p(x)) _results.push(x);
}
return _results;
};
}
}).call(this);

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

((function(){var a,b,c,d,e,f,g;jQuery.fn.render=function(a,e,h){var i,j,k,l,m,n,o,p;j=this,a instanceof Array||(a=[a]),e||(e={});for(m=0,o=j.length;m<o;m++){i=j[m],i=jQuery(i),i.data("template")||i.data("template",i.clone()),i.empty();for(n=0,p=a.length;n<p;n++)k=a[n],l=i.data("template").clone(),f(l,k),g(l,k),d(l,k,h),c(l,k,e),b(l,k,e),i.append(l.children())}return j},f=function(a,b){var c;if(typeof b!="object")return c=a.find(".listElement").get(0)||a.children().get(0),e(c,b)},g=function(b,c){var d,f,g,h;h=[];for(f in c)g=c[f],typeof g!="object"&&h.push(function(){var c,h,i,j;i=a(b,f),j=[];for(c=0,h=i.length;c<h;c++)d=i[c],j.push(e(d,g));return j}());return h},d=function(a,b,c){var d,f,g,h,i;if(!c)return;i=[];for(f in b){h=b[f];if(typeof h=="object")continue;d=""+c+"\\["+f+"\\]",a.is("input")&&a.attr("name")===d&&a.attr("type")==="text"&&e(a,h,"value"),i.push(function(){var b,c,f,i;f=a.find("input[name="+d+"]"),i=[];for(b=0,c=f.length;b<c;b++)g=f[b],i.push(e(g,h,"value"));return i}())}return i},c=function(b,c,d){var f,g,h,i,j,k;k=[];for(h in d){g=d[h];if(typeof g!="function")continue;j=h.split("@"),h=j[0],f=j[1],k.push(function(){var d,j,k,l;k=a(b,h),l=[];for(d=0,j=k.length;d<j;d++)i=k[d],l.push(e(i,g.call(c,i),f));return l}())}return k},b=function(b,c,d){var e,f,g;g=[];for(e in c)f=c[e],typeof f=="object"&&g.push(a(b,e).render(f,d[e],e));return g},e=function(a,b,c){var d,e,f,g,h;if(c)return a.setAttribute(c,b);h=function(){var b,c,e,f;e=a.childNodes,f=[];for(b=0,c=e.length;b<c;b++)d=e[b],d.nodeType===3&&f.push(d);return f}();for(f=0,g=h.length;f<g;f++)e=h[f],a.removeChild(e);return a.insertBefore(document.createTextNode(b),a.firstChild)},a=function(a,b){return a.find("#"+b+", "+b+", ."+b+", [data-bind='"+b+"']")}})).call(this);
((function(){var a,b,c,d,e,f,g,h,i;jQuery.fn.render=function(a,c){return b.render(this.get(),a,c),this},b=this.Transparency={},b.render=function(b,c,d){var i,j,k,l,m,n,o,p,q,r,s,t,u,v,w;b=b.length!=null?function(){var a,c,d;d=[];for(a=0,c=b.length;a<c;a++)i=b[a],d.push(i);return d}():[b],m=c instanceof Array,c instanceof Array||(c=[c]),d||(d={});for(r=0,t=b.length;r<t;r++){j=b[r],q=j.nextSibling,p=j.parentNode,p!=null&&p.removeChild(j),e(j,c);for(l=0,u=c.length;l<u;l++){o=c[l],k=j.transparency.fragment,w=j.transparency.instances[l];for(s=0,v=w.length;s<v;s++)n=w[s],k.appendChild(n),m&&n.nodeType===a&&(n.transparency||(n.transparency={}),n.transparency.model=o);h(k,o),g(k,o,d),f(k,o,d);while(n=j.transparency.fragment.firstChild)j.appendChild(n)}q?p!=null&&p.insertBefore(j,q):p!=null&&p.appendChild(j)}return b},e=function(a,b){var c,d,e,f,g,h,i;a.transparency||(a.transparency={}),(e=a.transparency).template||(e.template=function(){var b;b=[];while(a.firstChild)b.push(a.removeChild(a.firstChild));return b}()),(f=a.transparency).templateCache||(f.templateCache=[]),(g=a.transparency).instances||(g.instances=[]),(h=a.transparency).fragment||(h.fragment=a.ownerDocument.createElement("div"));while(b.length>a.transparency.instances.length)d=a.transparency.templateCache.pop()||function(){var b,d,e,f;e=a.transparency.template,f=[];for(b=0,d=e.length;b<d;b++)c=e[b],f.push(c.cloneNode(!0));return f}(),a.transparency.instances.push(d);i=[];while(b.length<a.transparency.instances.length)i.push(a.transparency.templateCache.push(function(){var b,d,e,f;e=a.transparency.instances.pop(),f=[];for(b=0,d=e.length;b<d;b++)c=e[b],f.push(a.removeChild(c));return f}()));return i},h=function(a,b){var c,e,f,g,h;if(typeof b=="object"){h=[];for(f in b)g=b[f],typeof g!="object"&&h.push(function(){var b,e,h,j;h=d(a,f),j=[];for(b=0,e=h.length;b<e;b++)c=h[b],j.push(i(c,g));return j}());return h}e=d(a,"listElement")[0]||a.getElementsByTagName("*")[0];if(e)return i(e,b)},g=function(a,b,c){var e,f,g,h,j,k,l;l=[];for(h in c){f=c[h];if(typeof f!="function")continue;k=h.split("@"),h=k[0],e=k[1],l.push(function(){var c,k,l,m;l=d(a,h),m=[];for(c=0,k=l.length;c<k;c++)g=l[c],j=f.call(b,g),e?m.push(g.setAttribute(e,j)):m.push(i(g,j));return m}())}return l},f=function(a,c,e){var f,g,h;h=[];for(f in c)g=c[f],typeof g=="object"&&h.push(b.render(d(a,f),g,e[f]));return h},i=function(b,c){var d,e,f,g,h,i,j;if((b!=null?(i=b.transparency)!=null?i.text:void 0:void 0)===c)return;b.transparency||(b.transparency={}),b.transparency.text=c,f=b.ownerDocument.createTextNode(c),e=filter(function(b){return b.nodeType===a},b.childNodes);while(b.firstChild)b.removeChild(b.firstChild);b.appendChild(f),j=[];for(g=0,h=e.length;g<h;g++)d=e[g],j.push(b.appendChild(d));return j},d=function(a,b){var d,e,f;return(d=a.firstChild)?(d.transparency||(d.transparency={}),(e=d.transparency).queryCache||(e.queryCache={}),(f=d.transparency.queryCache)[b]||(f[b]=a.querySelectorAll?a.querySelectorAll("#"+b+", "+b+", ."+b+", [data-bind='"+b+"']"):filter(c(b),a.getElementsByTagName("*")))):[]},c=function(a){return function(b){return b.className.indexOf(a)>-1||b.id===a||b.tagName.toLowerCase()===a.toLowerCase()||b.getAttribute("data-bind")===a}},a=1;if(typeof filter=="undefined"||filter===null)filter=function(a,b){var c,d,e,f;f=[];for(d=0,e=b.length;d<e;d++)c=b[d],a(c)&&f.push(c);return f}})).call(this);
{
"name" : "transparency",
"version" : "0.3.3",
"version" : "0.4.0",
"description" : "Transparency is a minimal template engine for jQuery. It maps JSON objects to DOM elements with zero configuration.",

@@ -5,0 +5,0 @@ "homepage" : "https://github.com/leonidas/transparency",

@@ -11,2 +11,4 @@ Transparency is a minimal template engine for jQuery. It maps JSON objects to DOM elements with zero configuration.

For more insight please see (FAQ)[https://github.com/leonidas/transparency/blob/master/FAQ.md]
## Usage

@@ -60,3 +62,3 @@

Values are escaped before binding.
Values are escaped before rendering.

@@ -78,8 +80,6 @@ Template:

var hello = {
hello: 'Hello',
goodbye: 'Goodbye!',
span: '<i>See Ya!</i>',
// Finnish i18n
'hi-label': 'Terve!'
hello: 'Hello',
goodbye: 'Goodbye!',
span: '<i>See Ya!</i>',
'hi-label': 'Terve!' // Finnish i18n
};

@@ -97,3 +97,3 @@

<span>lt;i&gt;See Ya!&lt;/i&gt;</span>
<button class="hi-button" data-bind="hi-label"></button>
<button class="hi-button" data-bind="hi-label">Terve!</button>
</div>

@@ -487,1 +487,2 @@ ```

Just call `$('.container').render(data)` and move on.

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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