From f5dbd05f9e0a8610f4304b153ebc3cd18fbc324d Mon Sep 17 00:00:00 2001 From: HTMLGuyLLC Date: Tue, 15 Oct 2019 14:11:32 -0400 Subject: [PATCH] Pass btn and jtippy instance to title function --- README.md | 2 +- index.html | 2 +- jTippy.js | 2 +- jTippy.min.js | 2 +- package.json | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 35fc2b9..e3be842 100755 --- a/README.md +++ b/README.md @@ -67,7 +67,7 @@ Defaults are shown ```javascript $(function(){ $('[data-toggle="tooltip"]').jTippy({ - //string/function returning string: overridden by the title attribute - function is run every time the tooltip is displayed and can be used to grab content via XHR/AJAX + //string/function(btn, jtippy):string returning string: overridden by the title attribute - function is run every time the tooltip is displayed and can be used to grab content via XHR/AJAX title: '', //string ('click', 'hover', 'focus', 'hoverfocus'): defines when the tooltip should be shown trigger: 'hoverfocus', diff --git a/index.html b/index.html index 78f7043..a14bafd 100755 --- a/index.html +++ b/index.html @@ -180,7 +180,7 @@

All options and events with defaults:


     $(function(){
       $('[data-toggle="tooltip"]').jTippy({
-            //string/function returning string: overridden by the title attribute - function is run every time the tooltip is displayed and can be used to grab content via XHR/AJAX
+            //string/function(btn, jtippy):string - overridden by the title attribute - function is run every time the tooltip is displayed and can be used to grab content via XHR/AJAX
             title: '',
             //string ('click', 'hover', 'focus', 'hoverfocus'): defines when the tooltip should be shown
             trigger: 'hoverfocus',
diff --git a/jTippy.js b/jTippy.js
index dcb8ada..3449cc4 100755
--- a/jTippy.js
+++ b/jTippy.js
@@ -216,7 +216,7 @@
                 }
                 //get string from function
                 if( typeof trigger_event === 'undefined' || trigger_event ){
-                    if( typeof helper.title === 'function' ) helper.content = helper.title();
+                    if( typeof helper.title === 'function' ) helper.content = helper.title(helper.dom_wrapped, helper);
                 }
                 //add the tooltip to the dom
                 body.append(helper.createTooltipHTML());
diff --git a/jTippy.min.js b/jTippy.min.js
index 9ff8aad..478d987 100755
--- a/jTippy.min.js
+++ b/jTippy.min.js
@@ -5,4 +5,4 @@
 	https://htmlguy.com
 	MIT Licensed
 */
-(function(a){a.fn.jTippy=function(b){if(1
${f.content}
`},createBackdropHTML:function(){return!!f.backdrop&&`
`},destroy:function(){const b=f.dom_wrapped.data(f.dataAttr);"undefined"!=typeof b&&null!==b&&("click"===b.trigger?(b.dom_wrapped.off("touchstart mousedown",b.toggleTooltipHandler),b.dom_wrapped.off("click",b.preventDefaultHandler)):"focus"===b.trigger?(b.dom_wrapped.off("touchstart focus",b.show),b.dom_wrapped.off("touchend blur",b.hide)):"hover"===b.trigger?(b.dom_wrapped.off("touchstart mouseenter",b.show),b.dom_wrapped.off("touchend mouseleave",b.hide)):"hoverfocus"===b.trigger&&(b.dom_wrapped.off("focus",b.hoverfocusFocusShow),b.dom_wrapped.off("blur",b.hoverfocusBlur),b.dom_wrapped.off("touchstart mouseenter",b.show),b.dom_wrapped.off("touchend mouseleave",b.hoverfocusHide)),a(window).off("resize",b.onResize),b.isVisible()&&b.hide(),b.dom_wrapped.data(b.dataAttr,null))},initialize:function(){return"click"===f.trigger?(f.dom_wrapped.on("touchstart mousedown",f.toggleTooltipHandler),f.dom_wrapped.on("click",f.preventDefaultHandler)):"focus"===f.trigger?(f.dom_wrapped.on("touchstart focus",f.show),f.dom_wrapped.on("touchend blur",f.hide)):"hover"===f.trigger?(f.dom_wrapped.on("touchstart mouseenter",f.show),f.dom_wrapped.on("touchend mouseleave",f.hide)):"hoverfocus"===f.trigger&&(f.dom_wrapped.on("focus",f.hoverfocusFocusShow),f.dom_wrapped.on("blur",f.hoverfocusBlur),f.dom_wrapped.on("touchstart mouseenter",f.show),f.dom_wrapped.on("touchend mouseleave",f.hoverfocusHide)),a.jTippy.body_click_initialized||(a(document).on("touchstart mousedown",f.onClickOutside),a.jTippy.bodyClickInitialized=!0),f.dom_wrapped.data(f.dataAttr,f),f.dom},hoverfocusFocusShow:function(){f.dom_wrapped.addClass("jt-focused"),f.show()},hoverfocusBlur:function(){f.dom_wrapped&&f.dom_wrapped.length&&f.dom_wrapped.removeClass("jt-focused"),f.hide()},hoverfocusHide:function(){return!f.dom_wrapped.hasClass("jt-focused")&&void f.hide()},preventDefaultHandler:function(a){return a.preventDefault(),!1},toggleTooltipHandler:function(a){return a.preventDefault(),f.isVisible()&&f.hide()||f.show(),!1},show:function(b){if(f.isVisible())return!1;f.singleton&&f.hideAllVisible();const c=a("body");"blurred"===f.backdrop?c.addClass("jt-blurred-body"):f.backdrop&&c.append(f.createBackdropHTML()),("undefined"==typeof b||b)&&"function"==typeof f.title&&(f.content=f.title()),c.append(f.createTooltipHTML()),f.tooltip=a(".jtippy:last"),f.positionTooltip(),a(window).on("resize",f.onResize);const d="jTippy"+Date.now();f.tooltip.attr("id",d),f.dom.attr("aria-describedby",d),a.jTippy.visible.push(f),("undefined"==typeof b||b)&&f.dom.trigger("jt-show",[f.tooltip,f.hide]),a("body").on("DOMSubtreeModified",f.positionTooltip)},isVisible:function(){return-1c&&(f.positionDebug("Element is less than "+c+"px. Setting arrow to hug the side tighter"),b+=" jt-arrow-super-hug"),a.addClass("jt-arrow-"+b),f.positionDebug("-- Done positioning --"),f)},calculateSafePosition:function(a){let b=f.tooltip.find(".jt-arrow"),c=f.dom_wrapped.offset(),d=f.dom_wrapped.outerHeight(),e=f.dom_wrapped.outerWidth(),g=f.tooltip.outerWidth(),h=f.tooltip.outerHeight(),i=document.querySelector("body").offsetWidth,j=document.querySelector("body").offsetHeight,k=b.is(":visible")?b.outerHeight():0,l=b.is(":visible")?b.outerWidth():0,m={};m.below=5
${f.content}
`},createBackdropHTML:function(){return!!f.backdrop&&`
`},destroy:function(){const b=f.dom_wrapped.data(f.dataAttr);"undefined"!=typeof b&&null!==b&&("click"===b.trigger?(b.dom_wrapped.off("touchstart mousedown",b.toggleTooltipHandler),b.dom_wrapped.off("click",b.preventDefaultHandler)):"focus"===b.trigger?(b.dom_wrapped.off("touchstart focus",b.show),b.dom_wrapped.off("touchend blur",b.hide)):"hover"===b.trigger?(b.dom_wrapped.off("touchstart mouseenter",b.show),b.dom_wrapped.off("touchend mouseleave",b.hide)):"hoverfocus"===b.trigger&&(b.dom_wrapped.off("focus",b.hoverfocusFocusShow),b.dom_wrapped.off("blur",b.hoverfocusBlur),b.dom_wrapped.off("touchstart mouseenter",b.show),b.dom_wrapped.off("touchend mouseleave",b.hoverfocusHide)),a(window).off("resize",b.onResize),b.isVisible()&&b.hide(),b.dom_wrapped.data(b.dataAttr,null))},initialize:function(){return"click"===f.trigger?(f.dom_wrapped.on("touchstart mousedown",f.toggleTooltipHandler),f.dom_wrapped.on("click",f.preventDefaultHandler)):"focus"===f.trigger?(f.dom_wrapped.on("touchstart focus",f.show),f.dom_wrapped.on("touchend blur",f.hide)):"hover"===f.trigger?(f.dom_wrapped.on("touchstart mouseenter",f.show),f.dom_wrapped.on("touchend mouseleave",f.hide)):"hoverfocus"===f.trigger&&(f.dom_wrapped.on("focus",f.hoverfocusFocusShow),f.dom_wrapped.on("blur",f.hoverfocusBlur),f.dom_wrapped.on("touchstart mouseenter",f.show),f.dom_wrapped.on("touchend mouseleave",f.hoverfocusHide)),a.jTippy.body_click_initialized||(a(document).on("touchstart mousedown",f.onClickOutside),a.jTippy.bodyClickInitialized=!0),f.dom_wrapped.data(f.dataAttr,f),f.dom},hoverfocusFocusShow:function(){f.dom_wrapped.addClass("jt-focused"),f.show()},hoverfocusBlur:function(){f.dom_wrapped&&f.dom_wrapped.length&&f.dom_wrapped.removeClass("jt-focused"),f.hide()},hoverfocusHide:function(){return!f.dom_wrapped.hasClass("jt-focused")&&void f.hide()},preventDefaultHandler:function(a){return a.preventDefault(),!1},toggleTooltipHandler:function(a){return a.preventDefault(),f.isVisible()&&f.hide()||f.show(),!1},show:function(b){if(f.isVisible())return!1;f.singleton&&f.hideAllVisible();const c=a("body");"blurred"===f.backdrop?c.addClass("jt-blurred-body"):f.backdrop&&c.append(f.createBackdropHTML()),("undefined"==typeof b||b)&&"function"==typeof f.title&&(f.content=f.title(f.dom_wrapped,f)),c.append(f.createTooltipHTML()),f.tooltip=a(".jtippy:last"),f.positionTooltip(),a(window).on("resize",f.onResize);const d="jTippy"+Date.now();f.tooltip.attr("id",d),f.dom.attr("aria-describedby",d),a.jTippy.visible.push(f),("undefined"==typeof b||b)&&f.dom.trigger("jt-show",[f.tooltip,f.hide]),a("body").on("DOMSubtreeModified",f.positionTooltip)},isVisible:function(){return-1c&&(f.positionDebug("Element is less than "+c+"px. Setting arrow to hug the side tighter"),b+=" jt-arrow-super-hug"),a.addClass("jt-arrow-"+b),f.positionDebug("-- Done positioning --"),f)},calculateSafePosition:function(a){let b=f.tooltip.find(".jt-arrow"),c=f.dom_wrapped.offset(),d=f.dom_wrapped.outerHeight(),e=f.dom_wrapped.outerWidth(),g=f.tooltip.outerWidth(),h=f.tooltip.outerHeight(),i=document.querySelector("body").offsetWidth,j=document.querySelector("body").offsetHeight,k=b.is(":visible")?b.outerHeight():0,l=b.is(":visible")?b.outerWidth():0,m={};m.below=5