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.7.4 to 0.7.5

browser/form.html

12

browser/spec/forms.spec.js

@@ -47,5 +47,15 @@ // Generated by CoffeeScript 1.3.3

template.render(data, directives);
template.children().first().attr('selected', 'selected');
template.children().first().prop('selected', true);
return expect(template).toBeEqual(expected);
});
it("should set the matching option to 'selected' in case the target element is 'select'", function() {
var data, expected, template;
template = $("<div>\n <select class=\"state\">\n <option value=\"1\">Alabama</option>\n <option value=\"2\">Alaska</option>\n <option value=\"3\">Arizona</option>\n </select>\n</div>");
data = {
state: 2
};
expected = $("<div>\n <select class=\"state\">\n <option value=\"1\">Alabama</option>\n <option value=\"2\" selected=\"selected\">Alaska</option>\n <option value=\"3\">Arizona</option>\n </select>\n</div>");
template.render(data);
return expect(template).toBeEqual(expected);
});
return it("should handle nested options elements", function() {

@@ -52,0 +62,0 @@ var data, expected, template;

125

examples/backbone/js/app.js
$(function() {
var CustomersView, CustomerRowView, CustomerModel, CustomerCollection;
var CustomersView, CustomerRowView, CustomerModel, CustomerCollection;
CustomerModel = Backbone.Model.extend({
CustomerModel = Backbone.Model.extend({});
});
CustomerCollection = Backbone.Collection.extend({
model: CustomerModel,
url: 'customers.json'
});
CustomerCollection = Backbone.Collection.extend({
model: CustomerModel,
url: 'customers.json'
});
CustomersView = Backbone.View.extend({
events: {
'submit .new-customer': 'addCustomer',
'click .delete': 'deleteCustomer'
},
CustomerRowView = Backbone.View.extend({
tagName: 'tr',
events: {
'click .delete': 'deleteModel'
},
templateBase: $('#templates .tmpl-customerrow').detach(),
initialize: function() {
this.template = this.templateBase.clone();
},
render: function() {
data = this.model.toJSON();
this.$el.html(this.template.render(data).children());
return this;
},
deleteModel: function() {
//Here you would actually call this.model.destroy() and you would
//have a callback for the "destroy" event
alert('Removing');
return false;
}
});
el: $('#application'),
CustomersView = Backbone.View.extend({
events: {
'submit .new-customer': 'addNewCustomer'
},
el: $('#application'),
templateBase: $('#templates > .tmpl-customers').detach(),
render: function() {
var data = {
suffixes: ['Ms.', 'Mrs.', 'Mr.']
}, directives = {
suffixes: {
suffix: {
html: function() {
return this.value;
}
}
}
};
this.$el.html(this.template.render(data, directives))
return this;
},
initialize: function() {
this.template = this.templateBase.clone();
this.customers = new CustomerCollection();
this.customers.on('add', this.addOne, this);
this.customers.on('reset', this.addAll, this);
this.customers.fetch();
},
addNewCustomer: function() {
this.customers.create({
suffix: this.$('.new-customer .suffixes').val(),
name: this.$('.new-customer .name').val(),
email: this.$('.new-customer .email').val(),
phone: this.$('.new-customer .phone').val()
});
render: function() {
this.$('.customers').render(this.customers.toJSON(), {
delete: {
index: function(params) { return params.index; }
}
});
return false;
},
addOne: function(model) {
var view = new CustomerRowView({
model: model
});
this.$('.customers').append(view.render().el);
},
addAll: function() {
this.customers.forEach(this.addOne);
}
});
return this;
},
//Kickstart
var app = new CustomersView();
app.render();
initialize: function() {
this.customers = new CustomerCollection();
this.customers.on('add', this.render, this);
this.customers.on('reset', this.render, this);
this.customers.on('destroy', this.render, this);
this.customers.fetch();
},
addCustomer: function(event) {
event.preventDefault();
this.customers.create({
suffix: this.$('.new-customer .suffixes').val(),
name: this.$('.new-customer .name').val(),
email: this.$('.new-customer .email').val(),
phone: this.$('.new-customer .phone').val()
});
},
});
deleteCustomer: function(event) {
event.preventDefault();
this.customers.at(event.target.getAttribute('index')).destroy();
}
});
//Kickstart
var app = new CustomersView();
app.render();
});

