DracoBlue / jsb

A very extendable Toolkit to inject Javascript Behaviour into rendered HTML without Inline Javascript. (jsb was formerly known as JsBehaviourToolkit)
http://dracoblue.net
Other
52 stars 8 forks source link

Multiple behaviours on one Element #16

Closed DracoBlue closed 10 years ago

DracoBlue commented 10 years ago

Currently only one element is possible, but it should be possible to add multiples.

@eberdt use case is:

<input type="text" class="jsb_ jsb_idValidator jsb_referenceBrowser"/>
selfawaresoup commented 10 years ago

What would be a practical example use case for this?

selfawaresoup commented 10 years ago

Wouldn't it be simpler and easier to maintain, if there was just one JSB that would wrap both of the required behaviors? Especially since this example sounds like the order of execution is important (validation before reference browser).

eberdt commented 10 years ago

on the element one both behaviours are appended on the other element i had only one behaviour of them. I can create a wrapper behaviour but it will be hard for situation like this one where you render dynamic the behaviours to the element:

<div class="jsb_ jsb_BehaviourOne jsb_BehaviourTwo">...</div>
<div class="jsb_ jsb_BehaviourOne jsb_BehaviourThree">...</div>
<div class="jsb_ jsb_BehaviourTwo jsb_BehaviourThree">...</div>
<div class="jsb_ jsb_BehaviourTwo">...</div>
DracoBlue commented 10 years ago

We have some options to add data values for those.

Here are 2, which @eberdt and I made up while discussing:

First: Use data-jsb-behaviour-name="key=value" and data-jsb as "fallback"

<div class="jsb_ jsb_idValidator jsb_browser/referenceBrowser" data-jsb-browser-referenceBrowser="key=value"></div>

Second: Use a specific MultipleBehaviours behaviour

class=jsb_ jsb_MultipleBehaviours
data-jsb={"referenceBrowser": {"key":"value"}, "blink": {"key2":"key3"}}

What do you think?

graste commented 10 years ago

I'd rather not have different support for key/value or json data depending on one or multiple behaviours being present. It should be consistent everywhere (usage/feature wise).

How about one data attribute per behaviour with fallback to data-jsb when no specific data-jsb-* attribute exists:

<div class="jsb_ jsb_Foo jsb_Core/Bar" data-jsb-foo="..." data-jsb-core-bar="..." />

<div class="jsb_ jsb_One jsb_Core/Two" data-jsb-one="..." data-jsb="..." />

That way developers have the ability to just put everything into data-jsb and if behaviours start to have different options they can get that without a BC break.

axten commented 10 years ago

I agree with @graste.

larslaade commented 10 years ago

I agree with @graste, too