From 0228e160ad3dc58691b215a2538378590efd862d Mon Sep 17 00:00:00 2001 From: HTMLGuyLLC Date: Thu, 25 Oct 2018 16:15:49 -0400 Subject: [PATCH] had to remove target option because it's too error prone --- README.md | 3 --- index.html | 5 +---- jConfirm.js | 15 +++++++-------- jConfirm.min.js | 8 ++++---- package.json | 2 +- 5 files changed, 13 insertions(+), 20 deletions(-) diff --git a/README.md b/README.md index 8fb8cd8..bc8b631 100755 --- a/README.md +++ b/README.md @@ -95,9 +95,6 @@ $(function(){ size: 'small', //boolean: show the tooltip immediately on instantiation show_now: false, - //string|null: tie the handler to a child of the supplier dom element (good for dynamically added elements) - //for example: $('body').jConfirm({'target':'a.confirm'}).on('confirm', function(){ }); - target: null, //string|false ('black', 'white', 'blurred') backdrop: false }).on('confirm', function(e){ diff --git a/index.html b/index.html index 264c570..83b490d 100755 --- a/index.html +++ b/index.html @@ -192,9 +192,6 @@

All options and events with defaults:

size: 'small', //boolean: show the tooltip immediately on instantiation show_now: false, - //string|null: tie the handler to a child of the supplier dom element (good for dynamically added elements) - //for example: $('body').jConfirm({'target':'a.confirm'}).on('confirm', function(){ }); - target: null, //string: class(es) to add to the tooltip 'class': '' }).on('confirm', function(e){ @@ -474,7 +471,7 @@

