From 20b9e11cca78a7642c42dcaa3987b757058bdab6 Mon Sep 17 00:00:00 2001 From: HTMLGuyLLC Date: Tue, 10 Sep 2019 17:30:02 -0400 Subject: [PATCH] Added data attributes for buttons --- README.md | 12 ++++++++++-- index.html | 8 ++++++++ jConfirm.js | 11 ++++++++++- jConfirm.min.js | 4 ++-- package.json | 2 +- 5 files changed, 31 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index bc8b631..5650c6e 100755 --- a/README.md +++ b/README.md @@ -216,19 +216,27 @@ $('.social-share').jConfirm({ { text:'Facebook', event:'facebook-share', + data: { + some_data_attr: 1 + }, class:'facebook-btn jc-button-highlight' }, { text:'Twitter', event:'twitter-share', + data: { + some_data_attr: 2 + }, class:'twitter-btn jc-button-highlight' } ] -}).on('facebook-share', function(e){ +}).on('facebook-share', function(e, data){ var btn = $(this); + var data_attr = btn.data('some_data_attr'); //1 console.log('Sharing to facebook: '+btn.data('url-to-share')); -}).on('twitter-share', function(e){ +}).on('twitter-share', function(e, data){ var btn = $(this); + var data_attr = btn.data('some_data_attr'); //2 console.log('Sharing to twitter: '+btn.data('url-to-share')); }); ``` diff --git a/index.html b/index.html index 83b490d..92f3895 100755 --- a/index.html +++ b/index.html @@ -335,16 +335,23 @@

Social Media Sharing:

{ text:'<i class="fa fa-facebook"></i> Facebook', event:'facebook-share', + data: { + some_data_attr: 1 + }, class:'facebook-btn' }, { text:'<i class="fa fa-twitter"></i> Twitter', event:'twitter-share', + data: { + some_data_attr: 2 + }, class:'twitter-btn' } ] }).on('facebook-share', function(e){ var btn = $(this); + var data_attr = btn.data('some_data_attr'); //1 var url = 'http://www.facebook.com/sharer.php?u='+btn.data('url-to-share'); window.open( url, @@ -352,6 +359,7 @@

Social Media Sharing:

); }).on('twitter-share', function(e){ var btn = $(this); + var data_attr = btn.data('some_data_attr'); //2 var url = 'http://twitter.com/share?text=This%20is%20the%20best!&url='+btn.data('url-to-share'); window.open( url, diff --git a/jConfirm.js b/jConfirm.js index ecc00e0..bb1abee 100755 --- a/jConfirm.js +++ b/jConfirm.js @@ -85,7 +85,16 @@ //loop through buttons and add to html $.each(helper.btns, function(key,btn){ html += `
- ${btn.text} + ${btn.text}
`; }); diff --git a/jConfirm.min.js b/jConfirm.min.js index 5fd94b8..0013a4e 100755 --- a/jConfirm.min.js +++ b/jConfirm.min.js @@ -6,6 +6,6 @@ MIT Licensed */ (function(a){a.fn.jConfirm=function(b){var c=a(this);if(1 -
`;return d.question&&0"+d.question+""),b+="
",a.each(d.btns,function(a,c){b+=`
- ${c.text} +
`;return d.question&&0"+d.question+"
"),b+="
",a.each(d.btns,function(a,c){if(b+=``}),b+="
",b},createBackdropHTML:function(){return!!d.backdrop&&`
`},destroy:function(){const b=d.dom_wrapped.data(d.dataAttr);"undefined"!=typeof b&&null!==b&&(b.dom_wrapped.off("touchstart mousedown",b.toggleTooltipHandler),b.dom_wrapped.off("click",b.preventDefaultHandler),a(window).off("resize",b.onResize),b.isVisible()&&b.hide(),b.dom_wrapped.data(b.dataAttr,null))},initialize:function(){return d.dom_wrapped.on("touchstart mousedown",d.toggleTooltipHandler),d.dom_wrapped.on("click",d.preventDefaultHandler),d.dom_wrapped.data(d.dataAttr,d),d.dom},preventDefaultHandler:function(a){return a.preventDefault(),!1},toggleTooltipHandler:function(a){return a.preventDefault(),d.isVisible()?d.hide():d.show(),!1},show:function(b){if(d.isVisible())return!1;null!==a.jConfirm.current&&a.jConfirm.current.hide();const c=a("body");"blurred"===d.backdrop?c.addClass("jc-blurred-body"):d.backdrop&&c.append(d.createBackdropHTML()),c.append(d.createTooltipHTML()),d.tooltip=a(".jc-tooltip"),d.attachTooltipHandlers(),d.positionTooltip(),a(window).on("resize",d.onResize),d.hide_on_click&&a(document).on("touchstart mousedown",d.onClickOutside);const e="jconfirm"+Date.now();d.tooltip.attr("id",e),d.dom.attr("aria-describedby",e),a.jConfirm.current={dom:d.dom,hide:d.hide},("undefined"==typeof b||b)&&d.dom.trigger("jc-show",{tooltip:d.tooltip})},isVisible:function(){return null!==a.jConfirm.current&&d.dom===a.jConfirm.current.dom},hide:function(b){return a(window).off("resize",d.onResize),d.hide_on_click&&a(document).off("touchstart mousedown",d.onClickOutside),d.dom.attr("aria-describedby",null),d.tooltip.remove(),"blurred"===d.backdrop?a("body").removeClass("jc-blurred-body"):d.backdrop&&a(".jc-backdrop").remove(),a.jConfirm.current=null,("undefined"==typeof b||b)&&d.dom.trigger("jc-hide"),d.dom},onResize:function(){d.hide(!1),d.show(!1)},onClickOutside:function(b){const c=a(b.target);c.hasClass("jc-tooltip")||c.parents(".jc-tooltip:first").length||d.hide()},attachTooltipHandlers:function(){d.tooltip.find(".jc-button").on("click",function(b){b.preventDefault();const c=a(this);return d.dom_wrapped.trigger(c.data("event")),d.hide(),"confirm"===c.data("event")&&d.follow_href&&(d.open_new_tab?window.open(d.dom_wrapped.prop("href"),"_blank"):window.location.href=d.dom_wrapped.prop("href")),!1})},positionTooltip:function(){d.positionDebug("-- Start positioning --");let a=d.tooltip.find(".jc-arrow"),[b,c,e,f,g,h]=d.calculateSafePosition(d.position);return("undefined"==typeof g&&(d.positionDebug("Couldn't fit preferred position, downsizing and trying again"),d.tooltip.addClass("jc-tight-fit"),[b,c,e,f,g,h]=d.calculateSafePosition(d.position)),"undefined"==typeof g&&"auto"!==d.position&&(d.positionDebug("Couldn't fit preferred position"),[b,c,e,f,g,h]=d.calculateSafePosition("auto")),"undefined"==typeof g)?(d.positionDebug("Doesn't appear to fit. Displaying centered"),d.tooltip.addClass("jc-centered").css({top:"50%",left:"50%","margin-left":-(e/2),"margin-top":-(f/2)}),a.remove(),void d.positionDebug("-- Done positioning --")):(d.positionDebug({"Setting Position":{Left:g,Top:h}}),d.tooltip.css("left",g),d.tooltip.css("top",h),60>c&&(d.positionDebug("Element is less than "+c+"px. Setting arrow to hug the side tighter"),b+=" jc-arrow-super-hug"),a.addClass("jc-arrow-"+b),d.positionDebug("-- Done positioning --"),d)},calculateSafePosition:function(a){let b=d.tooltip.find(".jc-arrow"),c=d.tooltip.outerWidth(),e=d.tooltip.outerHeight();if(0===d.dom_wrapped.length||!d.dom_wrapped.is(":visible"))return d.position="auto",["none",0,c,e];let f=d.dom_wrapped.offset(),g=d.dom_wrapped.outerHeight(),h=d.dom_wrapped.outerWidth(),i=parseInt(d.dom_wrapped.css("marginLeft").replace("px","")),j=parseInt(d.dom_wrapped.css("marginTop").replace("px",""));f.left+=i,f.top+=j;let k=document.querySelector("body").offsetWidth,l=document.querySelector("body").offsetHeight,m=b.is(":visible")?b.outerHeight():0,n=b.is(":visible")?b.outerWidth():0,o={};o.below=5