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