weepy / o_O

Funnyface: HTML binding for teh lulz
http://weepy.github.com/o_O/
MIT License
149 stars 11 forks source link

dynamic binding to child html #41

Closed weepy closed 12 years ago

weepy commented 12 years ago

sometimes a binding might write html to an element and then we want to control the css of a child element. E.g.

<div data-bind='html: html;'></div>

o = {
  html: '<p></p>',
  paragraph_css: { color: 'red'}
}

bind(o, 'div')

question is - how to bind the paragraph_css to the <p> tag that's created ?

weepy commented 12 years ago

so binding markup could be like :

<div data-bind="html: html(); css('p'): paragraph_css()"></div>

but that seems a bit lame

weepy commented 12 years ago

alternatively the inserted html could have bound property:

<div data-bind="html: html();"></div>
...

object.
o_O.bind({
    html: function() {
      return "<p data-bind='css: paragraph_css()'></p>"
    }, 
    paragraph_css: function() { return { 
      color: 'red' 
    } 
}, 'div')

In this case we'd have to special case .html to rebind inserted HTML ?

weepy commented 12 years ago

or perhaps we could have expressions as attribute names:

<div data-bind="html: html(); find('p').css: paragraph_css()"></div>
weepy commented 12 years ago

should be able to do :

<div data-bind="html: html();"></div>
...

o_O.bind({
    html: function() {
      return "<p data-bind='css: paragraph_css()'></p>"
    }, 
    paragraph_css: function() { return { 
      color: 'red' 
    } 
}, 'div')
weepy commented 12 years ago

also could potentially get access to o_O.current.$el and o_O.current.context