I wrote the following extension to the JQuery UI tooltip widget that allows the tooltip to have context on getting its content from a HTMLElement's html. However, I have the 'title' attribute hard coded but I would like to use whatever attribute is defined in options.items. For example if they want the tooltip to use alt tag then the extention populates that attribute with the html content.
Also I am looking for the jquery ui way of correctly escaping the contentIdstring concatenation
$(function() {
(function() {
var cache = {};
$.widget("custom.tooltipContent", $.ui.tooltip, {
_init: function() {
this._super();
this.options.content = function() {
return $(this).attr("title");
};
this.element.attr("title", function() {
var contentId = $(this).attr("data-tooltip-content");
if (!cache[contentId]) {
cache[contentId] = $("[data-tooltip-content-id=" + contentId + "]").remove().html();
}
return cache[contentId];
});
}
});
})();
});
http://jsfiddle.net/5d7sqx89/1/
from JQuery UI tooltip extension using options.items vs title
No comments:
Post a Comment