Socket
Socket
Sign inDemoInstall

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.9.1 to 0.9.2

AmdSpecRunner.html

2

component.json
{
"name": "transparency",
"version": "0.9.1",
"version": "0.9.2",
"main": "./dist/transparency.js"
}

@@ -0,3 +1,11 @@

/*!
* transparency - v0.9.1 - 2013-02-21
* https://github.com/leonidas/transparency
* Copyright (c) 2013 Jarno Keskikangas <jarno.keskikangas@leonidasoy.fi>; Licensed MIT
*/
(function() {
var Context, ELEMENT_NODE, Element, ElementFactory, Input, Instance, Select, TEXT_NODE, Transparency, VoidElement, chainable, cloneNode, consoleLogger, data, expando, getChildNodes, getElements, html5Clone, isArray, isBoolean, isDate, isDomElement, isPlainValue, log, nullLogger, toString, _getElements, _ref,
var Attribute, AttributeFactory, BooleanAttribute, Checkbox, Class, Context, ELEMENT_NODE, Element, ElementFactory, Html, Input, Instance, Radio, Select, TEXT_NODE, Text, Transparency, VoidElement, after, before, chainable, cloneNode, consoleLogger, data, expando, getChildNodes, getElements, html5Clone, isArray, isBoolean, isDate, isDomElement, isPlainValue, log, nullLogger, toString, _getElements, _ref,
__indexOf = [].indexOf || function(item) { for (var i = 0, l = this.length; i < l; i++) { if (i in this && this[i] === item) return i; } return -1; },

@@ -7,6 +15,122 @@ __hasProp = {}.hasOwnProperty,

before = function(decorator) {
return function(method) {
return function() {
decorator.apply(this, arguments);
return method.apply(this, arguments);
};
};
};
after = function(decorator) {
return function(method) {
return function() {
method.apply(this, arguments);
return decorator.apply(this, arguments);
};
};
};
chainable = after(function() {
return this;
});
getChildNodes = function(el) {
var child, childNodes;
childNodes = [];
child = el.firstChild;
while (child) {
childNodes.push(child);
child = child.nextSibling;
}
return childNodes;
};
getElements = function(el) {
var elements;
elements = [];
_getElements(el, elements);
return elements;
};
_getElements = function(template, elements) {
var child, _results;
child = template.firstChild;
_results = [];
while (child) {
if (child.nodeType === ELEMENT_NODE) {
elements.push(new ElementFactory.createElement(child));
_getElements(child, elements);
}
_results.push(child = child.nextSibling);
}
return _results;
};
ELEMENT_NODE = 1;
TEXT_NODE = 3;
html5Clone = function() {
return document.createElement('nav').cloneNode(true).outerHTML !== '<:nav></:nav>';
};
cloneNode = !(typeof document !== "undefined" && document !== null) || html5Clone() ? function(node) {
return node.cloneNode(true);
} : function(node) {
var cloned, element, _i, _len, _ref;
cloned = Transparency.clone(node);
if (cloned.nodeType === ELEMENT_NODE) {
cloned.removeAttribute(expando);
_ref = cloned.getElementsByTagName('*');
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
element = _ref[_i];
element.removeAttribute(expando);
}
}
return cloned;
};
expando = 'transparency';
data = function(element) {
return element[expando] || (element[expando] = {});
};
nullLogger = function() {};
consoleLogger = function() {
return console.log(arguments);
};
log = nullLogger;
toString = Object.prototype.toString;
isArray = Array.isArray || function(obj) {
return toString.call(obj) === '[object Array]';
};
isDate = function(obj) {
return toString.call(obj) === '[object Date]';
};
isDomElement = function(obj) {
return obj.nodeType === ELEMENT_NODE;
};
isPlainValue = function(obj) {
var type;
type = typeof obj;
return (type !== 'object' && type !== 'function') || isDate(obj);
};
isBoolean = function(obj) {
return obj === true || obj === false;
};
Transparency = this.Transparency = {};
Transparency.render = function(context, models, directives, options) {
var log, _base;
var _base;
if (models == null) {

@@ -30,13 +154,14 @@ models = [];

context = (_base = data(context)).context || (_base.context = new Context(context));
return context.detach().render(models, directives, options).attach().el;
return context.render(models, directives, options).el;
};
Transparency.jQueryPlugin = function(models, directives, options) {
var context, _i, _len;
Transparency.jQueryPlugin = chainable(function(models, directives, options) {
var context, _i, _len, _results;
_results = [];
for (_i = 0, _len = this.length; _i < _len; _i++) {
context = this[_i];
Transparency.render(context, models, directives, options);
_results.push(Transparency.render(context, models, directives, options));
}
return this;
};
return _results;
});

@@ -52,19 +177,16 @@ Transparency.matcher = function(element, key) {

chainable = function(method) {
return function() {
method.apply(this, arguments);
return this;
};
};
if ((_ref = jQuery || Zepto) != null) {
_ref.fn.render = Transparency.jQueryPlugin;
}
if (typeof define !== "undefined" && define !== null ? define.amd : void 0) {
define(function() {
return Transparency;
});
}
Context = (function() {
var attach, detach;
function Context(el) {
this.el = el;
this.template = cloneNode(this.el);
this.instances = [new Instance(this.el)];
this.instanceCache = [];
}
Context.prototype.detach = chainable(function() {
detach = chainable(function() {
this.parent = this.el.parentNode;

@@ -77,3 +199,3 @@ if (this.parent) {

Context.prototype.attach = chainable(function() {
attach = chainable(function() {
if (this.parent) {

@@ -88,3 +210,10 @@ if (this.nextSibling) {

Context.prototype.render = chainable(function(models, directives, options) {
function Context(el) {
this.el = el;
this.template = cloneNode(this.el);
this.instances = [new Instance(this.el)];
this.instanceCache = [];
}
Context.prototype.render = before(detach)(after(attach)(chainable(function(models, directives, options) {
var children, index, instance, model, _i, _len, _results;

@@ -105,3 +234,3 @@ while (models.length < this.instances.length) {

return _results;
});
})));

@@ -121,7 +250,7 @@ return Context;

Instance.prototype.remove = chainable(function() {
var node, _i, _len, _ref, _results;
_ref = this.childNodes;
var node, _i, _len, _ref1, _results;
_ref1 = this.childNodes;
_results = [];
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
node = _ref[_i];
for (_i = 0, _len = _ref1.length; _i < _len; _i++) {
node = _ref1[_i];
_results.push(node.parentNode.removeChild(node));

@@ -133,7 +262,7 @@ }

Instance.prototype.appendTo = chainable(function(parent) {
var node, _i, _len, _ref, _results;
_ref = this.childNodes;
var node, _i, _len, _ref1, _results;
_ref1 = this.childNodes;
_results = [];
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
node = _ref[_i];
for (_i = 0, _len = _ref1.length; _i < _len; _i++) {
node = _ref1[_i];
_results.push(parent.appendChild(node));

@@ -145,7 +274,7 @@ }

Instance.prototype.prepare = chainable(function(model) {
var element, _i, _len, _ref, _results;
_ref = this.elements;
var element, _i, _len, _ref1, _results;
_ref1 = this.elements;
_results = [];
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
element = _ref[_i];
for (_i = 0, _len = _ref1.length; _i < _len; _i++) {
element = _ref1[_i];
element.reset();

@@ -169,7 +298,7 @@ _results.push(data(element.el).model = model);

_results.push((function() {
var _i, _len, _ref, _results1;
_ref = this.matchingElements(key);
var _i, _len, _ref1, _results1;
_ref1 = this.matchingElements(key);
_results1 = [];
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
element = _ref[_i];
for (_i = 0, _len = _ref1.length; _i < _len; _i++) {
element = _ref1[_i];
_results1.push(element.render(value));

@@ -191,3 +320,3 @@ }

Instance.prototype.renderDirectives = chainable(function(model, index, directives) {
var attribute, attributes, directive, element, key, value, _results;
var attributes, element, key, _results;
_results = [];

@@ -197,35 +326,20 @@ for (key in directives) {

attributes = directives[key];
if (typeof attributes === 'object') {
_results.push((function() {
var _i, _len, _ref, _results1;
_ref = this.matchingElements(key);
_results1 = [];
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
element = _ref[_i];
_results1.push((function() {
var _results2;
_results2 = [];
for (attribute in attributes) {
if (!__hasProp.call(attributes, attribute)) continue;
directive = attributes[attribute];
if (!(typeof directive === 'function')) {
continue;
}
value = directive.call(model, {
element: element.el,
index: index,
value: element.originalAttributes[attribute]
});
if (value != null) {
_results2.push(element.attr(attribute, value));
} else {
_results2.push(void 0);
}
}
return _results2;
})());
}
return _results1;
}).call(this));
if (!(typeof attributes === 'object')) {
continue;
}
if (typeof model !== 'object') {
model = {
value: model
};
}
_results.push((function() {
var _i, _len, _ref1, _results1;
_ref1 = this.matchingElements(key);
_results1 = [];
for (_i = 0, _len = _ref1.length; _i < _len; _i++) {
element = _ref1[_i];
_results1.push(element.renderDirectives(model, index, attributes));
}
return _results1;
}).call(this));
}

@@ -241,7 +355,7 @@ return _results;

_results.push((function() {
var _j, _len1, _ref, _results1;
_ref = this.matchingElements(key);
var _j, _len1, _ref1, _results1;
_ref1 = this.matchingElements(key);
_results1 = [];
for (_j = 0, _len1 = _ref.length; _j < _len1; _j++) {
element = _ref[_j];
for (_j = 0, _len1 = _ref1.length; _j < _len1; _j++) {
element = _ref1[_j];
_results1.push(Transparency.render(element.el, model[key], directives[key], options));

@@ -258,7 +372,7 @@ }

elements = (_base = this.queryCache)[key] || (_base[key] = (function() {
var _i, _len, _ref, _results;
_ref = this.elements;
var _i, _len, _ref1, _results;
_ref1 = this.elements;
_results = [];
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
el = _ref[_i];
for (_i = 0, _len = _ref1.length; _i < _len; _i++) {
el = _ref1[_i];
if (Transparency.matcher(el, key)) {

@@ -278,2 +392,144 @@ _results.push(el);

AttributeFactory = {
Attributes: {},
createAttribute: function(element, name, value) {
var Attr;
Attr = AttributeFactory.Attributes[name] || (isBoolean(value) ? BooleanAttribute : Attribute);
return new Attr(element, name);
}
};
Attribute = (function() {
function Attribute(el, name) {
this.el = el;
this.name = name;
this.templateValue = this.el.getAttribute(this.name) || '';
}
Attribute.prototype.set = function(value) {
this.el[this.name] = value;
return this.el.setAttribute(this.name, value.toString());
};
return Attribute;
})();
BooleanAttribute = (function(_super) {
__extends(BooleanAttribute, _super);
function BooleanAttribute(el, name) {
this.el = el;
this.name = name;
this.templateValue = this.el.getAttribute(this.name) || false;
}
BooleanAttribute.prototype.set = function(value) {
this.el[this.name] = value;
if (value) {
return this.el.setAttribute(this.name, this.name);
} else {
return this.el.removeAttribute(this.name);
}
};
return BooleanAttribute;
})(Attribute);
Text = (function(_super) {
__extends(Text, _super);
AttributeFactory.Attributes['text'] = Text;
function Text(el, name) {
var child;
this.el = el;
this.name = name;
this.templateValue = ((function() {
var _i, _len, _ref1, _results;
_ref1 = getChildNodes(this.el);
_results = [];
for (_i = 0, _len = _ref1.length; _i < _len; _i++) {
child = _ref1[_i];
if (child.nodeType === TEXT_NODE) {
_results.push(child.nodeValue);
}
}
return _results;
}).call(this)).join('');
if (!(this.textNode = this.el.firstChild)) {
this.el.appendChild(this.textNode = this.el.ownerDocument.createTextNode(''));
} else if (this.textNode.nodeType !== TEXT_NODE) {
this.textNode = this.el.insertBefore(this.el.ownerDocument.createTextNode(''), this.textNode);
}
}
Text.prototype.set = function(text) {
return this.textNode.nodeValue = text;
};
return Text;
})(Attribute);
Html = (function(_super) {
__extends(Html, _super);
AttributeFactory.Attributes['html'] = Html;
function Html(el) {
Html.__super__.constructor.call(this, el, 'innerHTML');
this.childNodes = getChildNodes(this.el);
}
Html.prototype.set = function(html) {
var child, _i, _len, _ref1, _results;
this.el.innerHTML = html;
_ref1 = this.childNodes;
_results = [];
for (_i = 0, _len = _ref1.length; _i < _len; _i++) {
child = _ref1[_i];
_results.push(this.el.appendChild(child));
}
return _results;
};
return Html;
})(Attribute);
Class = (function(_super) {
__extends(Class, _super);
AttributeFactory.Attributes['class'] = Class;
function Class(el) {
Class.__super__.constructor.call(this, el, 'class');
}
return Class;
})(Attribute);
ElementFactory = {
Elements: {
input: {}
},
createElement: function(el) {
var El, name;
if ('input' === (name = el.nodeName.toLowerCase())) {
El = ElementFactory.Elements[name][el.type.toLowerCase()] || Input;
} else {
El = ElementFactory.Elements[name] ||  Element;
}
return new El(el);
}
};
Element = (function() {

@@ -283,2 +539,3 @@

this.el = el;
this.attributes = {};
this.childNodes = getChildNodes(this.el);

@@ -290,17 +547,18 @@ this.nodeName = this.el.nodeName.toLowerCase();

Element.prototype.empty = function() {
var child;
Element.prototype.empty = chainable(function() {
var child, _results;
_results = [];
while (child = this.el.firstChild) {
this.el.removeChild(child);
_results.push(this.el.removeChild(child));
}
return this;
};
return _results;
});
Element.prototype.reset = function() {
var attribute, value, _ref, _results;
_ref = this.originalAttributes;
var attribute, name, _ref1, _results;
_ref1 = this.attributes;
_results = [];
for (attribute in _ref) {
value = _ref[attribute];
_results.push(this.attr(attribute, value));
for (name in _ref1) {
attribute = _ref1[name];
_results.push(attribute.set(attribute.templateValue));
}

@@ -314,79 +572,29 @@ return _results;

Element.prototype.setHtml = function(html) {
var child, _i, _len, _ref, _results;
this.empty();
this.el.innerHTML = html;
_ref = this.childNodes;
_results = [];
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
child = _ref[_i];
_results.push(this.el.appendChild(child));
}
return _results;
Element.prototype.attr = function(name, value) {
var attribute, _base;
attribute = (_base = this.attributes)[name] || (_base[name] = AttributeFactory.createAttribute(this.el, name, value));
return attribute.set(value);
};
Element.prototype.setText = function(text) {
var textNode;
textNode = this.el.firstChild;
if (!textNode) {
return this.el.appendChild(this.el.ownerDocument.createTextNode(text));
} else if (textNode.nodeType !== TEXT_NODE) {
return this.el.insertBefore(this.el.ownerDocument.createTextNode(text), textNode);
} else {
return textNode.nodeValue = text;
}
};
Element.prototype.getText = function() {
var child;
return ((function() {
var _i, _len, _ref, _results;
_ref = this.childNodes;
_results = [];
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
child = _ref[_i];
if (child.nodeType === TEXT_NODE) {
_results.push(child.nodeValue);
}
Element.prototype.renderDirectives = function(model, index, attributes) {
var directive, name, value, _ref1, _results;
_results = [];
for (name in attributes) {
if (!__hasProp.call(attributes, name)) continue;
directive = attributes[name];
if (!(typeof directive === 'function')) {
continue;
}
return _results;
}).call(this)).join('');
};
Element.prototype.attr = function(attribute, value) {
var _base, _base1, _base2, _base3, _base4, _ref, _ref1, _ref2, _ref3, _ref4;
switch (attribute) {
case 'text':
if ((_ref = (_base = this.originalAttributes)['text']) == null) {
_base['text'] = this.getText();
}
return this.setText(value);
case 'html':
if ((_ref1 = (_base1 = this.originalAttributes)['html']) == null) {
_base1['html'] = this.el.innerHTML;
}
return this.setHtml(value);
case 'class':
if ((_ref2 = (_base2 = this.originalAttributes)['class']) == null) {
_base2['class'] = this.el.className;
}
return this.el.className = value;
default:
this.el[attribute] = value;
if (isBoolean(value)) {
if ((_ref3 = (_base3 = this.originalAttributes)[attribute]) == null) {
_base3[attribute] = this.el.getAttribute(attribute) || false;
}
if (value) {
return this.el.setAttribute(attribute, attribute);
} else {
return this.el.removeAttribute(attribute);
}
} else {
if ((_ref4 = (_base4 = this.originalAttributes)[attribute]) == null) {
_base4[attribute] = this.el.getAttribute(attribute) || "";
}
return this.el.setAttribute(attribute, value.toString());
}
value = directive.call(model, {
element: this.el,
index: index,
value: ((_ref1 = this.attributes[name]) != null ? _ref1.templateValue : void 0) || ''
});
if (value != null) {
_results.push(this.attr(name, value));
} else {
_results.push(void 0);
}
}
return _results;
};

@@ -398,11 +606,2 @@

ElementFactory = {
elements: {},
createElement: function(el) {
var Klass;
Klass = ElementFactory.elements[el.nodeName.toLowerCase()] || Element;
return new Klass(el);
}
};
Select = (function(_super) {

@@ -412,17 +611,18 @@

function Select() {
return Select.__super__.constructor.apply(this, arguments);
ElementFactory.Elements['select'] = Select;
function Select(el) {
Select.__super__.constructor.call(this, el);
this.elements = getElements(el);
}
ElementFactory.elements.select = Select;
Select.prototype.render = function(value) {
var child, _i, _len, _ref, _results;
var option, _i, _len, _ref1, _results;
value = value.toString();
_ref = getElements(this.el);
_ref1 = this.elements;
_results = [];
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
child = _ref[_i];
if (child.nodeName === 'option') {
_results.push(child.el.selected = child.el.value === value);
for (_i = 0, _len = _ref1.length; _i < _len; _i++) {
option = _ref1[_i];
if (option.nodeName === 'option') {
_results.push(option.attr('selected', option.el.value === value));
}

@@ -450,6 +650,10 @@ }

nodeName = VOID_ELEMENTS[_i];
ElementFactory.elements[nodeName] = VoidElement;
ElementFactory.Elements[nodeName] = VoidElement;
}
VoidElement.prototype.setText = function() {};
VoidElement.prototype.attr = function(name, value) {
if (name !== 'text' && name !== 'html') {
return VoidElement.__super__.attr.call(this, name, value);
}
};

@@ -468,4 +672,2 @@ return VoidElement;

ElementFactory.elements.input = Input;
Input.prototype.render = function(value) {

@@ -479,106 +681,34 @@ return this.attr('value', value);

getChildNodes = function(el) {
var child, childNodes;
childNodes = [];
child = el.firstChild;
while (child) {
childNodes.push(child);
child = child.nextSibling;
}
return childNodes;
};
Checkbox = (function(_super) {
getElements = function(el) {
var elements;
elements = [];
_getElements(el, elements);
return elements;
};
__extends(Checkbox, _super);
_getElements = function(template, elements) {
var child, _results;
child = template.firstChild;
_results = [];
while (child) {
if (child.nodeType === ELEMENT_NODE) {
elements.push(new ElementFactory.createElement(child));
_getElements(child, elements);
}
_results.push(child = child.nextSibling);
function Checkbox() {
return Checkbox.__super__.constructor.apply(this, arguments);
}
return _results;
};
ELEMENT_NODE = 1;
ElementFactory.Elements['input']['checkbox'] = Checkbox;
TEXT_NODE = 3;
Checkbox.prototype.render = function(value) {
return this.attr('checked', Boolean(value));
};
html5Clone = function() {
return document.createElement('nav').cloneNode(true).outerHTML !== '<:nav></:nav>';
};
return Checkbox;
cloneNode = !(typeof document !== "undefined" && document !== null) || html5Clone() ? function(node) {
return node.cloneNode(true);
} : function(node) {
var cloned, element, _i, _len, _ref;
cloned = Transparency.clone(node);
if (cloned.nodeType === ELEMENT_NODE) {
cloned.removeAttribute(expando);
_ref = cloned.getElementsByTagName('*');
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
element = _ref[_i];
element.removeAttribute(expando);
}
}
return cloned;
};
})(Input);
expando = 'transparency';
Radio = (function(_super) {
data = function(element) {
return element[expando] || (element[expando] = {});
};
__extends(Radio, _super);
nullLogger = function() {};
function Radio() {
return Radio.__super__.constructor.apply(this, arguments);
}
consoleLogger = function() {
return console.log(arguments);
};
ElementFactory.Elements['input']['radio'] = Radio;
log = nullLogger;
return Radio;
toString = Object.prototype.toString;
})(Checkbox);
isDate = function(obj) {
return toString.call(obj) === '[object Date]';
};
isDomElement = function(obj) {
return obj.nodeType === ELEMENT_NODE;
};
isPlainValue = function(obj) {
var type;
type = typeof obj;
return (type !== 'object' && type !== 'function') || isDate(obj);
};
isBoolean = function(obj) {
return obj === true || obj === false;
};
isArray = Array.isArray || function(obj) {
return toString.call(obj) === '[object Array]';
};
if ((_ref = jQuery || Zepto) != null) {
_ref.fn.render = Transparency.jQueryPlugin;
}
if (typeof define !== "undefined" && define !== null ? define.amd : void 0) {
define(function() {
return Transparency;
});
}
}).call(this);

@@ -1,4 +0,6 @@

/*! transparency - v0.9.0 - 2013-02-17
/*!
* transparency - v0.9.1 - 2013-02-21
* https://github.com/leonidas/transparency
* Copyright (c) 2013 Jarno Keskikangas <jarno.keskikangas@leonidasoy.fi>; Licensed MIT */
(function(){var e,t,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=[].indexOf||function(e){for(var t=0,n=this.length;t<n;t++)if(t in this&&this[t]===e)return t;return-1},A={}.hasOwnProperty,O=function(e,t){function r(){this.constructor=e}for(var n in t)A.call(t,n)&&(e[n]=t[n]);return r.prototype=t.prototype,e.prototype=new r,e.__super__=t.prototype,e};a=this.Transparency={},a.render=function(t,n,r,i){var s,o;n==null&&(n=[]),r==null&&(r={}),i==null&&(i={}),s=i.debug&&console?h:T,s("Transparency.render:",t,n,r,i);if(!t)return;return y(n)||(n=[n]),t=(o=p(t)).context||(o.context=new e(t)),t.detach().render(n,r,i).attach().el},a.jQueryPlugin=function(e,t,n){var r,i,s;for(i=0,s=this.length;i<s;i++)r=this[i],a.render(r,e,t,n);return this},a.matcher=function(e,t){return e.el.id===t||L.call(e.classNames,t)>=0||e.el.name===t||e.el.getAttribute("data-bind")===t},a.clone=function(e){var t;return typeof (t=jQuery||Zepto)=="function"?t(e).clone()[0]:void 0},l=function(e){return function(){return e.apply(this,arguments),this}},e=function(){function e(e){this.el=e,this.template=c(this.el),this.instances=[new s(this.el)],this.instanceCache=[]}return e.prototype.detach=l(function(){this.parent=this.el.parentNode;if(this.parent)return this.nextSibling=this.el.nextSibling,this.parent.removeChild(this.el)}),e.prototype.attach=l(function(){if(this.parent)return this.nextSibling?this.parent.insertBefore(this.el,this.nextSibling):this.parent.appendChild(this.el)}),e.prototype.render=l(function(e,t,n){var r,i,o,u,a,f,l;while(e.length<this.instances.length)this.instanceCache.push(this.instances.pop().remove());l=[];for(i=a=0,f=e.length;a<f;i=++a)u=e[i],(o=this.instances[i])||(o=this.instanceCache.pop()||new s(c(this.template)),this.instances.push(o.appendTo(this.el))),r=[],l.push(o.prepare(u,r).renderValues(u,r).renderDirectives(u,i,t).renderChildren(u,r,t,n));return l}),e}(),s=function(){function e(e){this.queryCache={},this.childNodes=v(e),this.elements=m(e)}return e.prototype.remove=l(function(){var e,t,n,r,i;r=this.childNodes,i=[];for(t=0,n=r.length;t<n;t++)e=r[t],i.push(e.parentNode.removeChild(e));return i}),e.prototype.appendTo=l(function(e){var t,n,r,i,s;i=this.childNodes,s=[];for(n=0,r=i.length;n<r;n++)t=i[n],s.push(e.appendChild(t));return s}),e.prototype.prepare=l(function(e){var t,n,r,i,s;i=this.elements,s=[];for(n=0,r=i.length;n<r;n++)t=i[n],t.reset(),s.push(p(t.el).model=e);return s}),e.prototype.renderValues=l(function(e,t){var n,r,i,s;if(E(e)&&(n=this.elements[0]))return n.empty().el.appendChild(e);if(typeof e=="object"){s=[];for(r in e){if(!A.call(e,r))continue;i=e[r],i!=null&&(S(i)?s.push(function(){var e,t,s,o;s=this.matchingElements(r),o=[];for(e=0,t=s.length;e<t;e++)n=s[e],o.push(n.render(i));return o}.call(this)):typeof i=="object"?s.push(t.push(r)):s.push(void 0))}return s}}),e.prototype.renderDirectives=l(function(e,t,n){var r,i,s,o,u,a,f;f=[];for(u in n){if(!A.call(n,u))continue;i=n[u],typeof i=="object"&&f.push(function(){var n,f,l,c;l=this.matchingElements(u),c=[];for(n=0,f=l.length;n<f;n++)o=l[n],c.push(function(){var n;n=[];for(r in i){if(!A.call(i,r))continue;s=i[r];if(typeof s!="function")continue;a=s.call(e,{element:o.el,index:t,value:o.originalAttributes[r]}),a!=null?n.push(o.attr(r,a)):n.push(void 0)}return n}());return c}.call(this))}return f}),e.prototype.renderChildren=l(function(e,t,n,r){var i,s,o,u,f;f=[];for(o=0,u=t.length;o<u;o++)s=t[o],f.push(function(){var t,o,u,f;u=this.matchingElements(s),f=[];for(t=0,o=u.length;t<o;t++)i=u[t],f.push(a.render(i.el,e[s],n[s],r));return f}.call(this));return f}),e.prototype.matchingElements=function(e){var t,n,r;return n=(r=this.queryCache)[e]||(r[e]=function(){var n,r,i,s;i=this.elements,s=[];for(n=0,r=i.length;n<r;n++)t=i[n],a.matcher(t,e)&&s.push(t);return s}.call(this)),x("Matching elements for '"+e+"':",n),n},e}(),n=function(){function e(e){this.el=e,this.childNodes=v(this.el),this.nodeName=this.el.nodeName.toLowerCase(),this.classNames=this.el.className.split(" "),this.originalAttributes={}}return e.prototype.empty=function(){var e;while(e=this.el.firstChild)this.el.removeChild(e);return this},e.prototype.reset=function(){var e,t,n,r;n=this.originalAttributes,r=[];for(e in n)t=n[e],r.push(this.attr(e,t));return r},e.prototype.render=function(e){return this.attr("text",e)},e.prototype.setHtml=function(e){var t,n,r,i,s;this.empty(),this.el.innerHTML=e,i=this.childNodes,s=[];for(n=0,r=i.length;n<r;n++)t=i[n],s.push(this.el.appendChild(t));return s},e.prototype.setText=function(e){var t;return t=this.el.firstChild,t?t.nodeType!==u?this.el.insertBefore(this.el.ownerDocument.createTextNode(e),t):t.nodeValue=e:this.el.appendChild(this.el.ownerDocument.createTextNode(e))},e.prototype.getText=function(){var e;return function(){var t,n,r,i;r=this.childNodes,i=[];for(t=0,n=r.length;t<n;t++)e=r[t],e.nodeType===u&&i.push(e.nodeValue);return i}.call(this).join("")},e.prototype.attr=function(e,t){var n,r,i,s,o,u,a,f,l,c;switch(e){case"text":return(u=(n=this.originalAttributes)["text"])==null&&(n.text=this.getText()),this.setText(t);case"html":return(a=(r=this.originalAttributes)["html"])==null&&(r.html=this.el.innerHTML),this.setHtml(t);case"class":return(f=(i=this.originalAttributes)["class"])==null&&(i["class"]=this.el.className),this.el.className=t;default:return this.el[e]=t,b(t)?((l=(s=this.originalAttributes)[e])==null&&(s[e]=this.el.getAttribute(e)||!1),t?this.el.setAttribute(e,e):this.el.removeAttribute(e)):((c=(o=this.originalAttributes)[e])==null&&(o[e]=this.el.getAttribute(e)||""),this.el.setAttribute(e,t.toString()))}},e}(),r={elements:{},createElement:function(e){var t;return t=r.elements[e.nodeName.toLowerCase()]||n,new t(e)}},o=function(e){function t(){return t.__super__.constructor.apply(this,arguments)}return O(t,e),r.elements.select=t,t.prototype.render=function(e){var t,n,r,i,s;e=e.toString(),i=m(this.el),s=[];for(n=0,r=i.length;n<r;n++)t=i[n],t.nodeName==="option"&&s.push(t.el.selected=t.el.value===e);return s},t}(n),f=function(e){function o(){return o.__super__.constructor.apply(this,arguments)}var t,n,i,s;O(o,e),t=["area","base","br","col","command","embed","hr","img","input","keygen","link","meta","param","source","track","wbr"];for(i=0,s=t.length;i<s;i++)n=t[i],r.elements[n]=o;return o.prototype.setText=function(){},o}(n),i=function(e){function t(){return t.__super__.constructor.apply(this,arguments)}return O(t,e),r.elements.input=t,t.prototype.render=function(e){return this.attr("value",e)},t}(f),v=function(e){var t,n;n=[],t=e.firstChild;while(t)n.push(t),t=t.nextSibling;return n},m=function(e){var t;return t=[],C(e,t),t},C=function(e,n){var i,s;i=e.firstChild,s=[];while(i)i.nodeType===t&&(n.push(new r.createElement(i)),C(i,n)),s.push(i=i.nextSibling);return s},t=1,u=3,g=function(){return document.createElement("nav").cloneNode(!0).outerHTML!=="<:nav></:nav>"},c=typeof document=="undefined"||document===null||g()?function(e){return e.cloneNode(!0)}:function(e){var n,r,i,s,o;n=a.clone(e);if(n.nodeType===t){n.removeAttribute(d),o=n.getElementsByTagName("*");for(i=0,s=o.length;i<s;i++)r=o[i],r.removeAttribute(d)}return n},d="transparency",p=function(e){return e[d]||(e[d]={})},T=function(){},h=function(){return console.log(arguments)},x=T,N=Object.prototype.toString,w=function(e){return N.call(e)==="[object Date]"},E=function(e){return e.nodeType===t},S=function(e){var t;return t=typeof e,t!=="object"&&t!=="function"||w(e)},b=function(e){return e===!0||e===!1},y=Array.isArray||function(e){return N.call(e)==="[object Array]"},(k=jQuery||Zepto)!=null&&(k.fn.render=a.jQueryPlugin),(typeof define!="undefined"&&define!==null?define.amd:void 0)&&define(function(){return a})}).call(this);
* Copyright (c) 2013 Jarno Keskikangas <jarno.keskikangas@leonidasoy.fi>; Licensed MIT
*/
(function(){var t,e,n,r,i,o,u,s,l,h,a,c,p,f,d,m,y,v,g,b,_,N,x,C,A,E,T,w,j,V,D,S,L,k,B,M,Q,H,O=[].indexOf||function(t){for(var e=0,n=this.length;n>e;e++)if(e in this&&this[e]===t)return e;return-1},P={}.hasOwnProperty,q=function(t,e){function n(){this.constructor=t}for(var r in e)P.call(e,r)&&(t[r]=e[r]);return n.prototype=e.prototype,t.prototype=new n,t.__super__=e.prototype,t};b=function(t){return function(e){return function(){return t.apply(this,arguments),e.apply(this,arguments)}}},g=function(t){return function(e){return function(){return e.apply(this,arguments),t.apply(this,arguments)}}},_=g(function(){return this}),E=function(t){var e,n;for(n=[],e=t.firstChild;e;)n.push(e),e=e.nextSibling;return n},T=function(t){var e;return e=[],Q(t,e),e},Q=function(t,e){var n,r;for(n=t.firstChild,r=[];n;)n.nodeType===u&&(e.push(new l.createElement(n)),Q(n,e)),r.push(n=n.nextSibling);return r},u=1,d=3,w=function(){return"<:nav></:nav>"!==document.createElement("nav").cloneNode(!0).outerHTML},N="undefined"==typeof document||null===document||w()?function(t){return t.cloneNode(!0)}:function(t){var e,n,r,i,o;if(e=y.clone(t),e.nodeType===u)for(e.removeAttribute(A),o=e.getElementsByTagName("*"),r=0,i=o.length;i>r;r++)n=o[r],n.removeAttribute(A);return e},A="transparency",C=function(t){return t[A]||(t[A]={})},B=function(){},x=function(){return console.log(arguments)},k=B,M=Object.prototype.toString,j=Array.isArray||function(t){return"[object Array]"===M.call(t)},D=function(t){return"[object Date]"===M.call(t)},S=function(t){return t.nodeType===u},L=function(t){var e;return e=typeof t,"object"!==e&&"function"!==e||D(t)},V=function(t){return t===!0||t===!1},y=this.Transparency={},y.render=function(t,e,n,r){var i;return null==e&&(e=[]),null==n&&(n={}),null==r&&(r={}),k=r.debug&&console?x:B,k("Transparency.render:",t,e,n,r),t?(j(e)||(e=[e]),t=(i=C(t)).context||(i.context=new o(t)),t.render(e,n,r).el):void 0},y.jQueryPlugin=_(function(t,e,n){var r,i,o,u;for(u=[],i=0,o=this.length;o>i;i++)r=this[i],u.push(y.render(r,t,e,n));return u}),y.matcher=function(t,e){return t.el.id===e||O.call(t.classNames,e)>=0||t.el.name===e||t.el.getAttribute("data-bind")===e},y.clone=function(t){var e;return"function"==typeof(e=jQuery||Zepto)?e(t).clone()[0]:void 0},null!=(H=jQuery||Zepto)&&(H.fn.render=y.jQueryPlugin),("undefined"!=typeof define&&null!==define?define.amd:void 0)&&define(function(){return y}),o=function(){function t(t){this.el=t,this.template=N(this.el),this.instances=[new c(this.el)],this.instanceCache=[]}var e,n;return n=_(function(){return this.parent=this.el.parentNode,this.parent?(this.nextSibling=this.el.nextSibling,this.parent.removeChild(this.el)):void 0}),e=_(function(){return this.parent?this.nextSibling?this.parent.insertBefore(this.el,this.nextSibling):this.parent.appendChild(this.el):void 0}),t.prototype.render=b(n)(g(e)(_(function(t,e,n){for(var r,i,o,u,s,l,h;t.length<this.instances.length;)this.instanceCache.push(this.instances.pop().remove());for(h=[],i=s=0,l=t.length;l>s;i=++s)u=t[i],(o=this.instances[i])||(o=this.instanceCache.pop()||new c(N(this.template)),this.instances.push(o.appendTo(this.el))),r=[],h.push(o.prepare(u,r).renderValues(u,r).renderDirectives(u,i,e).renderChildren(u,r,e,n));return h}))),t}(),c=function(){function t(t){this.queryCache={},this.childNodes=E(t),this.elements=T(t)}return t.prototype.remove=_(function(){var t,e,n,r,i;for(r=this.childNodes,i=[],e=0,n=r.length;n>e;e++)t=r[e],i.push(t.parentNode.removeChild(t));return i}),t.prototype.appendTo=_(function(t){var e,n,r,i,o;for(i=this.childNodes,o=[],n=0,r=i.length;r>n;n++)e=i[n],o.push(t.appendChild(e));return o}),t.prototype.prepare=_(function(t){var e,n,r,i,o;for(i=this.elements,o=[],n=0,r=i.length;r>n;n++)e=i[n],e.reset(),o.push(C(e.el).model=t);return o}),t.prototype.renderValues=_(function(t,e){var n,r,i,o;if(S(t)&&(n=this.elements[0]))return n.empty().el.appendChild(t);if("object"==typeof t){o=[];for(r in t)P.call(t,r)&&(i=t[r],null!=i&&(L(i)?o.push(function(){var t,e,o,u;for(o=this.matchingElements(r),u=[],t=0,e=o.length;e>t;t++)n=o[t],u.push(n.render(i));return u}.call(this)):"object"==typeof i?o.push(e.push(r)):o.push(void 0)));return o}}),t.prototype.renderDirectives=_(function(t,e,n){var r,i,o,u;u=[];for(o in n)P.call(n,o)&&(r=n[o],"object"==typeof r&&("object"!=typeof t&&(t={value:t}),u.push(function(){var n,u,s,l;for(s=this.matchingElements(o),l=[],n=0,u=s.length;u>n;n++)i=s[n],l.push(i.renderDirectives(t,e,r));return l}.call(this))));return u}),t.prototype.renderChildren=_(function(t,e,n,r){var i,o,u,s,l;for(l=[],u=0,s=e.length;s>u;u++)o=e[u],l.push(function(){var e,u,s,l;for(s=this.matchingElements(o),l=[],e=0,u=s.length;u>e;e++)i=s[e],l.push(y.render(i.el,t[o],n[o],r));return l}.call(this));return l}),t.prototype.matchingElements=function(t){var e,n,r;return n=(r=this.queryCache)[t]||(r[t]=function(){var n,r,i,o;for(i=this.elements,o=[],n=0,r=i.length;r>n;n++)e=i[n],y.matcher(e,t)&&o.push(e);return o}.call(this)),k("Matching elements for '"+t+"':",n),n},t}(),e={Attributes:{},createAttribute:function(r,i,o){var u;return u=e.Attributes[i]||(V(o)?n:t),new u(r,i)}},t=function(){function t(t,e){this.el=t,this.name=e,this.templateValue=this.el.getAttribute(this.name)||""}return t.prototype.set=function(t){return this.el[this.name]=t,this.el.setAttribute(this.name,""+t)},t}(),n=function(t){function e(t,e){this.el=t,this.name=e,this.templateValue=this.el.getAttribute(this.name)||!1}return q(e,t),e.prototype.set=function(t){return this.el[this.name]=t,t?this.el.setAttribute(this.name,this.name):this.el.removeAttribute(this.name)},e}(t),m=function(t){function n(t,e){var n;this.el=t,this.name=e,this.templateValue=function(){var t,e,r,i;for(r=E(this.el),i=[],t=0,e=r.length;e>t;t++)n=r[t],n.nodeType===d&&i.push(n.nodeValue);return i}.call(this).join(""),(this.textNode=this.el.firstChild)?this.textNode.nodeType!==d&&(this.textNode=this.el.insertBefore(this.el.ownerDocument.createTextNode(""),this.textNode)):this.el.appendChild(this.textNode=this.el.ownerDocument.createTextNode(""))}return q(n,t),e.Attributes.text=n,n.prototype.set=function(t){return this.textNode.nodeValue=t},n}(t),h=function(t){function n(t){n.__super__.constructor.call(this,t,"innerHTML"),this.childNodes=E(this.el)}return q(n,t),e.Attributes.html=n,n.prototype.set=function(t){var e,n,r,i,o;for(this.el.innerHTML=t,i=this.childNodes,o=[],n=0,r=i.length;r>n;n++)e=i[n],o.push(this.el.appendChild(e));return o},n}(t),i=function(t){function n(t){n.__super__.constructor.call(this,t,"class")}return q(n,t),e.Attributes["class"]=n,n}(t),l={Elements:{input:{}},createElement:function(t){var e,n;return e="input"===(n=t.nodeName.toLowerCase())?l.Elements[n][t.type.toLowerCase()]||a:l.Elements[n]||s,new e(t)}},s=function(){function t(t){this.el=t,this.attributes={},this.childNodes=E(this.el),this.nodeName=this.el.nodeName.toLowerCase(),this.classNames=this.el.className.split(" "),this.originalAttributes={}}return t.prototype.empty=_(function(){var t,e;for(e=[];t=this.el.firstChild;)e.push(this.el.removeChild(t));return e}),t.prototype.reset=function(){var t,e,n,r;n=this.attributes,r=[];for(e in n)t=n[e],r.push(t.set(t.templateValue));return r},t.prototype.render=function(t){return this.attr("text",t)},t.prototype.attr=function(t,n){var r,i;return r=(i=this.attributes)[t]||(i[t]=e.createAttribute(this.el,t,n)),r.set(n)},t.prototype.renderDirectives=function(t,e,n){var r,i,o,u,s;s=[];for(i in n)P.call(n,i)&&(r=n[i],"function"==typeof r&&(o=r.call(t,{element:this.el,index:e,value:(null!=(u=this.attributes[i])?u.templateValue:void 0)||""}),null!=o?s.push(this.attr(i,o)):s.push(void 0)));return s},t}(),f=function(t){function e(t){e.__super__.constructor.call(this,t),this.elements=T(t)}return q(e,t),l.Elements.select=e,e.prototype.render=function(t){var e,n,r,i,o;for(t=""+t,i=this.elements,o=[],n=0,r=i.length;r>n;n++)e=i[n],"option"===e.nodeName&&o.push(e.attr("selected",e.el.value===t));return o},e}(s),v=function(t){function e(){return e.__super__.constructor.apply(this,arguments)}var n,r,i,o;for(q(e,t),n=["area","base","br","col","command","embed","hr","img","input","keygen","link","meta","param","source","track","wbr"],i=0,o=n.length;o>i;i++)r=n[i],l.Elements[r]=e;return e.prototype.attr=function(t,n){return"text"!==t&&"html"!==t?e.__super__.attr.call(this,t,n):void 0},e}(s),a=function(t){function e(){return e.__super__.constructor.apply(this,arguments)}return q(e,t),e.prototype.render=function(t){return this.attr("value",t)},e}(v),r=function(t){function e(){return e.__super__.constructor.apply(this,arguments)}return q(e,t),l.Elements.input.checkbox=e,e.prototype.render=function(t){return this.attr("checked",Boolean(t))},e}(a),p=function(t){function e(){return e.__super__.constructor.apply(this,arguments)}return q(e,t),l.Elements.input.radio=e,e}(r)}).call(this);
{
"name": "transparency",
"version": "0.9.1",
"version": "0.9.2",
"main": "dist/transparency",

@@ -31,11 +31,16 @@ "description": "Transparency is a minimal template engine for browsers. It maps JSON objects to DOM elements with zero configuration.",

"dependencies": {
"jsdom": ">=0.2.10"
"jsdom": "~0.5.0"
},
"devDependencies": {
"coffee-script": ">=1.4.x",
"jquery": ">=1.8.x",
"grunt": "~0.3.17",
"grunt-contrib-coffee": "~0.3.2",
"coffee-script": "~1.4.0",
"jquery": "~1.8.3",
"grunt": "~0.4.0",
"grunt-contrib-coffee": "~0.4.0",
"grunt-jasmine-task": "~0.2.3",
"grunt-docco": "~0.1.2"
"grunt-docco": "git://github.com/bdougherty/grunt-docco.git#grunt-0.4",
"grunt-contrib-jasmine": "~0.3.2",
"grunt-contrib-watch": "~0.2.0",
"grunt-contrib-uglify": "~0.1.1",
"grunt-contrib-concat": "~0.1.2",
"grunt-template-jasmine-requirejs": "~0.1.0"
},

@@ -42,0 +47,0 @@ "scripts": {

@@ -185,3 +185,3 @@ # Synopsis

Access to the plain values within the directives is provided through `this`. There's a whole
Access to the plain values within the directives is provided through `this.value`. There's a whole
lot more to say about the directives, but that's all we need for now. For the details, see

@@ -211,3 +211,3 @@ section [Directives](https://github.com/leonidas/transparency#directives).

text: function() {
return this;
return this.value;
}

@@ -214,0 +214,0 @@ }

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