@@ -15,3 +15,3 @@ // Generated by CoffeeScript 1.3.3

})(this, function() {
var $, ELEMENT_NODE, Instance, TEXT_NODE, attr, cloneNode, consoleLogger, data, empty, expando, exports, getElementsAndChildNodes, getText, html5Clone, isDate, isDomElement, isPlainValue, log, matcher, matchingElements, nullLogger, prepareContext, register, render, renderDirectives, setHtml, setText, _base, _ref, _ref1;
var $, ELEMENT_NODE, Instance, TEXT_NODE, attr, cloneNode, consoleLogger, data, empty, expando, exports, getElementsAndChildNodes, getText, html5Clone, isDate, isDomElement, isPlainValue, log, matcher, matchingElements, nullLogger, prepareContext, register, render, renderDirectives, setHtml, setSelected, setText, _base, _ref, _ref1;
register = function($) {

@@ -48,3 +48,3 @@ return $.fn.render = function(models, directives, config) {

render = function(context, models, directives, config) {
var children, contextData, e, element, index, instance, key, model, parent, sibling, value, _i, _j, _k, _l, _len, _len1, _len2, _len3, _len4, _m, _ref, _ref1, _ref2;
var children, contextData, e, element, index, instance, key, model, nodeName, parent, sibling, value, _i, _j, _k, _l, _len, _len1, _len2, _len3, _len4, _m, _ref, _ref1, _ref2;
log = (config != null ? config.debug : void 0) && (typeof console !== "undefined" && console !== null) ? consoleLogger : nullLogger;

@@ -88,4 +88,7 @@ log("Context:", context, "Models:", models, "Directives:", directives, "Config:", config);

element = _ref1[_k];
if (element.nodeName.toLowerCase() === 'input') {
nodeName = element.nodeName.toLowerCase();
if (nodeName === 'input') {
attr(element, 'value', value);
} else if (nodeName === 'select') {
attr(element, 'selected', value);
} else {

@@ -287,2 +290,21 @@ attr(element, 'text', value);

};
setSelected = function(element, value) {
var child, childElements, _i, _len, _results;
childElements = [];
getElementsAndChildNodes(element, childElements);
_results = [];
for (_i = 0, _len = childElements.length; _i < _len; _i++) {
child = childElements[_i];
if (child.nodeName.toLowerCase() === 'option') {
if (child.value === value) {
_results.push(child.selected = true);
} else {
_results.push(child.selected = false);
}
} else {
_results.push(void 0);
}
}
return _results;
};
attr = function(element, attribute, value) {

@@ -314,2 +336,7 @@ var elementData, _base, _base1, _base2, _base3;

break;
case 'selected':
if (value != null) {
setSelected(element, value);
}
break;
default:

@@ -316,0 +343,0 @@ (_base3 = elementData.originalAttributes)[attribute] || (_base3[attribute] = element.getAttribute(attribute));

// Generated by CoffeeScript 1.3.3
(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;T=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],N(r,e,t,n);return this}};if(this.jQuery!=null||this.Zepto!=null)n=this.jQuery||this.Zepto,T(n);return c="transparency",f=function(e){return e[c]||(e[c]={})},S=function(){},a=function(){var t,n,r,i,s;n=1<=arguments.length?e.call(arguments,0):[],s=[];for(r=0,i=n.length;r<i;r++)t=n[r],s.push(console.log(t));return s},b=S,N=function(e,n,r,i){var s,u,c,h,p,d,v,m,w,T,k,L,A,O,M,_,D,P,H,B,j,F,I,q;b=(i!=null?i.debug:void 0)&&typeof console!="undefined"&&console!==null?a:S,b("Context:",e,"Models:",n,"Directives:",r,"Config:",i);if(!e)return;n||(n=[]),r||(r={}),Array.isArray(n)||(n=[n]),w=e.parentNode,w&&(T=e.nextSibling,w.removeChild(e)),x(e,n),u=f(e);for(p=L=0,_=n.length;L<_;p=++L){m=n[p],s=[],d=u.instances[p],b("Model:",m,"Template instance for the model:",d),F=d.elements;for(A=0,D=F.length;A<D;A++)c=F[A],f(c).model=m;if(g(m)&&(h=d.elements[0]))l(h).appendChild(m);else if(typeof m=="object")for(v in m){if(!t.call(m,v))continue;k=m[v];if(k!=null)if(y(k)){I=E(d,v);for(O=0,P=I.length;O<P;O++)h=I[O],h.nodeName.toLowerCase()==="input"?o(h,"value",k):o(h,"text",k)}else typeof k=="object"&&s.push(v)}C(d,m,p,r);for(M=0,H=s.length;M<H;M++){v=s[M],q=E(d,v);for(j=0,B=q.length;j<B;j++)h=q[j],N(h,m[v],r[v],i)}}return w&&(T?w.insertBefore(e,T):w.appendChild(e)),e},x=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)]),b("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},C=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];if(typeof u!="object")throw new Error("Directive syntax is directive[element][attribute] = function(params)");h.push(function(){var t,i,h,p;h=E(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},k=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},L=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("")},o=function(e,t,n){var r,i,s,o,u;n!=null&&typeof n!="string"&&(n=n.toString()),r=f(e),r.originalAttributes||(r.originalAttributes={});switch(t){case"text":(i=r.originalAttributes).text||(i.text=d(e)),n!=null&&L(e,n);break;case"html":(s=r.originalAttributes).html||(s.html=e.innerHTML),n!=null&&k(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&&e.setAttribute(t,n)}return n!=null?n:r.originalAttributes[t]},E=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}()),b("Matching elements for '"+t+"':",r),r},w=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},(O=Array.isArray)==null&&(Array.isArray=function(e){return n.isArray(e)}),(M=(A=Array.prototype).indexOf)==null&&(A.indexOf=function(e){return n.inArray(e,this)}),m=function(e){return Object.prototype.toString.call(e)==="[object Date]"},g=function(e){return(e!=null?e.nodeType:void 0)===r},y=function(e){return m(e)||typeof e!="object"&&typeof e!="function"},h={render:N,register:T,matcher:w}})}).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,_;T=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],N(r,e,t,n);return this}};if(this.jQuery!=null||this.Zepto!=null)n=this.jQuery||this.Zepto,T(n);return c="transparency",f=function(e){return e[c]||(e[c]={})},S=function(){},a=function(){var t,n,r,i,s;n=1<=arguments.length?e.call(arguments,0):[],s=[];for(r=0,i=n.length;r<i;r++)t=n[r],s.push(console.log(t));return s},b=S,N=function(e,n,r,i){var s,u,c,h,p,d,v,m,w,T,k,L,A,O,M,_,D,P,H,B,j,F,I,q,R;b=(i!=null?i.debug:void 0)&&typeof console!="undefined"&&console!==null?a:S,b("Context:",e,"Models:",n,"Directives:",r,"Config:",i);if(!e)return;n||(n=[]),r||(r={}),Array.isArray(n)||(n=[n]),T=e.parentNode,T&&(k=e.nextSibling,T.removeChild(e)),x(e,n),u=f(e);for(p=A=0,D=n.length;A<D;p=++A){m=n[p],s=[],d=u.instances[p],b("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(g(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(y(L)){q=E(d,v);for(M=0,H=q.length;M<H;M++)h=q[M],w=h.nodeName.toLowerCase(),w==="input"?o(h,"value",L):w==="select"?o(h,"selected",L):o(h,"text",L)}else typeof L=="object"&&s.push(v)}C(d,m,p,r);for(_=0,B=s.length;_<B;_++){v=s[_],R=E(d,v);for(F=0,j=R.length;F<j;F++)h=R[F],N(h,m[v],r[v],i)}}return T&&(k?T.insertBefore(e,k):T.appendChild(e)),e},x=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)]),b("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},C=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];if(typeof u!="object")throw new Error("Directive syntax is directive[element][attribute] = function(params)");h.push(function(){var t,i,h,p;h=E(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},k=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},A=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("")},L=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;n!=null&&typeof n!="string"&&(n=n.toString()),r=f(e),r.originalAttributes||(r.originalAttributes={});switch(t){case"text":(i=r.originalAttributes).text||(i.text=d(e)),n!=null&&A(e,n);break;case"html":(s=r.originalAttributes).html||(s.html=e.innerHTML),n!=null&&k(e,n);break;case"class":(o=r.originalAttributes)["class"]||(o["class"]=e.className),n!=null&&(e.className=n);break;case"selected":n!=null&&L(e,n);break;default:(u=r.originalAttributes)[t]||(u[t]=e.getAttribute(t)),n!=null&&e.setAttribute(t,n)}return n!=null?n:r.originalAttributes[t]},E=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}()),b("Matching elements for '"+t+"':",r),r},w=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},(M=Array.isArray)==null&&(Array.isArray=function(e){return n.isArray(e)}),(_=(O=Array.prototype).indexOf)==null&&(O.indexOf=function(e){return n.inArray(e,this)}),m=function(e){return Object.prototype.toString.call(e)==="[object Date]"},g=function(e){return(e!=null?e.nodeType:void 0)===r},y=function(e){return m(e)||typeof e!="object"&&typeof e!="function"},h={render:N,register:T,matcher:w}})}).call(this);
{
"name" : "transparency",
"version" : "0.7.4",
"version" : "0.7.5",
"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.",

@@ -365,3 +365,3 @@ # Synopsis

href: function(params) {
return this.email;
return "mailto:" + this.email;
}

@@ -368,0 +368,0 @@ }

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