Skip to content

Instantly share code, notes, and snippets.

@staaky
Created January 10, 2011 14:29
Show Gist options
  • Save staaky/772825 to your computer and use it in GitHub Desktop.
Save staaky/772825 to your computer and use it in GitHub Desktop.
/* A quick parent/child helper idea for tipped.js
* blocks parent tooltips from hiding when child tooltips are open
* http://groups.google.com/group/tippedjs/browse_thread/thread/29a65b3a4c0a37df
*/
(function($) {
window.TippedParentChildHelper = {
showChild: function(content, element) {
var parent = element.getAttribute('data-tipped-parent');
if (parent) {
var vc = $('#' + parent).data('tipped_visible_children') || 0;
$('#' + parent).data('tipped_visible_children', vc++);
}
},
hideChild: function(content, element) {
var parent = element.getAttribute('data-tipped-parent');
if (parent) {
var vc = $('#' + parent).data('tipped_visible_children') || 1;
$('#' + parent).data('tipped_visible_children', vc--);
}
},
hideParent: function(content, element) {
if ($(element).data('tipped_visible_children')) > 0) {
Tipped.show(element);
}
}
};
})(jQuery);
// then on the child tooltips
data-tipped-parent='id_of_parent'
data-tipped-options="
onShow: TippedParentChildHelper.showChild,
onHide: TippedParentChildHelper.hideChild
"
/* On the parent tooltips to block hiding when
* child tooltips are open:
* fadeDuration is set to 0 otherwise the tooltip
*/ will first fade out on browsers that support it
id='id_of_parent',
data-tipped-options="
fadeDuration: 0,
onHide: TippedParentChildHelper.hideParent
"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment