leonidas / transparency

Transparency is a semantic template engine for the browser. It maps JSON objects to DOM elements by id, class and data-bind attributes.
http://leonidas.github.com/transparency/
MIT License
969 stars 112 forks source link

In-place element manipulation no longer possible #34

Closed miohtama closed 12 years ago

miohtama commented 12 years ago

This is regression from early Transparency versions.

html() directive should allow to take element node as input value for manipulation, so that user can run his/her custom crap over the element instead of generating HTML as text or DOM nodes.

Example use case:

       // Template directives
        var directives = {

            // Conditionally set CSS state to empty or not
            // whether we have any products in the list
            'checkout-list-root' : {

                html : function(elem) {
                    var $elem = $(elem);

                    // Set a CSS class which will determine
                    // whether we so "no items" or list view
                    if(data.count > 0) {
                        $elem.addClass("has-items");
                    } else {
                        $elem.removeClass("has-items");
                    }
                }
            },

(Though this is bad example as this could be now done with attribute API?)

Possible API implementations

If you provide green light for this after discussion I can provide patch

miohtama commented 12 years ago

To be precise, looks like this is issue only with html() + attributes, not when using plain functions as directives

pyykkis commented 12 years ago

Any directive function can now return void and Transparency skips the assignment.