From 6697f2027cdaa62b705c7f2511290a482757baf3 Mon Sep 17 00:00:00 2001 From: Ben Davis Date: Fri, 21 Jun 2013 18:11:53 -0600 Subject: [PATCH] Updated detailsHTML option to double as callback function This should allow the hovercard to be populated with various HTML dependent on selector attributes. Can be accessed from callback function via this or as arg[0]. --- jquery.hovercard.js | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/jquery.hovercard.js b/jquery.hovercard.js index 2801eb0..2ff2a3c 100644 --- a/jquery.hovercard.js +++ b/jquery.hovercard.js @@ -114,8 +114,17 @@ hcImg = ''; } + //Determine if detailsHTML is a callable function + var detailsHTML = ''; + if($.isFunction(options.detailsHTML)){ + //if so, call the function with the current object as the "this" value and argument, and update detailsHTML + detailsHTML = options.detailsHTML.call(obj, obj); + }else{ + detailsHTML = options.detailsHTML; + } + //generate details span with html provided by the user - var hcDetails = '
' + hcImg + options.detailsHTML + '
'; + var hcDetails = '
' + hcImg + detailsHTML + '
'; //append this detail after the selected element obj.after(hcDetails); @@ -360,4 +369,4 @@ }); }; -})(jQuery); \ No newline at end of file +})(jQuery);