(function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o= 0 || element.el.name === key || element.el.getAttribute('data-bind') === key; }; Transparency.clone = function(node) { return $(node).clone()[0]; }; Transparency.jQueryPlugin = helpers.chainable(function(models, directives, options) { var context, i, len, results; results = []; for (i = 0, len = this.length; i < len; i++) { context = this[i]; results.push(Transparency.render(context, models, directives, options)); } return results; }); if ((typeof jQuery !== "undefined" && jQuery !== null) || (typeof Zepto !== "undefined" && Zepto !== null)) { $ = jQuery || Zepto; if ($ != null) { $.fn.render = Transparency.jQueryPlugin; } } if (typeof module !== "undefined" && module !== null ? module.exports : void 0) { module.exports = Transparency; } if (typeof window !== "undefined" && window !== null) { window.Transparency = Transparency; } if (typeof define !== "undefined" && define !== null ? define.amd : void 0) { define(function() { return Transparency; }); } },{"../lib/lodash.js":7,"./context":3,"./helpers":5}],2:[function(require,module,exports){ var Attribute, AttributeFactory, BooleanAttribute, Class, Html, Text, _, helpers, extend = function(child, parent) { for (var key in parent) { if (hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; }, hasProp = {}.hasOwnProperty; _ = require('../lib/lodash'); helpers = require('./helpers'); module.exports = AttributeFactory = { Attributes: {}, createAttribute: function(element, name) { var Attr; Attr = AttributeFactory.Attributes[name] || Attribute; return new Attr(element, name); } }; Attribute = (function() { function Attribute(el1, name1) { this.el = el1; this.name = name1; 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(superClass) { var BOOLEAN_ATTRIBUTES, i, len, name; extend(BooleanAttribute, superClass); BOOLEAN_ATTRIBUTES = ['hidden', 'async', 'defer', 'autofocus', 'formnovalidate', 'disabled', 'autofocus', 'formnovalidate', 'multiple', 'readonly', 'required', 'checked', 'scoped', 'reversed', 'selected', 'loop', 'muted', 'autoplay', 'controls', 'seamless', 'default', 'ismap', 'novalidate', 'open', 'typemustmatch', 'truespeed']; for (i = 0, len = BOOLEAN_ATTRIBUTES.length; i < len; i++) { name = BOOLEAN_ATTRIBUTES[i]; AttributeFactory.Attributes[name] = BooleanAttribute; } function BooleanAttribute(el1, name1) { this.el = el1; this.name = name1; 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(superClass) { extend(Text, superClass); AttributeFactory.Attributes['text'] = Text; function Text(el1, name1) { var child; this.el = el1; this.name = name1; this.templateValue = ((function() { var i, len, ref, results; ref = this.el.childNodes; results = []; for (i = 0, len = ref.length; i < len; i++) { child = ref[i]; if (child.nodeType === helpers.TEXT_NODE) { results.push(child.nodeValue); } } return results; }).call(this)).join(''); this.children = _.toArray(this.el.children); if (!(this.textNode = this.el.firstChild)) { this.el.appendChild(this.textNode = this.el.ownerDocument.createTextNode('')); } else if (this.textNode.nodeType !== helpers.TEXT_NODE) { this.textNode = this.el.insertBefore(this.el.ownerDocument.createTextNode(''), this.textNode); } } Text.prototype.set = function(text) { var child, i, len, ref, results; while (child = this.el.firstChild) { this.el.removeChild(child); } this.textNode.nodeValue = text; this.el.appendChild(this.textNode); ref = this.children; results = []; for (i = 0, len = ref.length; i < len; i++) { child = ref[i]; results.push(this.el.appendChild(child)); } return results; }; return Text; })(Attribute); Html = (function(superClass) { extend(Html, superClass); AttributeFactory.Attributes['html'] = Html; function Html(el1) { this.el = el1; this.templateValue = ''; this.children = _.toArray(this.el.children); } Html.prototype.set = function(html) { var child, i, len, ref, results; while (child = this.el.firstChild) { this.el.removeChild(child); } this.el.innerHTML = html + this.templateValue; ref = this.children; results = []; for (i = 0, len = ref.length; i < len; i++) { child = ref[i]; results.push(this.el.appendChild(child)); } return results; }; return Html; })(Attribute); Class = (function(superClass) { extend(Class, superClass); AttributeFactory.Attributes['class'] = Class; function Class(el) { Class.__super__.constructor.call(this, el, 'class'); } return Class; })(Attribute); },{"../lib/lodash":7,"./helpers":5}],3:[function(require,module,exports){ var Context, Instance, after, before, chainable, cloneNode, ref; ref = require('./helpers'), before = ref.before, after = ref.after, chainable = ref.chainable, cloneNode = ref.cloneNode; Instance = require('./instance'); module.exports = Context = (function() { var attach, detach; detach = chainable(function() { this.parent = this.el.parentNode; if (this.parent) { this.nextSibling = this.el.nextSibling; return this.parent.removeChild(this.el); } }); attach = chainable(function() { if (this.parent) { if (this.nextSibling) { return this.parent.insertBefore(this.el, this.nextSibling); } else { return this.parent.appendChild(this.el); } } }); function Context(el, Transparency) { this.el = el; this.Transparency = Transparency; this.template = cloneNode(this.el); this.instances = [new Instance(this.el, this.Transparency)]; this.instanceCache = []; } Context.prototype.render = before(detach)(after(attach)(chainable(function(models, directives, options) { var children, i, index, instance, len, model, results; while (models.length < this.instances.length) { this.instanceCache.push(this.instances.pop().remove()); } while (models.length > this.instances.length) { instance = this.instanceCache.pop() || new Instance(cloneNode(this.template), this.Transparency); this.instances.push(instance.appendTo(this.el)); } results = []; for (index = i = 0, len = models.length; i < len; index = ++i) { model = models[index]; instance = this.instances[index]; children = []; results.push(instance.prepare(model, children).renderValues(model, children).renderDirectives(model, index, directives).renderChildren(model, children, directives, options)); } return results; }))); return Context; })(); },{"./helpers":5,"./instance":6}],4:[function(require,module,exports){ var AttributeFactory, Checkbox, Element, ElementFactory, Input, Radio, Select, TextArea, VoidElement, _, helpers, hasProp = {}.hasOwnProperty, extend = function(child, parent) { for (var key in parent) { if (hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; }; _ = require('../lib/lodash.js'); helpers = require('./helpers'); AttributeFactory = require('./attributeFactory'); module.exports = 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() { function Element(el1) { this.el = el1; this.attributes = {}; this.childNodes = _.toArray(this.el.childNodes); this.nodeName = this.el.nodeName.toLowerCase(); this.classNames = this.el.className.split(' '); this.originalAttributes = {}; } Element.prototype.empty = function() { var child; while (child = this.el.firstChild) { this.el.removeChild(child); } return this; }; Element.prototype.reset = function() { var attribute, name, ref, results; ref = this.attributes; results = []; for (name in ref) { attribute = ref[name]; results.push(attribute.set(attribute.templateValue)); } return results; }; Element.prototype.render = function(value) { return this.attr('text', value); }; Element.prototype.attr = function(name, value) { var attribute, base; attribute = (base = this.attributes)[name] || (base[name] = AttributeFactory.createAttribute(this.el, name, value)); if (value != null) { attribute.set(value); } return attribute; }; Element.prototype.renderDirectives = function(model, index, attributes) { var directive, name, results, value; results = []; for (name in attributes) { if (!hasProp.call(attributes, name)) continue; directive = attributes[name]; if (!(typeof directive === 'function')) { continue; } value = directive.call(model, { element: this.el, index: index, value: this.attr(name).templateValue }); if (value != null) { results.push(this.attr(name, value)); } else { results.push(void 0); } } return results; }; return Element; })(); Select = (function(superClass) { extend(Select, superClass); ElementFactory.Elements['select'] = Select; function Select(el) { Select.__super__.constructor.call(this, el); this.elements = helpers.getElements(el); } Select.prototype.render = function(value) { var i, len, option, ref, results; value = value.toString(); ref = this.elements; results = []; for (i = 0, len = ref.length; i < len; i++) { option = ref[i]; if (option.nodeName === 'option') { results.push(option.attr('selected', option.el.value === value)); } } return results; }; return Select; })(Element); VoidElement = (function(superClass) { var VOID_ELEMENTS, i, len, nodeName; extend(VoidElement, superClass); function VoidElement() { return VoidElement.__super__.constructor.apply(this, arguments); } VOID_ELEMENTS = ['area', 'base', 'br', 'col', 'command', 'embed', 'hr', 'img', 'input', 'keygen', 'link', 'meta', 'param', 'source', 'track', 'wbr']; for (i = 0, len = VOID_ELEMENTS.length; i < len; i++) { nodeName = VOID_ELEMENTS[i]; ElementFactory.Elements[nodeName] = VoidElement; } VoidElement.prototype.attr = function(name, value) { if (name !== 'text' && name !== 'html') { return VoidElement.__super__.attr.call(this, name, value); } }; return VoidElement; })(Element); Input = (function(superClass) { extend(Input, superClass); function Input() { return Input.__super__.constructor.apply(this, arguments); } Input.prototype.render = function(value) { return this.attr('value', value); }; return Input; })(VoidElement); TextArea = (function(superClass) { extend(TextArea, superClass); function TextArea() { return TextArea.__super__.constructor.apply(this, arguments); } ElementFactory.Elements['textarea'] = TextArea; return TextArea; })(Input); Checkbox = (function(superClass) { extend(Checkbox, superClass); function Checkbox() { return Checkbox.__super__.constructor.apply(this, arguments); } ElementFactory.Elements['input']['checkbox'] = Checkbox; Checkbox.prototype.render = function(value) { return this.attr('checked', Boolean(value)); }; return Checkbox; })(Input); Radio = (function(superClass) { extend(Radio, superClass); function Radio() { return Radio.__super__.constructor.apply(this, arguments); } ElementFactory.Elements['input']['radio'] = Radio; return Radio; })(Checkbox); },{"../lib/lodash.js":7,"./attributeFactory":2,"./helpers":5}],5:[function(require,module,exports){ var ElementFactory, _getElements, expando, html5Clone; ElementFactory = require('./elementFactory'); exports.before = function(decorator) { return function(method) { return function() { decorator.apply(this, arguments); return method.apply(this, arguments); }; }; }; exports.after = function(decorator) { return function(method) { return function() { method.apply(this, arguments); return decorator.apply(this, arguments); }; }; }; exports.chainable = exports.after(function() { return this; }); exports.onlyWith$ = function(fn) { if ((typeof jQuery !== "undefined" && jQuery !== null) || (typeof Zepto !== "undefined" && Zepto !== null)) { return (function($) { return fn(arguments); })(jQuery || Zepto); } }; exports.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 === exports.ELEMENT_NODE) { elements.push(new ElementFactory.createElement(child)); _getElements(child, elements); } results.push(child = child.nextSibling); } return results; }; exports.ELEMENT_NODE = 1; exports.TEXT_NODE = 3; html5Clone = function() { return document.createElement('nav').cloneNode(true).outerHTML !== '<:nav>'; }; exports.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 === exports.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'; exports.data = function(element) { return element[expando] || (element[expando] = {}); }; exports.nullLogger = function() {}; exports.consoleLogger = function() { return console.log(arguments); }; exports.log = exports.nullLogger; },{"./elementFactory":4}],6:[function(require,module,exports){ var Instance, _, chainable, helpers, hasProp = {}.hasOwnProperty; _ = require('../lib/lodash.js'); chainable = (helpers = require('./helpers')).chainable; module.exports = Instance = (function() { function Instance(template, Transparency) { this.Transparency = Transparency; this.queryCache = {}; this.childNodes = _.toArray(template.childNodes); this.elements = helpers.getElements(template); } Instance.prototype.remove = chainable(function() { var i, len, node, ref, results; ref = this.childNodes; results = []; for (i = 0, len = ref.length; i < len; i++) { node = ref[i]; results.push(node.parentNode.removeChild(node)); } return results; }); Instance.prototype.appendTo = chainable(function(parent) { var i, len, node, ref, results; ref = this.childNodes; results = []; for (i = 0, len = ref.length; i < len; i++) { node = ref[i]; results.push(parent.appendChild(node)); } return results; }); Instance.prototype.prepare = chainable(function(model) { var element, i, len, ref, results; ref = this.elements; results = []; for (i = 0, len = ref.length; i < len; i++) { element = ref[i]; element.reset(); results.push(helpers.data(element.el).model = model); } return results; }); Instance.prototype.renderValues = chainable(function(model, children) { var element, key, results, value; if (_.isElement(model) && (element = this.elements[0])) { return element.empty().el.appendChild(model); } else if (typeof model === 'object') { results = []; for (key in model) { if (!hasProp.call(model, key)) continue; value = model[key]; if (value != null) { if (_.isString(value) || _.isNumber(value) || _.isBoolean(value) || _.isDate(value)) { 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(element.render(value)); } return results1; }).call(this)); } else if (typeof value === 'object') { results.push(children.push(key)); } else { results.push(void 0); } } } return results; } }); Instance.prototype.renderDirectives = chainable(function(model, index, directives) { var attributes, element, key, results; results = []; for (key in directives) { if (!hasProp.call(directives, key)) continue; attributes = directives[key]; if (!(typeof attributes === 'object')) { continue; } if (typeof model !== 'object') { model = { value: model }; } 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(element.renderDirectives(model, index, attributes)); } return results1; }).call(this)); } return results; }); Instance.prototype.renderChildren = chainable(function(model, children, directives, options) { var element, i, key, len, results; results = []; for (i = 0, len = children.length; i < len; i++) { key = children[i]; results.push((function() { var j, len1, ref, results1; ref = this.matchingElements(key); results1 = []; for (j = 0, len1 = ref.length; j < len1; j++) { element = ref[j]; results1.push(this.Transparency.render(element.el, model[key], directives[key], options)); } return results1; }).call(this)); } return results; }); Instance.prototype.matchingElements = function(key) { var base, el, elements; elements = (base = this.queryCache)[key] || (base[key] = (function() { var i, len, ref, results; ref = this.elements; results = []; for (i = 0, len = ref.length; i < len; i++) { el = ref[i]; if (this.Transparency.matcher(el, key)) { results.push(el); } } return results; }).call(this)); helpers.log("Matching elements for '" + key + "':", elements); return elements; }; return Instance; })(); },{"../lib/lodash.js":7,"./helpers":5}],7:[function(require,module,exports){ var _ = {}; _.toString = Object.prototype.toString; _.toArray = function(obj) { var arr = new Array(obj.length); for (var i = 0; i < obj.length; i++) { arr[i] = obj[i]; } return arr; }; _.isString = function(obj) { return _.toString.call(obj) == '[object String]'; }; _.isNumber = function(obj) { return _.toString.call(obj) == '[object Number]'; }; _.isArray = Array.isArray || function(obj) { return _.toString.call(obj) === '[object Array]'; }; _.isDate = function(obj) { return _.toString.call(obj) === '[object Date]'; }; _.isElement = function(obj) { return !!(obj && obj.nodeType === 1); }; _.isPlainValue = function(obj) { var type; type = typeof obj; return (type !== 'object' && type !== 'function') || exports.isDate(obj); }; _.isBoolean = function(obj) { return obj === true || obj === false; }; module.exports = _; },{}]},{},[1]);