transparency

Transparency is a minimal template engine for browsers. It maps JSON objects to DOM elements with zero configuration

This script should not be not be installed directly. It is a library for other scripts to include with the meta directive // @require https://update.greatest.deepsurf.us/scripts/6649/25968/transparency.js

  1. // ==UserScript==
  2. // @name transparency
  3. // @namespace https://github.com/leonidas
  4. // @homepage http://leonidas.github.io/transparency
  5. // @version 0.10.0
  6. // @description Transparency is a minimal template engine for browsers. It maps JSON objects to DOM elements with zero configuration
  7. // @author Jarno Keskikangas <jarno.keskikangas@leonidasoy.fi>
  8. // @license MIT
  9. // ==/UserScript==
  10. (function e(t, n, r) {
  11. function s(o, u) {
  12. if (!n[o]) {
  13. if (!t[o]) {
  14. var a = typeof require == "function" && require;
  15. if (!u && a) return a(o, !0);
  16. if (i) return i(o, !0);
  17. var f = new Error("Cannot find module '" + o + "'");
  18. throw f.code = "MODULE_NOT_FOUND", f
  19. }
  20. var l = n[o] = {
  21. exports: {}
  22. };
  23. t[o][0].call(l.exports, function (e) {
  24. var n = t[o][1][e];
  25. return s(n ? n : e)
  26. }, l, l.exports, e, t, n, r)
  27. }
  28. return n[o].exports
  29. }
  30. var i = typeof require == "function" && require;
  31. for (var o = 0; o < r.length; o++) s(r[o]);
  32. return s
  33. })({
  34. 1: [function (require, module, exports) {
  35. var $, Context, Transparency, helpers, _,
  36. __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; };
  37.  
  38. _ = require('../lib/lodash.js');
  39.  
  40. helpers = require('./helpers');
  41.  
  42. Context = require('./context');
  43.  
  44. Transparency = {};
  45.  
  46. Transparency.render = function(context, models, directives, options) {
  47. var log, _base;
  48. if (models == null) {
  49. models = [];
  50. }
  51. if (directives == null) {
  52. directives = {};
  53. }
  54. if (options == null) {
  55. options = {};
  56. }
  57. log = options.debug && console ? helpers.consoleLogger : helpers.nullLogger;
  58. log("Transparency.render:", context, models, directives, options);
  59. if (!context) {
  60. return;
  61. }
  62. if (!_.isArray(models)) {
  63. models = [models];
  64. }
  65. context = (_base = helpers.data(context)).context || (_base.context = new Context(context, Transparency));
  66. return context.render(models, directives, options).el;
  67. };
  68.  
  69. Transparency.matcher = function(element, key) {
  70. return element.el.id === key || __indexOf.call(element.classNames, key) >= 0 || element.el.name === key || element.el.getAttribute('data-bind') === key;
  71. };
  72.  
  73. Transparency.clone = function(node) {
  74. return $(node).clone()[0];
  75. };
  76.  
  77. Transparency.jQueryPlugin = helpers.chainable(function(models, directives, options) {
  78. var context, _i, _len, _results;
  79. _results = [];
  80. for (_i = 0, _len = this.length; _i < _len; _i++) {
  81. context = this[_i];
  82. _results.push(Transparency.render(context, models, directives, options));
  83. }
  84. return _results;
  85. });
  86.  
  87. if ((typeof jQuery !== "undefined" && jQuery !== null) || (typeof Zepto !== "undefined" && Zepto !== null)) {
  88. $ = jQuery || Zepto;
  89. if ($ != null) {
  90. $.fn.render = Transparency.jQueryPlugin;
  91. }
  92. }
  93.  
  94. if (typeof module !== "undefined" && module !== null ? module.exports : void 0) {
  95. module.exports = Transparency;
  96. }
  97.  
  98. if (typeof window !== "undefined" && window !== null) {
  99. window.Transparency = Transparency;
  100. }
  101.  
  102. if (typeof define !== "undefined" && define !== null ? define.amd : void 0) {
  103. define(function() {
  104. return Transparency;
  105. });
  106. }
  107.  
  108. },{"../lib/lodash.js":7,"./context":3,"./helpers":5}],2:[function(require,module,exports){
  109. var Attribute, AttributeFactory, BooleanAttribute, Class, Html, Text, helpers, _,
  110. __hasProp = {}.hasOwnProperty,
  111. __extends = 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; };
  112.  
  113. _ = require('../lib/lodash');
  114.  
  115. helpers = require('./helpers');
  116.  
  117. module.exports = AttributeFactory = {
  118. Attributes: {},
  119. createAttribute: function(element, name) {
  120. var Attr;
  121. Attr = AttributeFactory.Attributes[name] || Attribute;
  122. return new Attr(element, name);
  123. }
  124. };
  125.  
  126. Attribute = (function() {
  127. function Attribute(el, name) {
  128. this.el = el;
  129. this.name = name;
  130. this.templateValue = this.el.getAttribute(this.name) || '';
  131. }
  132.  
  133. Attribute.prototype.set = function(value) {
  134. this.el[this.name] = value;
  135. return this.el.setAttribute(this.name, value.toString());
  136. };
  137.  
  138. return Attribute;
  139.  
  140. })();
  141.  
  142. BooleanAttribute = (function(_super) {
  143. var BOOLEAN_ATTRIBUTES, name, _i, _len;
  144.  
  145. __extends(BooleanAttribute, _super);
  146.  
  147. 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'];
  148.  
  149. for (_i = 0, _len = BOOLEAN_ATTRIBUTES.length; _i < _len; _i++) {
  150. name = BOOLEAN_ATTRIBUTES[_i];
  151. AttributeFactory.Attributes[name] = BooleanAttribute;
  152. }
  153.  
  154. function BooleanAttribute(el, name) {
  155. this.el = el;
  156. this.name = name;
  157. this.templateValue = this.el.getAttribute(this.name) || false;
  158. }
  159.  
  160. BooleanAttribute.prototype.set = function(value) {
  161. this.el[this.name] = value;
  162. if (value) {
  163. return this.el.setAttribute(this.name, this.name);
  164. } else {
  165. return this.el.removeAttribute(this.name);
  166. }
  167. };
  168.  
  169. return BooleanAttribute;
  170.  
  171. })(Attribute);
  172.  
  173. Text = (function(_super) {
  174. __extends(Text, _super);
  175.  
  176. AttributeFactory.Attributes['text'] = Text;
  177.  
  178. function Text(el, name) {
  179. var child;
  180. this.el = el;
  181. this.name = name;
  182. this.templateValue = ((function() {
  183. var _i, _len, _ref, _results;
  184. _ref = this.el.childNodes;
  185. _results = [];
  186. for (_i = 0, _len = _ref.length; _i < _len; _i++) {
  187. child = _ref[_i];
  188. if (child.nodeType === helpers.TEXT_NODE) {
  189. _results.push(child.nodeValue);
  190. }
  191. }
  192. return _results;
  193. }).call(this)).join('');
  194. this.children = _.toArray(this.el.children);
  195. if (!(this.textNode = this.el.firstChild)) {
  196. this.el.appendChild(this.textNode = this.el.ownerDocument.createTextNode(''));
  197. } else if (this.textNode.nodeType !== helpers.TEXT_NODE) {
  198. this.textNode = this.el.insertBefore(this.el.ownerDocument.createTextNode(''), this.textNode);
  199. }
  200. }
  201.  
  202. Text.prototype.set = function(text) {
  203. var child, _i, _len, _ref, _results;
  204. while (child = this.el.firstChild) {
  205. this.el.removeChild(child);
  206. }
  207. this.textNode.nodeValue = text;
  208. this.el.appendChild(this.textNode);
  209. _ref = this.children;
  210. _results = [];
  211. for (_i = 0, _len = _ref.length; _i < _len; _i++) {
  212. child = _ref[_i];
  213. _results.push(this.el.appendChild(child));
  214. }
  215. return _results;
  216. };
  217.  
  218. return Text;
  219.  
  220. })(Attribute);
  221.  
  222. Html = (function(_super) {
  223. __extends(Html, _super);
  224.  
  225. AttributeFactory.Attributes['html'] = Html;
  226.  
  227. function Html(el) {
  228. this.el = el;
  229. this.templateValue = '';
  230. this.children = _.toArray(this.el.children);
  231. }
  232.  
  233. Html.prototype.set = function(html) {
  234. var child, _i, _len, _ref, _results;
  235. while (child = this.el.firstChild) {
  236. this.el.removeChild(child);
  237. }
  238. this.el.innerHTML = html + this.templateValue;
  239. _ref = this.children;
  240. _results = [];
  241. for (_i = 0, _len = _ref.length; _i < _len; _i++) {
  242. child = _ref[_i];
  243. _results.push(this.el.appendChild(child));
  244. }
  245. return _results;
  246. };
  247.  
  248. return Html;
  249.  
  250. })(Attribute);
  251.  
  252. Class = (function(_super) {
  253. __extends(Class, _super);
  254.  
  255. AttributeFactory.Attributes['class'] = Class;
  256.  
  257. function Class(el) {
  258. Class.__super__.constructor.call(this, el, 'class');
  259. }
  260.  
  261. return Class;
  262.  
  263. })(Attribute);
  264.  
  265. },{"../lib/lodash":7,"./helpers":5}],3:[function(require,module,exports){
  266. var Context, Instance, after, before, chainable, cloneNode, _ref;
  267.  
  268. _ref = require('./helpers'), before = _ref.before, after = _ref.after, chainable = _ref.chainable, cloneNode = _ref.cloneNode;
  269.  
  270. Instance = require('./instance');
  271.  
  272. module.exports = Context = (function() {
  273. var attach, detach;
  274.  
  275. detach = chainable(function() {
  276. this.parent = this.el.parentNode;
  277. if (this.parent) {
  278. this.nextSibling = this.el.nextSibling;
  279. return this.parent.removeChild(this.el);
  280. }
  281. });
  282.  
  283. attach = chainable(function() {
  284. if (this.parent) {
  285. if (this.nextSibling) {
  286. return this.parent.insertBefore(this.el, this.nextSibling);
  287. } else {
  288. return this.parent.appendChild(this.el);
  289. }
  290. }
  291. });
  292.  
  293. function Context(el, Transparency) {
  294. this.el = el;
  295. this.Transparency = Transparency;
  296. this.template = cloneNode(this.el);
  297. this.instances = [new Instance(this.el, this.Transparency)];
  298. this.instanceCache = [];
  299. }
  300.  
  301. Context.prototype.render = before(detach)(after(attach)(chainable(function(models, directives, options) {
  302. var children, index, instance, model, _i, _len, _results;
  303. while (models.length < this.instances.length) {
  304. this.instanceCache.push(this.instances.pop().remove());
  305. }
  306. while (models.length > this.instances.length) {
  307. instance = this.instanceCache.pop() || new Instance(cloneNode(this.template), this.Transparency);
  308. this.instances.push(instance.appendTo(this.el));
  309. }
  310. _results = [];
  311. for (index = _i = 0, _len = models.length; _i < _len; index = ++_i) {
  312. model = models[index];
  313. instance = this.instances[index];
  314. children = [];
  315. _results.push(instance.prepare(model, children).renderValues(model, children).renderDirectives(model, index, directives).renderChildren(model, children, directives, options));
  316. }
  317. return _results;
  318. })));
  319.  
  320. return Context;
  321.  
  322. })();
  323.  
  324. },{"./helpers":5,"./instance":6}],4:[function(require,module,exports){
  325. var AttributeFactory, Checkbox, Element, ElementFactory, Input, Radio, Select, TextArea, VoidElement, helpers, _,
  326. __hasProp = {}.hasOwnProperty,
  327. __extends = 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; };
  328.  
  329. _ = require('../lib/lodash.js');
  330.  
  331. helpers = require('./helpers');
  332.  
  333. AttributeFactory = require('./attributeFactory');
  334.  
  335. module.exports = ElementFactory = {
  336. Elements: {
  337. input: {}
  338. },
  339. createElement: function(el) {
  340. var El, name;
  341. if ('input' === (name = el.nodeName.toLowerCase())) {
  342. El = ElementFactory.Elements[name][el.type.toLowerCase()] || Input;
  343. } else {
  344. El = ElementFactory.Elements[name] || Element;
  345. }
  346. return new El(el);
  347. }
  348. };
  349.  
  350. Element = (function() {
  351. function Element(el) {
  352. this.el = el;
  353. this.attributes = {};
  354. this.childNodes = _.toArray(this.el.childNodes);
  355. this.nodeName = this.el.nodeName.toLowerCase();
  356. this.classNames = this.el.className.split(' ');
  357. this.originalAttributes = {};
  358. }
  359.  
  360. Element.prototype.empty = function() {
  361. var child;
  362. while (child = this.el.firstChild) {
  363. this.el.removeChild(child);
  364. }
  365. return this;
  366. };
  367.  
  368. Element.prototype.reset = function() {
  369. var attribute, name, _ref, _results;
  370. _ref = this.attributes;
  371. _results = [];
  372. for (name in _ref) {
  373. attribute = _ref[name];
  374. _results.push(attribute.set(attribute.templateValue));
  375. }
  376. return _results;
  377. };
  378.  
  379. Element.prototype.render = function(value) {
  380. return this.attr('text', value);
  381. };
  382.  
  383. Element.prototype.attr = function(name, value) {
  384. var attribute, _base;
  385. attribute = (_base = this.attributes)[name] || (_base[name] = AttributeFactory.createAttribute(this.el, name, value));
  386. if (value != null) {
  387. attribute.set(value);
  388. }
  389. return attribute;
  390. };
  391.  
  392. Element.prototype.renderDirectives = function(model, index, attributes) {
  393. var directive, name, value, _results;
  394. _results = [];
  395. for (name in attributes) {
  396. if (!__hasProp.call(attributes, name)) continue;
  397. directive = attributes[name];
  398. if (!(typeof directive === 'function')) {
  399. continue;
  400. }
  401. value = directive.call(model, {
  402. element: this.el,
  403. index: index,
  404. value: this.attr(name).templateValue
  405. });
  406. if (value != null) {
  407. _results.push(this.attr(name, value));
  408. } else {
  409. _results.push(void 0);
  410. }
  411. }
  412. return _results;
  413. };
  414.  
  415. return Element;
  416.  
  417. })();
  418.  
  419. Select = (function(_super) {
  420. __extends(Select, _super);
  421.  
  422. ElementFactory.Elements['select'] = Select;
  423.  
  424. function Select(el) {
  425. Select.__super__.constructor.call(this, el);
  426. this.elements = helpers.getElements(el);
  427. }
  428.  
  429. Select.prototype.render = function(value) {
  430. var option, _i, _len, _ref, _results;
  431. value = value.toString();
  432. _ref = this.elements;
  433. _results = [];
  434. for (_i = 0, _len = _ref.length; _i < _len; _i++) {
  435. option = _ref[_i];
  436. if (option.nodeName === 'option') {
  437. _results.push(option.attr('selected', option.el.value === value));
  438. }
  439. }
  440. return _results;
  441. };
  442.  
  443. return Select;
  444.  
  445. })(Element);
  446.  
  447. VoidElement = (function(_super) {
  448. var VOID_ELEMENTS, nodeName, _i, _len;
  449.  
  450. __extends(VoidElement, _super);
  451.  
  452. function VoidElement() {
  453. return VoidElement.__super__.constructor.apply(this, arguments);
  454. }
  455.  
  456. VOID_ELEMENTS = ['area', 'base', 'br', 'col', 'command', 'embed', 'hr', 'img', 'input', 'keygen', 'link', 'meta', 'param', 'source', 'track', 'wbr'];
  457.  
  458. for (_i = 0, _len = VOID_ELEMENTS.length; _i < _len; _i++) {
  459. nodeName = VOID_ELEMENTS[_i];
  460. ElementFactory.Elements[nodeName] = VoidElement;
  461. }
  462.  
  463. VoidElement.prototype.attr = function(name, value) {
  464. if (name !== 'text' && name !== 'html') {
  465. return VoidElement.__super__.attr.call(this, name, value);
  466. }
  467. };
  468.  
  469. return VoidElement;
  470.  
  471. })(Element);
  472.  
  473. Input = (function(_super) {
  474. __extends(Input, _super);
  475.  
  476. function Input() {
  477. return Input.__super__.constructor.apply(this, arguments);
  478. }
  479.  
  480. Input.prototype.render = function(value) {
  481. return this.attr('value', value);
  482. };
  483.  
  484. return Input;
  485.  
  486. })(VoidElement);
  487.  
  488. TextArea = (function(_super) {
  489. __extends(TextArea, _super);
  490.  
  491. function TextArea() {
  492. return TextArea.__super__.constructor.apply(this, arguments);
  493. }
  494.  
  495. ElementFactory.Elements['textarea'] = TextArea;
  496.  
  497. return TextArea;
  498.  
  499. })(Input);
  500.  
  501. Checkbox = (function(_super) {
  502. __extends(Checkbox, _super);
  503.  
  504. function Checkbox() {
  505. return Checkbox.__super__.constructor.apply(this, arguments);
  506. }
  507.  
  508. ElementFactory.Elements['input']['checkbox'] = Checkbox;
  509.  
  510. Checkbox.prototype.render = function(value) {
  511. return this.attr('checked', Boolean(value));
  512. };
  513.  
  514. return Checkbox;
  515.  
  516. })(Input);
  517.  
  518. Radio = (function(_super) {
  519. __extends(Radio, _super);
  520.  
  521. function Radio() {
  522. return Radio.__super__.constructor.apply(this, arguments);
  523. }
  524.  
  525. ElementFactory.Elements['input']['radio'] = Radio;
  526.  
  527. return Radio;
  528.  
  529. })(Checkbox);
  530.  
  531. },{"../lib/lodash.js":7,"./attributeFactory":2,"./helpers":5}],5:[function(require,module,exports){
  532. var ElementFactory, expando, html5Clone, _getElements;
  533.  
  534. ElementFactory = require('./elementFactory');
  535.  
  536. exports.before = function(decorator) {
  537. return function(method) {
  538. return function() {
  539. decorator.apply(this, arguments);
  540. return method.apply(this, arguments);
  541. };
  542. };
  543. };
  544.  
  545. exports.after = function(decorator) {
  546. return function(method) {
  547. return function() {
  548. method.apply(this, arguments);
  549. return decorator.apply(this, arguments);
  550. };
  551. };
  552. };
  553.  
  554. exports.chainable = exports.after(function() {
  555. return this;
  556. });
  557.  
  558. exports.onlyWith$ = function(fn) {
  559. if ((typeof jQuery !== "undefined" && jQuery !== null) || (typeof Zepto !== "undefined" && Zepto !== null)) {
  560. return (function($) {
  561. return fn(arguments);
  562. })(jQuery || Zepto);
  563. }
  564. };
  565.  
  566. exports.getElements = function(el) {
  567. var elements;
  568. elements = [];
  569. _getElements(el, elements);
  570. return elements;
  571. };
  572.  
  573. _getElements = function(template, elements) {
  574. var child, _results;
  575. child = template.firstChild;
  576. _results = [];
  577. while (child) {
  578. if (child.nodeType === exports.ELEMENT_NODE) {
  579. elements.push(new ElementFactory.createElement(child));
  580. _getElements(child, elements);
  581. }
  582. _results.push(child = child.nextSibling);
  583. }
  584. return _results;
  585. };
  586.  
  587. exports.ELEMENT_NODE = 1;
  588.  
  589. exports.TEXT_NODE = 3;
  590.  
  591. html5Clone = function() {
  592. return document.createElement('nav').cloneNode(true).outerHTML !== '<:nav></:nav>';
  593. };
  594.  
  595. exports.cloneNode = (typeof document === "undefined" || document === null) || html5Clone() ? function(node) {
  596. return node.cloneNode(true);
  597. } : function(node) {
  598. var cloned, element, _i, _len, _ref;
  599. cloned = Transparency.clone(node);
  600. if (cloned.nodeType === exports.ELEMENT_NODE) {
  601. cloned.removeAttribute(expando);
  602. _ref = cloned.getElementsByTagName('*');
  603. for (_i = 0, _len = _ref.length; _i < _len; _i++) {
  604. element = _ref[_i];
  605. element.removeAttribute(expando);
  606. }
  607. }
  608. return cloned;
  609. };
  610.  
  611. expando = 'transparency';
  612.  
  613. exports.data = function(element) {
  614. return element[expando] || (element[expando] = {});
  615. };
  616.  
  617. exports.nullLogger = function() {};
  618.  
  619. exports.consoleLogger = function() {
  620. return console.log(arguments);
  621. };
  622.  
  623. exports.log = exports.nullLogger;
  624.  
  625. },{"./elementFactory":4}],6:[function(require,module,exports){
  626. var Instance, chainable, helpers, _,
  627. __hasProp = {}.hasOwnProperty;
  628.  
  629. _ = require('../lib/lodash.js');
  630.  
  631. chainable = (helpers = require('./helpers')).chainable;
  632.  
  633. module.exports = Instance = (function() {
  634. function Instance(template, Transparency) {
  635. this.Transparency = Transparency;
  636. this.queryCache = {};
  637. this.childNodes = _.toArray(template.childNodes);
  638. this.elements = helpers.getElements(template);
  639. }
  640.  
  641. Instance.prototype.remove = chainable(function() {
  642. var node, _i, _len, _ref, _results;
  643. _ref = this.childNodes;
  644. _results = [];
  645. for (_i = 0, _len = _ref.length; _i < _len; _i++) {
  646. node = _ref[_i];
  647. _results.push(node.parentNode.removeChild(node));
  648. }
  649. return _results;
  650. });
  651.  
  652. Instance.prototype.appendTo = chainable(function(parent) {
  653. var node, _i, _len, _ref, _results;
  654. _ref = this.childNodes;
  655. _results = [];
  656. for (_i = 0, _len = _ref.length; _i < _len; _i++) {
  657. node = _ref[_i];
  658. _results.push(parent.appendChild(node));
  659. }
  660. return _results;
  661. });
  662.  
  663. Instance.prototype.prepare = chainable(function(model) {
  664. var element, _i, _len, _ref, _results;
  665. _ref = this.elements;
  666. _results = [];
  667. for (_i = 0, _len = _ref.length; _i < _len; _i++) {
  668. element = _ref[_i];
  669. element.reset();
  670. _results.push(helpers.data(element.el).model = model);
  671. }
  672. return _results;
  673. });
  674.  
  675. Instance.prototype.renderValues = chainable(function(model, children) {
  676. var element, key, value, _results;
  677. if (_.isElement(model) && (element = this.elements[0])) {
  678. return element.empty().el.appendChild(model);
  679. } else if (typeof model === 'object') {
  680. _results = [];
  681. for (key in model) {
  682. if (!__hasProp.call(model, key)) continue;
  683. value = model[key];
  684. if (value != null) {
  685. if (_.isString(value) || _.isNumber(value) || _.isBoolean(value) || _.isDate(value)) {
  686. _results.push((function() {
  687. var _i, _len, _ref, _results1;
  688. _ref = this.matchingElements(key);
  689. _results1 = [];
  690. for (_i = 0, _len = _ref.length; _i < _len; _i++) {
  691. element = _ref[_i];
  692. _results1.push(element.render(value));
  693. }
  694. return _results1;
  695. }).call(this));
  696. } else if (typeof value === 'object') {
  697. _results.push(children.push(key));
  698. } else {
  699. _results.push(void 0);
  700. }
  701. }
  702. }
  703. return _results;
  704. }
  705. });
  706.  
  707. Instance.prototype.renderDirectives = chainable(function(model, index, directives) {
  708. var attributes, element, key, _results;
  709. _results = [];
  710. for (key in directives) {
  711. if (!__hasProp.call(directives, key)) continue;
  712. attributes = directives[key];
  713. if (!(typeof attributes === 'object')) {
  714. continue;
  715. }
  716. if (typeof model !== 'object') {
  717. model = {
  718. value: model
  719. };
  720. }
  721. _results.push((function() {
  722. var _i, _len, _ref, _results1;
  723. _ref = this.matchingElements(key);
  724. _results1 = [];
  725. for (_i = 0, _len = _ref.length; _i < _len; _i++) {
  726. element = _ref[_i];
  727. _results1.push(element.renderDirectives(model, index, attributes));
  728. }
  729. return _results1;
  730. }).call(this));
  731. }
  732. return _results;
  733. });
  734.  
  735. Instance.prototype.renderChildren = chainable(function(model, children, directives, options) {
  736. var element, key, _i, _len, _results;
  737. _results = [];
  738. for (_i = 0, _len = children.length; _i < _len; _i++) {
  739. key = children[_i];
  740. _results.push((function() {
  741. var _j, _len1, _ref, _results1;
  742. _ref = this.matchingElements(key);
  743. _results1 = [];
  744. for (_j = 0, _len1 = _ref.length; _j < _len1; _j++) {
  745. element = _ref[_j];
  746. _results1.push(this.Transparency.render(element.el, model[key], directives[key], options));
  747. }
  748. return _results1;
  749. }).call(this));
  750. }
  751. return _results;
  752. });
  753.  
  754. Instance.prototype.matchingElements = function(key) {
  755. var el, elements, _base;
  756. elements = (_base = this.queryCache)[key] || (_base[key] = (function() {
  757. var _i, _len, _ref, _results;
  758. _ref = this.elements;
  759. _results = [];
  760. for (_i = 0, _len = _ref.length; _i < _len; _i++) {
  761. el = _ref[_i];
  762. if (this.Transparency.matcher(el, key)) {
  763. _results.push(el);
  764. }
  765. }
  766. return _results;
  767. }).call(this));
  768. helpers.log("Matching elements for '" + key + "':", elements);
  769. return elements;
  770. };
  771.  
  772. return Instance;
  773.  
  774. })();
  775.  
  776. },{"../lib/lodash.js":7,"./helpers":5}],7:[function(require,module,exports){
  777. var _ = {};
  778.  
  779. _.toString = Object.prototype.toString;
  780.  
  781. _.toArray = function(obj) {
  782. var arr = new Array(obj.length);
  783. for (var i = 0; i < obj.length; i++) {
  784. arr[i] = obj[i];
  785. }
  786. return arr;
  787. };
  788.  
  789. _.isString = function(obj) { return _.toString.call(obj) == '[object String]'; };
  790.  
  791. _.isNumber = function(obj) { return _.toString.call(obj) == '[object Number]'; };
  792.  
  793. _.isArray = Array.isArray || function(obj) {
  794. return _.toString.call(obj) === '[object Array]';
  795. };
  796.  
  797. _.isDate = function(obj) {
  798. return _.toString.call(obj) === '[object Date]';
  799. };
  800.  
  801. _.isElement = function(obj) {
  802. return !!(obj && obj.nodeType === 1);
  803. };
  804.  
  805. _.isPlainValue = function(obj) {
  806. var type;
  807. type = typeof obj;
  808. return (type !== 'object' && type !== 'function') || exports.isDate(obj);
  809. };
  810.  
  811. _.isBoolean = function(obj) {
  812. return obj === true || obj === false;
  813. };
  814.  
  815. module.exports = _;
  816.  
  817. },{}]},{},[1]);