enyo / opentip

Opentip is an open source javascript tooltip based on the protoype framework.
http://www.opentip.org
1.25k stars 401 forks source link

HTML elements as tolltip content #64

Open Burtsev-Alexey opened 11 years ago

Burtsev-Alexey commented 11 years ago

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.

Burtsev-Alexey commented 11 years ago

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); }

deckchairhq commented 10 years ago

+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?

dotob commented 9 years ago

+1

BenAlthauser commented 9 years ago

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.

dscafati commented 9 years ago

+1

tonosama-atlacatl commented 7 years ago

+1

scotchi commented 7 years ago

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).