From 1cd5b0f1139885231797722d810e59a81016f82d Mon Sep 17 00:00:00 2001 From: jos Date: Tue, 30 Sep 2014 12:43:34 +0200 Subject: [PATCH] Fixed #355: Titles support HTML elements --- HISTORY.md | 1 + docs/network.html | 8 +++++--- lib/network/Popup.js | 14 ++++++++++---- 3 files changed, 16 insertions(+), 7 deletions(-) diff --git a/HISTORY.md b/HISTORY.md index 0e7c11ed..4afe6bab 100644 --- a/HISTORY.md +++ b/HISTORY.md @@ -5,6 +5,7 @@ http://visjs.org ### Network +- Title of nodes and edges can now be an HTML element too. - Renamed storePosition to storePositions. Added deprication message and old name still works. - Worked around hammer.js bug with multiple release listeners. - Improved cleaning up after manipulation toolbar. diff --git a/docs/network.html b/docs/network.html index 77f4c462..5b53977a 100644 --- a/docs/network.html +++ b/docs/network.html @@ -316,10 +316,11 @@ When using a DataSet, the network is automatically updating to changes in the Da title - string | function + string | function | Element no Title to be displayed when the user hovers over the node. - The title can contain HTML code. If using a function, returning undefined + The title can be an HTML element or a string containing plain text or HTML. + When title is a function, the returned result is displayed as tooltip, and returning undefined will prevent the tooltip from being displayed. @@ -428,7 +429,8 @@ When using a DataSet, the network is automatically updating to changes in the Da string | function no Title to be displayed when the user hovers over the edge. - The title can contain HTML code. If using a function, returning undefined + The title can be an HTML element or a string containing plain text or HTML. + When title is a function, the returned result is displayed as tooltip, and returning undefined will prevent the tooltip from being displayed. diff --git a/lib/network/Popup.js b/lib/network/Popup.js index 072d90d8..966f1c86 100644 --- a/lib/network/Popup.js +++ b/lib/network/Popup.js @@ -77,11 +77,17 @@ Popup.prototype.setPosition = function(x, y) { }; /** - * Set the text for the popup window. This can be HTML code - * @param {string} text + * Set the content for the popup window. This can be HTML code or text. + * @param {string | Element} content */ -Popup.prototype.setText = function(text) { - this.frame.innerHTML = text; +Popup.prototype.setText = function(content) { + if (content instanceof Element) { + this.frame.innerHTML = ''; + this.frame.appendChild(content); + } + else { + this.frame.innerHTML = content; // string containing text or HTML + } }; /**