BS.Twipsy/Tooltip manual control possible?

69 views
Skip to first unread message

Rolf-nl

unread,
Feb 17, 2013, 10:57:01 AM2/17/13
to clien...@googlegroups.com
I need to open some tooltips currently setup with a BS.Tooltip behavior automatically as an info bubble to give the viewer some additional explanation without he/she hovering over an element.
Normally form another filter I'd to an api.fireEvent('stateXYZ') that my other filter can listen to and perhaps do something. But I don't think the current implementation of BS.Tooltip allows this, correct?
I could create a new filter that also sets up the Bootstrap.Tooltip with some additional code for handling api calls and doing a manual show/hide of the tip element, but I am not sure if I can also use the current Behavior.BS.Tooltip code and use it more efficiently?

If this makes sense... haha

Rolf-nl

unread,
Feb 17, 2013, 11:28:15 AM2/17/13
to clien...@googlegroups.com
Oh yes, what I am doing now for dirty mockup testing out an interface idea is:

var behaviors = myElement.getBehaviors();
if (behaviors.contains('BS.Tooltip')){
    var tip = myElement.getBehaviorResult('BS.Tooltip');
    tip.show();
}

I think this is proper use of the getBehaviorResult method even though I am coding this into some other filter mixing up one filter with the tooltip filter

Aaron Newton

unread,
Feb 17, 2013, 2:48:11 PM2/17/13
to clien...@googlegroups.com
The solution here is a filter plugin. Plugins are always run after the filter they augment and are handed the instance that is created. So, using this, you could, for example, have a plugin for BS.Tooltip that checks for some other property or setting and automatically shows it on startup. I don't have a ton of examples of this in public repositories, but here's one from Bootstrap: https://github.com/anutron/mootools-bootstrap/blob/master/Source/Behaviors/Behavior.BS.FormValidator.js#L39

Your code would define a new plugin and then reference the instance and call .show() if the api has some flag set to true.

Note that the API handed to this plugin is the plugin's, not the filter it augments. I.e. if you have a filter called Foo and you create a filter that augments Foo with Bar, the API handed to your plugin is for Bar (data-bar-options, etc), not Foo. If you want to drop your flag into the Foo options, you'll need to grab those values with a new instance of BehaviorAPI:

Behavior.addGlobalPlugin("Foo", "Bar", {
setup: function(element, apiForBar, instanceOfFoo){
var apiForFoo = new BehaviorAPI(element, 'Foo');
//check for the flag on either api
var autoShow = apiForBar.get('showOnStart') || apiForFoo.get('showOnStart');
if (autoShow) instanceOfFoo.show();
}
});

--
You received this message because you are subscribed to the Google Groups "Clientcide" group.
To unsubscribe from this group and stop receiving emails from it, send an email to clientside+...@googlegroups.com.
To post to this group, send email to clien...@googlegroups.com.
Visit this group at http://groups.google.com/group/clientside?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Rolf-nl

unread,
Feb 24, 2013, 7:59:02 AM2/24/13
to clien...@googlegroups.com
Thanks, I understand. Playing with this and testing it in a prototype though I see how this won't work in my case.
One reason is that the BS.Tooltip filter has a delayUntil setting, so the behavior doesn't get created until hover or focus. So that would mean to create a new Filter (basically a copy without that setting). I tried using a mock event to see if faking a mouseover/focus would work, but it doesn't work really.
A second reason is that a tooltip is not the best use for this (my) case. I probably need a more custom popover with close button or something like that to act as an advice-thingy. It can probably be based on the tooltip though.

Aaron Newton

unread,
Feb 24, 2013, 2:07:37 PM2/24/13
to clien...@googlegroups.com
Well, that seems odd to me. What's the point of delayUntil if you want to show it on startup? It's contradictory...

Rolf-nl

unread,
Feb 25, 2013, 4:25:28 PM2/25/13
to clien...@googlegroups.com
The BS.Tooltip has a delayUntil setting, so there's no instance created from the start, correct? Show you can't show it on startup if you wanted to, instance.show doesn't exist yet. I think I tried it, it only worked if I removed the delayUntil setting in the Tooltip behavior filter code.

In my case, it's not really on startup that I need it. I need to show it after some other action. Like the user selects a certain option from a select dropdown and then there's an additional select with the advice/info attached what the extra select is about. I can do this with a plugin (the plugin listens to an api event) that shows the tooltip on command, but the tooltip by itself is not the correct "bootstrap plugin" I need in this case (I need a close button for example).

Aaron Newton

unread,
Feb 25, 2013, 6:58:48 PM2/25/13
to clien...@googlegroups.com
My point is that delayUntil + showOnStartup makes no sense. I'd have to go dig into the code, but there's probably some way you can manually kick off the filter to instantiate it for your custom event... Look at the showOnStartup code.

Rolf-nl

unread,
Feb 27, 2013, 2:13:32 PM2/27/13
to clien...@googlegroups.com
I follow you, but I don't follow you ;)
Reply all
Reply to author
Forward
0 new messages