Social Media Sharing:

}).on('jc-hide', function(e){ console.log('js-hide'); }); - }) + }); diff --git a/jConfirm.js b/jConfirm.js index 3b1bab3..d835446 100755 --- a/jConfirm.js +++ b/jConfirm.js @@ -8,6 +8,7 @@ ;(function($) { $.fn.jConfirm = function(options) { + var this_wrapped = $(this); //Instantiate jConfirm once per dom element if (this.length > 1){ @@ -24,7 +25,7 @@ } //get list of options - options = $.extend({}, $.jConfirm.defaults, options, $(this).data()); + options = $.extend({}, $.jConfirm.defaults, options, this_wrapped.data()); //add theme class options.class += ' jc-'+options.theme+'-theme'; @@ -33,7 +34,7 @@ let helper = { dom: this, - dom_wrapped: $(this), + dom_wrapped: this_wrapped, position_debug: options.position_debug, follow_href: options.follow_href, open_new_tab: options.open_new_tab, @@ -48,7 +49,6 @@ show_deny_btn: options.show_deny_btn, position: options.position, show_now: options.show_now, - target: options.target, dataAttr: 'jConfirm', //create tooltip html createTooltipHTML: function(){ @@ -105,8 +105,8 @@ if( typeof existing !== 'undefined' && existing !== null ) { //disable handler - existing.dom_wrapped.off('touchstart mousedown', helper.target, existing.toggleTooltipHandler); - existing.dom_wrapped.off('click', helper.target, existing.preventDefaultHandler); + existing.dom_wrapped.off('touchstart mousedown', existing.toggleTooltipHandler); + existing.dom_wrapped.off('click', existing.preventDefaultHandler); //attach resize handler to reposition tooltip $(window).off('resize', existing.onResize); @@ -123,8 +123,8 @@ //attach on handler to show tooltip //use touchstart and mousedown just like if you click outside the tooltip to close it //this way it blocks the hide if you click the button a second time to close the tooltip - helper.dom_wrapped.on('touchstart mousedown', helper.target, helper.toggleTooltipHandler); - helper.dom_wrapped.on('click', helper.target, helper.preventDefaultHandler); + helper.dom_wrapped.on('touchstart mousedown', helper.toggleTooltipHandler); + helper.dom_wrapped.on('click', helper.preventDefaultHandler); //attach to dom for easy access later helper.dom_wrapped.data(helper.dataAttr, helper); @@ -507,7 +507,6 @@ size: 'small', backdrop: false, show_now: false, - target: null, } })(jQuery); \ No newline at end of file diff --git a/jConfirm.min.js b/jConfirm.min.js index 708d9ad..c900aa7 100755 --- a/jConfirm.min.js +++ b/jConfirm.min.js @@ -5,7 +5,7 @@ https://htmlguy.com MIT Licensed */ -(function(a){a.fn.jConfirm=function(b){if(1 -
`;return c.question&&0'+c.question+''),f+='
',a.each(c.btns,function(g,h){f+=`
- ${h.text} -
`}),f+='
',f},createBackdropHTML:function(){return!!c.backdrop&&`
`},destroy:function(){const f=c.dom_wrapped.data(c.dataAttr);'undefined'!=typeof f&&null!==f&&(f.dom_wrapped.off('touchstart mousedown',c.target,f.toggleTooltipHandler),f.dom_wrapped.off('click',c.target,f.preventDefaultHandler),a(window).off('resize',f.onResize),f.isVisible()&&f.hide(),f.dom_wrapped.data(f.dataAttr,null))},initialize:function(){return c.dom_wrapped.on('touchstart mousedown',c.target,c.toggleTooltipHandler),c.dom_wrapped.on('click',c.target,c.preventDefaultHandler),c.dom_wrapped.data(c.dataAttr,c),c.dom},preventDefaultHandler:function(f){return f.preventDefault(),!1},toggleTooltipHandler:function(f){return f.preventDefault(),c.isVisible()?c.hide():c.show(),!1},show:function(f){if(c.isVisible())return!1;null!==a.jConfirm.current&&a.jConfirm.current.hide();const g=a('body');'blurred'===c.backdrop?g.addClass('jc-blurred-body'):c.backdrop&&g.append(c.createBackdropHTML()),g.append(c.createTooltipHTML()),c.tooltip=a('.jc-tooltip'),c.attachTooltipHandlers(),c.positionTooltip(),a(window).on('resize',c.onResize),c.hide_on_click&&a(document).on('touchstart mousedown',c.onClickOutside);const h='jconfirm'+Date.now();c.tooltip.attr('id',h),c.dom.attr('aria-describedby',h),a.jConfirm.current={dom:c.dom,hide:c.hide},('undefined'==typeof f||f)&&c.dom.trigger('jc-show',{tooltip:c.tooltip})},isVisible:function(){return null!==a.jConfirm.current&&c.dom===a.jConfirm.current.dom},hide:function(f){return a(window).off('resize',c.onResize),c.hide_on_click&&a(document).off('touchstart mousedown',c.onClickOutside),c.dom.attr('aria-describedby',null),c.tooltip.remove(),'blurred'===c.backdrop?a('body').removeClass('jc-blurred-body'):c.backdrop&&a('.jc-backdrop').remove(),a.jConfirm.current=null,('undefined'==typeof f||f)&&c.dom.trigger('jc-hide'),c.dom},onResize:function(){c.hide(!1),c.show(!1)},onClickOutside:function(f){const g=a(f.target);g.hasClass('jc-tooltip')||g.parents('.jc-tooltip:first').length||c.hide()},attachTooltipHandlers:function(){c.tooltip.find('.jc-button').on('click',function(f){f.preventDefault();const g=a(this);return c.dom_wrapped.trigger(g.data('event')),c.hide(),'confirm'===g.data('event')&&c.follow_href&&(c.open_new_tab?window.open(c.dom_wrapped.prop('href'),'_blank'):window.location.href=c.dom_wrapped.prop('href')),!1})},positionTooltip:function(){c.positionDebug('-- Start positioning --');let f=c.tooltip.find('.jc-arrow'),[g,h,i,j,k,l]=c.calculateSafePosition(c.position);return('undefined'==typeof k&&(c.positionDebug('Couldn\'t fit preferred position, downsizing and trying again'),c.tooltip.addClass('jc-tight-fit'),[g,l,k,l,k,l]=c.calculateSafePosition(c.position)),'undefined'==typeof k&&'auto'!==c.position&&(c.positionDebug('Couldn\'t fit preferred position'),[g,l,k,l,k,l]=c.calculateSafePosition('auto')),'undefined'==typeof k)?(c.positionDebug('Doesn\'t appear to fit. Displaying centered'),c.tooltip.addClass('jc-centered').css({top:'50%',left:'50%','margin-left':-(i/2),'margin-top':-(j/2)}),f.remove(),void c.positionDebug('-- Done positioning --')):(c.positionDebug({'Setting Position':{Left:k,Top:l}}),c.tooltip.css('left',k),c.tooltip.css('top',l),60>h&&(c.positionDebug('Element is less than '+h+'px. Setting arrow to hug the side tighter'),g+=' jc-arrow-super-hug'),f.addClass('jc-arrow-'+g),c.positionDebug('-- Done positioning --'),c)},calculateSafePosition:function(f){let g=c.tooltip.find('.jc-arrow'),h=c.dom_wrapped.offset(),i=c.dom_wrapped.outerHeight(),j=c.dom_wrapped.outerWidth(),k=parseInt(c.dom_wrapped.css('marginLeft').replace('px','')),l=parseInt(c.dom_wrapped.css('marginTop').replace('px',''));h.left+=k,h.top+=l;let m=c.tooltip.outerWidth(),n=c.tooltip.outerHeight(),o=document.querySelector('body').offsetWidth,p=document.querySelector('body').offsetHeight,q=g.is(':visible')?g.outerHeight():0,r=g.is(':visible')?g.outerWidth():0,s={};s.below=5 +
`;return d.question&&0'+d.question+''),g+='
',a.each(d.btns,function(h,i){g+=`
+ ${i.text} +
`}),g+='
',g},createBackdropHTML:function(){return!!d.backdrop&&`
`},destroy:function(){const g=d.dom_wrapped.data(d.dataAttr);'undefined'!=typeof g&&null!==g&&(g.dom_wrapped.off('touchstart mousedown',g.toggleTooltipHandler),g.dom_wrapped.off('click',g.preventDefaultHandler),a(window).off('resize',g.onResize),g.isVisible()&&g.hide(),g.dom_wrapped.data(g.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(g){return g.preventDefault(),!1},toggleTooltipHandler:function(g){return g.preventDefault(),d.isVisible()?d.hide():d.show(),!1},show:function(g){if(d.isVisible())return!1;null!==a.jConfirm.current&&a.jConfirm.current.hide();const h=a('body');'blurred'===d.backdrop?h.addClass('jc-blurred-body'):d.backdrop&&h.append(d.createBackdropHTML()),h.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 i='jconfirm'+Date.now();d.tooltip.attr('id',i),d.dom.attr('aria-describedby',i),a.jConfirm.current={dom:d.dom,hide:d.hide},('undefined'==typeof g||g)&&d.dom.trigger('jc-show',{tooltip:d.tooltip})},isVisible:function(){return null!==a.jConfirm.current&&d.dom===a.jConfirm.current.dom},hide:function(g){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 g||g)&&d.dom.trigger('jc-hide'),d.dom},onResize:function(){d.hide(!1),d.show(!1)},onClickOutside:function(g){const h=a(g.target);h.hasClass('jc-tooltip')||h.parents('.jc-tooltip:first').length||d.hide()},attachTooltipHandlers:function(){d.tooltip.find('.jc-button').on('click',function(g){g.preventDefault();const h=a(this);return d.dom_wrapped.trigger(h.data('event')),d.hide(),'confirm'===h.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 g=d.tooltip.find('.jc-arrow'),[h,i,j,k,l,m]=d.calculateSafePosition(d.position);return('undefined'==typeof l&&(d.positionDebug('Couldn\'t fit preferred position, downsizing and trying again'),d.tooltip.addClass('jc-tight-fit'),[h,m,l,m,l,m]=d.calculateSafePosition(d.position)),'undefined'==typeof l&&'auto'!==d.position&&(d.positionDebug('Couldn\'t fit preferred position'),[h,m,l,m,l,m]=d.calculateSafePosition('auto')),'undefined'==typeof l)?(d.positionDebug('Doesn\'t appear to fit. Displaying centered'),d.tooltip.addClass('jc-centered').css({top:'50%',left:'50%','margin-left':-(j/2),'margin-top':-(k/2)}),g.remove(),void d.positionDebug('-- Done positioning --')):(d.positionDebug({'Setting Position':{Left:l,Top:m}}),d.tooltip.css('left',l),d.tooltip.css('top',m),60>i&&(d.positionDebug('Element is less than '+i+'px. Setting arrow to hug the side tighter'),h+=' jc-arrow-super-hug'),g.addClass('jc-arrow-'+h),d.positionDebug('-- Done positioning --'),d)},calculateSafePosition:function(g){let h=d.tooltip.find('.jc-arrow'),i=d.dom_wrapped.offset(),j=d.dom_wrapped.outerHeight(),k=d.dom_wrapped.outerWidth(),l=parseInt(d.dom_wrapped.css('marginLeft').replace('px','')),m=parseInt(d.dom_wrapped.css('marginTop').replace('px',''));i.left+=l,i.top+=m;let n=d.tooltip.outerWidth(),o=d.tooltip.outerHeight(),p=document.querySelector('body').offsetWidth,q=document.querySelector('body').offsetHeight,r=h.is(':visible')?h.outerHeight():0,s=h.is(':visible')?h.outerWidth():0,t={};t.below=5