Skip to content

Commit d44727a

Browse files
committed
Merge branch 'jmagnusson-accept-dom-element'
2 parents d39e31b + fb26b27 commit d44727a

7 files changed

Lines changed: 56 additions & 5 deletions

File tree

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@ isotip.positionTooltip( '.tooltip', '.tooltip-click', 'left' );
131131

132132
## Changelog
133133

134+
- 1.2.6 - Support passing in a DOM element to content
134135
- 1.2.2 - Fixes an edge case when trying to close a tooltip and it didn't exist
135136
- 1.2.0 - Adds a scrollContainer option for tooltips inside scolling elements
136137
- 1.1.2 - Reduces the default tooltip removal delay to 200ms

dist/isotip.js

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,9 @@ module.exports = {
301301

302302
// If the supplied string should be interpreted as html, make an element for it...
303303
if ( ( this.options.html || html ) && content ) {
304-
if ( this.getTagName( content )) {
304+
if ( this.isElement( content )) {
305+
tooltipContent = content;
306+
} else if ( this.getTagName( content )) {
305307
tooltipContent = this.createDOMElement( content );
306308
} else {
307309
tooltipContent = this.createDOMElement( '<p class="tooltip-content">' + content + '</p>' );
@@ -339,7 +341,7 @@ module.exports = {
339341
this.currentTooltip = this.currentContainer.appendChild( tooltip );
340342
}
341343

342-
this.currentTrigger = trigger
344+
this.currentTrigger = trigger;
343345

344346
// Position the tooltip on the page
345347
this.positionTooltip( this.currentTooltip, this.currentTrigger, placement );
@@ -831,6 +833,23 @@ module.exports = {
831833
return /<([\w:]+)/.exec( html );
832834
},
833835

836+
/**
837+
* isElement - Small function to determine if object is a DOM element.
838+
* @version 1.2.6
839+
* @example
840+
* this.isElement( '<div></div>' ); # false
841+
* @example
842+
* this.isElement( this.createElement('div') ); # true
843+
* @param {string} obj - The object to check
844+
* @return {boolean} - Whether or not the object is a DOM element.
845+
* @api private
846+
*/
847+
isElement: function getTagName( obj ) {
848+
'use strict';
849+
850+
return !!( obj && obj.nodeType === 1 );
851+
},
852+
834853
/**
835854
* createDOMElement - Small function to transform an html string into an element
836855
* @version 1.0.0

dist/isotip.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

isotip.js

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,9 @@ module.exports = {
300300

301301
// If the supplied string should be interpreted as html, make an element for it...
302302
if ( ( this.options.html || html ) && content ) {
303-
if ( this.getTagName( content )) {
303+
if ( this.isElement( content )) {
304+
tooltipContent = content;
305+
} else if ( this.getTagName( content )) {
304306
tooltipContent = this.createDOMElement( content );
305307
} else {
306308
tooltipContent = this.createDOMElement( '<p class="tooltip-content">' + content + '</p>' );
@@ -830,6 +832,23 @@ module.exports = {
830832
return /<([\w:]+)/.exec( html );
831833
},
832834

835+
/**
836+
* isElement - Small function to determine if object is a DOM element.
837+
* @version 1.2.6
838+
* @example
839+
* this.isElement( '<div></div>' ); # false
840+
* @example
841+
* this.isElement( this.createElement('div') ); # true
842+
* @param {string} obj - The object to check
843+
* @return {boolean} - Whether or not the object is a DOM element.
844+
* @api private
845+
*/
846+
isElement: function getTagName( obj ) {
847+
'use strict';
848+
849+
return !!( obj && obj.nodeType === 1 );
850+
},
851+
833852
/**
834853
* createDOMElement - Small function to transform an html string into an element
835854
* @version 1.0.0

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "isotip",
3-
"version": "1.2.5",
3+
"version": "1.2.6",
44
"description": "The javascript tooltip plugin with no dependencies",
55
"main": "isotip.js",
66
"repository": "https://github.com/datuhealth/isotip",

test/index.html

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@
4646
<div>
4747
<span class="tooltip-click tooltip-left-edge" data-tooltip-content="Test content" data-tooltip-placement="left">This is a tooltip too far to the left</span>
4848
</div>
49+
<div class="tooltip-empty-insert-point">
50+
</div>
4951
<div class="scroll-container" style="overflow:scroll;height:300px;">
5052
<div class="tooltip-container" style="height: 600px;">
5153
<span class="tooltip-click button tooltip-scroll-container" style="margin-top: 100px;display:block;" data-tooltip-content="I'm In a scrolling container!" data-tooltip-placement="top" data-tooltip-container=".scroll-container" data-tooltip-scrollContainer=".scroll-container">In a scrolling container</span>

test/index.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,16 @@ describe( 'tooltip markup', function() {
8585
expect( tooltipTmp.childNodes[ 1 ].tagName ).to.equal( 'SPAN' );
8686
expect( tooltipTmp.childNodes[ 1 ] instanceof Element ).to.equal( true );
8787
});
88+
89+
it( 'should accept a DOM Element', function() {
90+
isotipJS.init();
91+
92+
var selector = '.tooltip-empty-insert-point',
93+
el = document.createElement( 'p' ),
94+
config = { html: true, content: el },
95+
tooltipTmp = isotipJS.open( selector, config );
96+
expect( tooltipTmp.childNodes[ 1 ].tagName ).to.equal( 'P' );
97+
});
8898
});
8999

90100
describe( 'tooltip options', function() {

0 commit comments

Comments
 (0)