@br0ken/simpletooltip
Advanced tools
Comparing version 3.3.1 to 3.3.2
@@ -6,3 +6,3 @@ { | ||
"license": "MIT", | ||
"version": "3.3.1", | ||
"version": "3.3.2", | ||
"homepage": "https://github.com/BR0kEN-/simpleTooltip", | ||
@@ -9,0 +9,0 @@ "description": "CSS tooltips with position control via JS.", |
@@ -17,5 +17,6 @@ /** | ||
* @typedef {Object} SimpleTooltip.Options | ||
* @property {String} [title] | ||
* @property {function(element: Element): Boolean} [hideIf] | ||
* @property {string} [title] | ||
* @property {function(element: Element): boolean} [hideIf] | ||
* @property {('nw'|'north'|'ne'|'west'|'east'|'sw'|'south'|'se')} shift | ||
* @property {boolean} destruct | ||
*/ | ||
@@ -54,13 +55,10 @@ | ||
// Set handlers for all elements having tooltips. | ||
hint.addEventListener('mouseover', function() { | ||
hint.simpleTooltipHandler = function() { | ||
if (typeof this.simpleTooltipHideIf === 'function') { | ||
if (this.simpleTooltipHideIf(this)) { | ||
this.removeAttribute(plugin.attrs.shift); | ||
return; | ||
} | ||
else { | ||
this.setAttribute(plugin.attrs.shift, this.simpleTooltipShift); | ||
} | ||
this.setAttribute(plugin.attrs.shift, this.simpleTooltipShift); | ||
} | ||
@@ -128,3 +126,6 @@ | ||
containers.css.innerHTML = style; | ||
}, false); | ||
}; | ||
// Set handlers for all elements having tooltips. | ||
hint.addEventListener(plugin.event, hint.simpleTooltipHandler, false); | ||
} | ||
@@ -136,2 +137,3 @@ | ||
var plugin = { | ||
event: 'mouseover', | ||
shifts: ['nw', 'north', 'ne', 'west', 'east', 'sw', 'south', 'se'], | ||
@@ -209,20 +211,22 @@ maxWidth: 300, | ||
try { | ||
options.title = options.title || element.getAttribute('title'); | ||
options.shift = plugin.shifts[ | ||
plugin.shifts.indexOf(options.shift || element.getAttribute(plugin.attrs.shift)) | ||
]; | ||
} catch (e) { | ||
continue; | ||
} | ||
if (options.destruct) { | ||
element.removeAttribute(plugin.attrs.shift); | ||
element.removeEventListener(plugin.event, element.simpleTooltipHandler); | ||
} else { | ||
try { | ||
options.title = options.title || element.getAttribute('title'); | ||
options.shift = plugin.shifts[ | ||
plugin.shifts.indexOf(options.shift || element.getAttribute(plugin.attrs.shift)) | ||
]; | ||
} catch (e) { | ||
continue; | ||
} | ||
if (options.shift && options.title) { | ||
if (typeof options.hideIf === 'function' && !options.hideIf(element)) { | ||
if (options.shift && options.title) { | ||
element.setAttribute(plugin.attrs.title, options.title); | ||
element.setAttribute(plugin.attrs.shift, options.shift); | ||
element.simpleTooltipHideIf = options.hideIf; | ||
element.simpleTooltipShift = options.shift; | ||
setup(element); | ||
} | ||
element.setAttribute(plugin.attrs.title, options.title); | ||
element.simpleTooltipHideIf = options.hideIf; | ||
element.simpleTooltipShift = options.shift; | ||
setup(element); | ||
} | ||
@@ -229,0 +233,0 @@ } |
79648
471