opentip
opentip copied to clipboard
HTML elements as tolltip content
Currently it is impossible to pass HTML elements as a content, only html string. I want to subscribe to some events fired by tool tip content, ie I have a button inside tool tip. The only way to achieve this currently, is to inline javascript in html string, and that's very limiting.
I want to be able to create HTML elements subscribe to event's, and pass this object to be attached to document object model.
Currently I'm using fixed code: in _updateElementContent if (this.content instanceof Node) { this.adapter.empty(contentDiv); this.adapter.append(contentDiv, this.content); } else this.adapter.update(contentDiv, this.content, this.options.escapeContent); }
+1 - It's a quick addition, why don't we merge that exact snippet in, leave it undocumented so we can spend some time playing around, check if there are any usage concerns, then officially document and support it in the release thereafter?
+1
I just edited the opentip-jquery.js file, and have it allowing html elements
Basically I am appending into a div wrapper to get it to work. It's not in coffeescript btw. I did have to comment an if statement to get it to work. edit occurs around line 109.
//Commented out to see if I can get object html to work
// if (typeof content === "object") {
//options = content;
//content = title = void 0;
//}
//Added these lines
HTMLObjectContainer = document.createElement('div');
jQuery(HTMLObjectContainer).append(content);
content = HTMLObjectContainer;
all of the event handlers i created, such as 'elementName.onclick =' carried over as well.
+1
+1
While it's a bit convoluted, if you pass the content as a function that returns a DOM element, e.g.:
var content = function() { return document.createElement("h1"); };
$("#foo").opentip(content);
Works just fine. That's because Opentip uses jQuery.html() internally, which happens to work with HTML elements, and passing in a function bypasses some of Opentips attempted cleverness (which looks like it was there to make non-options arguments to the constructor optional).