transparency.coffee | |
|---|---|
| Transparency is a client-side template engine which binds JSON objects to DOM elements.
This documentation focuses on the implementation and internals. For the full API reference, please see the README. | |
Public API | Transparency = @Transparency = {} |
|
| Transparency.render = (context, models = [], directives = {}, options = {}) -> |
| First, check if we are in debug mode and if so, log the arguments. | log = if options.debug and console then consoleLogger else nullLogger
log "Transparency.render:", context, models, directives, options
return unless context
models = [models] unless isArray models |
| Context element, state and functionality is wrapped to | context = data(context).context ||= new Context(context) |
| Rendering is a lot faster when the context element is detached from the DOM, as reflow calculations are not triggered. So, detach it before rendering. | context.render(models, directives, options).el |
Configuration | |
| In order to use Transparency as a jQuery plugin, add Transparency.jQueryPlugin to jQuery.fn object. | Transparency.jQueryPlugin = chainable (models, directives, options) ->
for context in this
Transparency.render context, models, directives, options |
| By default, Transparency matches model properties to elements by | Transparency.matcher = (element, key) ->
element.el.id == key ||
key in element.classNames ||
element.el.name == key ||
element.el.getAttribute('data-bind') == key |
| IE6-8 fails to clone nodes properly. By default, Transparency uses jQuery.clone() as a shim.
Override | Transparency.clone = onlyWith$ -> (node) -> $(node).clone()[0]
onlyWith$ -> $.fn.render = Transparency.jQueryPlugin
if define?.amd then define -> Transparency
|