Comparing version 4.3.0 to 4.4.0
@@ -11,2 +11,3 @@ /* | ||
$.fn.jConfirm = function(options) { | ||
var this_wrapped = $(this); | ||
@@ -28,3 +29,3 @@ //Instantiate jConfirm once per dom element | ||
//get list of options | ||
options = $.extend({}, $.jConfirm.defaults, options, $(this).data()); | ||
options = $.extend({}, $.jConfirm.defaults, options, this_wrapped.data()); | ||
@@ -38,3 +39,3 @@ //add theme class | ||
dom: this, | ||
dom_wrapped: $(this), | ||
dom_wrapped: this_wrapped, | ||
position_debug: options.position_debug, | ||
@@ -54,3 +55,2 @@ follow_href: options.follow_href, | ||
show_now: options.show_now, | ||
target: options.target, | ||
dataAttr: 'jConfirm', | ||
@@ -112,4 +112,4 @@ //create tooltip html | ||
//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); | ||
@@ -131,4 +131,4 @@ //attach resize handler to reposition tooltip | ||
//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); | ||
@@ -516,5 +516,4 @@ //attach to dom for easy access later | ||
show_now: false, | ||
target: null, | ||
} | ||
})(jQuery); |
@@ -8,5 +8,5 @@ /* | ||
*/ | ||
(function(a){a.fn.jConfirm=function(b){if(1<this.length)return this.each(function(){a(this).jConfirm(b)}),this;if('undefined'==typeof this||1!==this.length)return this;b=a.extend({},a.jConfirm.defaults,b,a(this).data()),b.class+=' jc-'+b.theme+'-theme',b.class+=' jc-'+b.size;let c={dom:this,dom_wrapped:a(this),position_debug:b.position_debug,follow_href:b.follow_href,open_new_tab:b.open_new_tab,hide_on_click:b.hide_on_click,question:b.question,theme:b.theme,class:b.class,backdrop:b.backdrop,btns:b.btns,confirm_text:b.confirm_text,deny_text:b.deny_text,show_deny_btn:b.show_deny_btn,position:b.position,show_now:b.show_now,target:b.target,dataAttr:'jConfirm',createTooltipHTML:function(){c.btns||(c.btns=[{text:c.confirm_text,class:-1<c.theme.indexOf('bootstrap')?'btn btn-success':'jc-button-highlight',event:'confirm'}],c.show_deny_btn&&c.btns.push({text:c.deny_text,class:-1<c.theme.indexOf('bootstrap')?'btn btn-secondary':'',event:'deny'}));let f=`<div class='jc-tooltip ${c.class}' role='tooltip'> | ||
<div class='jc-arrow'></div>`;return c.question&&0<c.question.length&&(f+='<div class=\'jc-question\'>'+c.question+'</div>'),f+='<div class=\'jc-buttons-wrap\'>',a.each(c.btns,function(g,h){f+=`<div class='jc-button-wrap'> | ||
<a href='#' data-event='${h.event}' class='jc-button ${h.class}'>${h.text}</a> | ||
</div>`}),f+='</div></div>',f},createBackdropHTML:function(){return!!c.backdrop&&`<div class='jc-backdrop jc-${c.backdrop}-backdrop'></div>`},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<p-(n+i+h.top),s.below_half=5<p-j/2-h.top-n/2,s.above=5<h.top-n,s.above_half=5<h.top-j/2-n/2,s.right=5<o-(m+j+h.left),s.right_half=5<o-h.left-j/2-m/2,s.right_full=5<o-h.left-m,s.left=5<h.left-m,s.left_half=5<h.left-j/2-m/2,s.left_full=5<h.left-m,c.positionDebug({'Clicked Element':{Left:h.left,Top:h.top}}),c.positionDebug({'Element Dimensions':{Height:i,Width:j},'Tooltip Dimensions':{Height:n,Width:m},'Window Dimensions':{Height:p,Width:o},'Arrow Dimensions':{Height:q,Width:r}}),c.positionDebug(s);let t,u,v;return('auto'===f||'bottom'===f)&&s.below&&s.left_half&&s.right_half?(c.positionDebug('Displaying below, centered'),t='top',u=h.left-m/2+j/2,v=h.top+i+q/2):('auto'===f||'top'===f)&&s.above&&s.left_half&&s.right_half?(c.positionDebug('Displaying above, centered'),t='bottom',u=h.left-m/2+j/2,v=h.top-n-q/2):('auto'===f||'left'===f)&&s.left&&s.below_half&&s.above_half?(c.positionDebug('Displaying left, centered'),t='right',u=h.left-m-r/2,v=h.top+i/2-n/2):('auto'===f||'right'===f)&&s.right&&s.below_half&&s.above_half?(c.positionDebug('Displaying right, centered'),t='left',u=h.left+j+r/2,v=h.top+i/2-n/2):('auto'===f||'bottom'===f)&&s.below&&s.right_full?(c.positionDebug('Displaying below, to the right'),t='top jc-arrow-hug-left',u=h.left,v=h.top+i+q/2):('auto'===f||'bottom'===f)&&s.below&&s.left_full?(c.positionDebug('Displaying below, to the left'),t='top jc-arrow-hug-right',u=h.left+j-m,v=h.top+i+q/2):('auto'===f||'top'===f)&&s.above&&s.right_full?(c.positionDebug('Displaying above, to the right'),t='bottom jc-arrow-hug-left',u=h.left,v=h.top-n-q/2):('auto'==f||'top'==f)&&s.above&&s.left_full&&(c.positionDebug('Displaying above, to the left'),t='bottom jc-arrow-hug-right',u=h.left+j-m,v=h.top-n-q/2),[t,j,m,n,u,v]},positionDebug:function(f){return!!c.position_debug&&('object'==typeof f?console.table(f):console.log(`Position: ${f}`))}};c.destroy();var d=c.initialize();return c.show_now&&c.show(),d},a.jConfirm={},a.jConfirm.current=null,a.jConfirm.defaults={btns:!1,position_debug:!1,question:'Are you sure?',confirm_text:'Yes',deny_text:'No',follow_href:!1,open_new_tab:!1,hide_on_click:!0,position:'auto',class:'',show_deny_btn:!0,theme:'black',size:'small',backdrop:!1,show_now:!1,target:null}})(jQuery); | ||
(function(a){a.fn.jConfirm=function(b){var c=a(this);if(1<this.length)return this.each(function(){a(this).jConfirm(b)}),this;if('undefined'==typeof this||1!==this.length)return this;b=a.extend({},a.jConfirm.defaults,b,c.data()),b.class+=' jc-'+b.theme+'-theme',b.class+=' jc-'+b.size;let d={dom:this,dom_wrapped:c,position_debug:b.position_debug,follow_href:b.follow_href,open_new_tab:b.open_new_tab,hide_on_click:b.hide_on_click,question:b.question,theme:b.theme,class:b.class,backdrop:b.backdrop,btns:b.btns,confirm_text:b.confirm_text,deny_text:b.deny_text,show_deny_btn:b.show_deny_btn,position:b.position,show_now:b.show_now,dataAttr:'jConfirm',createTooltipHTML:function(){d.btns||(d.btns=[{text:d.confirm_text,class:-1<d.theme.indexOf('bootstrap')?'btn btn-success':'jc-button-highlight',event:'confirm'}],d.show_deny_btn&&d.btns.push({text:d.deny_text,class:-1<d.theme.indexOf('bootstrap')?'btn btn-secondary':'',event:'deny'}));let g=`<div class='jc-tooltip ${d.class}' role='tooltip'> | ||
<div class='jc-arrow'></div>`;return d.question&&0<d.question.length&&(g+='<div class=\'jc-question\'>'+d.question+'</div>'),g+='<div class=\'jc-buttons-wrap\'>',a.each(d.btns,function(h,i){g+=`<div class='jc-button-wrap'> | ||
<a href='#' data-event='${i.event}' class='jc-button ${i.class}'>${i.text}</a> | ||
</div>`}),g+='</div></div>',g},createBackdropHTML:function(){return!!d.backdrop&&`<div class='jc-backdrop jc-${d.backdrop}-backdrop'></div>`},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<q-(o+j+i.top),t.below_half=5<q-k/2-i.top-o/2,t.above=5<i.top-o,t.above_half=5<i.top-k/2-o/2,t.right=5<p-(n+k+i.left),t.right_half=5<p-i.left-k/2-n/2,t.right_full=5<p-i.left-n,t.left=5<i.left-n,t.left_half=5<i.left-k/2-n/2,t.left_full=5<i.left-n,d.positionDebug({'Clicked Element':{Left:i.left,Top:i.top}}),d.positionDebug({'Element Dimensions':{Height:j,Width:k},'Tooltip Dimensions':{Height:o,Width:n},'Window Dimensions':{Height:q,Width:p},'Arrow Dimensions':{Height:r,Width:s}}),d.positionDebug(t);let u,v,w;return('auto'===g||'bottom'===g)&&t.below&&t.left_half&&t.right_half?(d.positionDebug('Displaying below, centered'),u='top',v=i.left-n/2+k/2,w=i.top+j+r/2):('auto'===g||'top'===g)&&t.above&&t.left_half&&t.right_half?(d.positionDebug('Displaying above, centered'),u='bottom',v=i.left-n/2+k/2,w=i.top-o-r/2):('auto'===g||'left'===g)&&t.left&&t.below_half&&t.above_half?(d.positionDebug('Displaying left, centered'),u='right',v=i.left-n-s/2,w=i.top+j/2-o/2):('auto'===g||'right'===g)&&t.right&&t.below_half&&t.above_half?(d.positionDebug('Displaying right, centered'),u='left',v=i.left+k+s/2,w=i.top+j/2-o/2):('auto'===g||'bottom'===g)&&t.below&&t.right_full?(d.positionDebug('Displaying below, to the right'),u='top jc-arrow-hug-left',v=i.left,w=i.top+j+r/2):('auto'===g||'bottom'===g)&&t.below&&t.left_full?(d.positionDebug('Displaying below, to the left'),u='top jc-arrow-hug-right',v=i.left+k-n,w=i.top+j+r/2):('auto'===g||'top'===g)&&t.above&&t.right_full?(d.positionDebug('Displaying above, to the right'),u='bottom jc-arrow-hug-left',v=i.left,w=i.top-o-r/2):('auto'==g||'top'==g)&&t.above&&t.left_full&&(d.positionDebug('Displaying above, to the left'),u='bottom jc-arrow-hug-right',v=i.left+k-n,w=i.top-o-r/2),[u,k,n,o,v,w]},positionDebug:function(g){return!!d.position_debug&&('object'==typeof g?console.table(g):console.log(`Position: ${g}`))}};d.destroy();var f=d.initialize();return d.show_now&&d.show(),f},a.jConfirm={},a.jConfirm.current=null,a.jConfirm.defaults={btns:!1,position_debug:!1,question:'Are you sure?',confirm_text:'Yes',deny_text:'No',follow_href:!1,open_new_tab:!1,hide_on_click:!0,position:'auto',class:'',show_deny_btn:!0,theme:'black',size:'small',backdrop:!1,show_now:!1}})(jQuery); |
{ | ||
"name": "jconfirm", | ||
"version": "4.3.0", | ||
"version": "4.4.0", | ||
"description": "jQuery confirmation tooltip plugin", | ||
@@ -5,0 +5,0 @@ "repository": { |
@@ -98,5 +98,2 @@ jConfirm | ||
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') | ||
@@ -103,0 +100,0 @@ backdrop: false |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
89538
900
235