Skip to content

Commit fa52e2c

Browse files
committed
SVG fixes
1 parent 807bbf4 commit fa52e2c

File tree

5 files changed

+63
-17
lines changed

5 files changed

+63
-17
lines changed

demo/index.html

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,11 @@
247247
.tooltipster({
248248
theme: 'tooltipster-shadow'
249249
});
250+
251+
$('#circle circle').tooltipster({
252+
restoration: 'previous'
253+
});
254+
$('#circle tspan').tooltipster();
250255
});
251256
</script>
252257
</head>
@@ -307,6 +312,16 @@
307312
SVG
308313
<div id="genderChart1"></div>
309314
<div id="drawing"></div>
315+
<svg id="circle">
316+
<text y="20">
317+
<tspan x="10" title="line 1">tspan line 1</tspan>
318+
<tspan x="10" dy="15" title="line 2">tspan line 2</tspan>
319+
<tspan x="10" dy="15" title="line 3">tspan line 3</tspan>
320+
</text>
321+
<circle cx="150" cy="50" r="40" stroke="black" stroke-width="3" fill="red">
322+
<title>Circle</title>
323+
</circle>
324+
</svg>
310325
</section>
311326
</body>
312327
</html>

demo/style.css

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,12 @@ body {
3636
color: #fff;
3737
}
3838

39+
#circle {
40+
display: block;
41+
margin: auto;
42+
position: relative;
43+
}
44+
3945
#genderChart1 {
4046
height: 300px;
4147
width: 300px;

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,5 +41,5 @@
4141
"scripts": {
4242
"test": "echo \"Error: no test specified\" && exit 1"
4343
},
44-
"version": "4.0.1"
44+
"version": "4.0.2"
4545
}

src/js/plugins/tooltipster/SVG/tooltipster-SVG.js

Lines changed: 32 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ $.tooltipster._plugin({
2525
var self = this;
2626

2727
//list of instance variables
28+
self.__hadTitleTag = false;
2829
self.__instance = instance;
2930

3031
// jQuery < v3.0's addClass and hasClass do not work on SVG elements.
@@ -44,10 +45,17 @@ $.tooltipster._plugin({
4445
// TODO: when there are several <title> tags (not supported in
4546
// today's browsers yet though, still an RFC draft), pick the right
4647
// one based on its "lang" attribute
47-
var $title = self.__instance._$origin.find('title');
48+
var $title = self.__instance._$origin.find('>title');
4849

4950
if ($title[0]) {
50-
self.__instance.content($title.text());
51+
52+
var title = $title.text();
53+
54+
self.__hadTitleTag = true;
55+
self.__instance._$origin.data('tooltipster-initialTitle', title);
56+
self.__instance.content(title);
57+
58+
$title.remove();
5159
}
5260
}
5361

@@ -83,18 +91,35 @@ $.tooltipster._plugin({
8391
})
8492
// if jQuery < v3.0, we have to remove the class ourselves
8593
._on('destroyed.'+ self.namespace, function() {
86-
self.destroy();
94+
self.__destroy();
8795
});
8896
},
8997

9098
__destroy: function() {
9199

92-
if (!self.__instance._$origin.hasClass('tooltipstered')) {
93-
var c = self.__instance._$origin.attr('class').replace('tooltipstered', '');
94-
self.__instance._$origin.attr('class', c);
100+
if (!this.__instance._$origin.hasClass('tooltipstered')) {
101+
var c = this.__instance._$origin.attr('class').replace('tooltipstered', '');
102+
this.__instance._$origin.attr('class', c);
95103
}
96104

97-
self.__instance._off('.'+ self.namespace);
105+
this.__instance._off('.'+ this.namespace);
106+
107+
// if the content was provided as a title tag, we may need to restore it
108+
if (this.__hadTitleTag) {
109+
110+
// if a title attribute was restored, we just need to replace it with a tag
111+
var title = this.__instance._$origin.attr('title');
112+
113+
if (title) {
114+
115+
// must be namespaced to work
116+
$(document.createElementNS('http://www.w3.org/2000/svg', 'title'))
117+
.text(title)
118+
.appendTo(this.__instance._$origin);
119+
120+
this.__instance._$origin.removeAttr('title');
121+
}
122+
}
98123
}
99124
}
100125
});

src/js/tooltipster.js

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2446,13 +2446,6 @@ $.Tooltipster.prototype = {
24462446
self.__destroying = false;
24472447
self.__destroyed = true;
24482448

2449-
// last event
2450-
self._trigger('destroyed');
2451-
2452-
// unbind private and public event listeners
2453-
self._off();
2454-
self.off();
2455-
24562449
self._$origin
24572450
.removeData(self.__namespace)
24582451
// remove the open trigger listeners
@@ -2506,13 +2499,20 @@ $.Tooltipster.prototype = {
25062499
}
25072500
}
25082501

2502+
// last event
2503+
self._trigger('destroyed');
2504+
2505+
// unbind private and public event listeners
2506+
self._off();
2507+
self.off();
2508+
25092509
// remove external references, just in case
25102510
self.__Content = null;
2511-
self._$origin = null;
25122511
self.__$emitterPrivate = null;
25132512
self.__$emitterPublic = null;
2514-
self._$tooltip = null;
25152513
self.__options.parent = null;
2514+
self._$origin = null;
2515+
self._$tooltip = null;
25162516

25172517
// make sure the object is no longer referenced in there to prevent
25182518
// memory leaks

0 commit comments

Comments
 (0)