First, I *strongly* recommend that you read the docs for Behavior
carefully. It's a very elegant system that I've used for a while now and
it's very robust, but it does have a learning curve.

I'm having some trouble parsing your questions, but I'll do my best to
answer them.

On Mon, Sep 2, 2013 at 11:31 AM, underscore_05
<[email protected]>wrote:

> Hello, I am experimenting with you Behavior and Delegator.
> Your mootools-bootstrap has only one example on how to use Delegator and
> Behavior in combination (showPop + BS.Popup).
> Now, since i am still studying. I want to create a delegator for the
> BS.Popover behavior by creating new based from the showPop delegator.
>

You should look at the other delegators (there's lots more in the
more-behaviors repo: https://github.com/anutron/more-behaviors)  to get a
feel for how they work, but the key thing to remember is that
Behaviors *instantiate
things* while Delegators *react to use behavior*. So if you want to watch
for clicks or submissions or whatever, that's going to be Delegator, but if
you have a widget that needs to be instantiated, that's Behavior. There's
also a primary rule that the different filters (Behavior) and triggers
(Delegator) don't know about each other and they aren't order dependent.

Anyway, looking at your code, the conflict is arising because I've delayed
instantiating the popup until the popop element is moused over (
https://github.com/anutron/mootools-bootstrap/blob/master/Source/Behaviors/Behavior.BS.Popover.js#L36).
So your trigger is attempting to invoke a method on a class that hasn't
been instantiated yet (the console echos: Could not apply the trigger
BS.showPopover Cannot call method 'show' of null).

Here's a version that does work: http://jsfiddle.net/URKSB/1/

But it's not ideal. This particular filter with it's built in delay (which
is done for optimization purposes, tooltips and popovers are generally
never displayed if they aren't moused-over, and a page with hundreds of
them might load sluggishly. further, delegating on mouseover has big
performance issues, so you have to add the event to each element itself...)
is problematic. Most of them don't do this.


> The "Show Popover" button only works when I hover/unhover first on the
> Element with Popover behavior.
> here's the fiddle http://jsfiddle.net/URKSB/
>
> BTW. Another problem I encounter is that link.getElement() dont get any
> element by passing #{target element} or .{target element} instead it
> returns element by !+#{target element} since the target element is a
> previous sibling of the triggered element.
>

As pointed out in the docs, all selectors (by convention) are relative to
the element with the filter on them, so
myElement.getElements(api.get('someTarget')) means that it looks for
children of myElement unless you do some sort of !selector (e.g. !body
#foo). This is for consistency's sake.

Also note that the api object has two helpers for this -
api.getElement('optionName') and api.getElements('optionName'). This allows
you to just do:

var target = api.getElement('target');

If the element is not found, the filter stops executing and an error is
thrown in the console. You can optionally pass in 'warn' in as a second
argument in which case the error is posted to console as a warning and
execution is NOT stopped.

-- 

--- 
You received this message because you are subscribed to the Google Groups 
"MooTools Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to