@@ -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} ) ; 
0 commit comments