Comparing version 4.0.4 to 4.1.1
@@ -31,2 +31,4 @@ /* | ||
options.class += ' jc-'+options.theme+'-theme'; | ||
//add size class | ||
options.class += ' jc-'+options.size; | ||
@@ -38,2 +40,3 @@ let helper = { | ||
follow_href: options.follow_href, | ||
open_new_tab: options.open_new_tab, | ||
hide_on_click: options.hide_on_click, | ||
@@ -240,5 +243,15 @@ question: options.question, | ||
//follow href | ||
if( helper.follow_href ) | ||
if( btn.data('event') === 'confirm' && helper.follow_href ) | ||
{ | ||
window.location.href = helper.dom_wrapped.prop('href'); | ||
if( helper.open_new_tab ) | ||
{ | ||
window.open( | ||
helper.dom_wrapped.prop('href'), | ||
'_blank' | ||
); | ||
} | ||
else | ||
{ | ||
window.location.href = helper.dom_wrapped.prop('href'); | ||
} | ||
} | ||
@@ -315,3 +328,3 @@ return false; | ||
//get position + size of clicked element | ||
let elem_position = helper.dom_wrapped.position(); | ||
let elem_position = helper.dom_wrapped.offset(); | ||
let elem_height = helper.dom_wrapped.outerHeight(); | ||
@@ -384,3 +397,3 @@ let elem_width = helper.dom_wrapped.outerWidth(); | ||
left = elem_position.left - (tooltip_width/2) + (elem_width/2); | ||
top = elem_position.top - tooltip_height - (elem_height/2) - (arrow_height/2); | ||
top = elem_position.top - tooltip_height - (arrow_height/2); | ||
} | ||
@@ -420,3 +433,3 @@ else if( (position === 'auto' || position === 'left') && fits_left && fits_below_half && fits_above_half ) | ||
left = elem_position.left; | ||
top = elem_position.top - tooltip_height - (elem_height/2) - (arrow_height/2); | ||
top = elem_position.top - tooltip_height - (arrow_height/2); | ||
} | ||
@@ -428,3 +441,3 @@ else if( (position === 'auto' || position === 'top') && fits_above && fits_left_full ) | ||
left = elem_position.left + elem_width - tooltip_width; | ||
top = elem_position.top - tooltip_height - (elem_height/2) - (arrow_height/2); | ||
top = elem_position.top - tooltip_height - (arrow_height/2); | ||
} | ||
@@ -454,3 +467,3 @@ | ||
btns: false, | ||
position_debug: false, | ||
position_debug: true, | ||
question: 'Are you sure?', | ||
@@ -460,2 +473,3 @@ confirm_text: 'Yes', | ||
follow_href: false, | ||
open_new_tab: false, | ||
hide_on_click: true, | ||
@@ -466,4 +480,5 @@ position: 'auto', | ||
theme: 'black', | ||
size: 'small', | ||
} | ||
})(jQuery); |
@@ -8,2 +8,2 @@ /* | ||
*/ | ||
(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!1;b=a.extend({},a.jConfirm.defaults,b,a(this).data()),b.class+=' jc-'+b.theme+'-theme';let c={dom:this,dom_wrapped:a(this),position_debug:b.position_debug,follow_href:b.follow_href,hide_on_click:b.hide_on_click,question:b.question,theme:b.theme,class:b.class,btns:b.btns,confirm_text:b.confirm_text,deny_text:b.deny_text,show_deny_btn:b.show_deny_btn,position:b.position,dataAttr:'jConfirm',createTooltipHTML:function(){let d='<div class=\'jc-tooltip '+c.class+'\' role=\'tooltip\'>';return d+='<div class=\'jc-arrow\'></div>',c.question&&0<c.question.length&&(d+='<div class=\'jc-question\'>'+c.question+'</div>'),d+='<div class=\'jc-buttons-wrap\'>',c.btns||(c.btns=[{text:c.confirm_text,class:-1<c.theme.indexOf('bootstrap')?'btn btn-success jc-confirm':'jc-confirm 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 jc-deny':'jc-deny',event:'deny'})),a.each(c.btns,function(f,g){d+='<div class=\'jc-button-wrap\'>',d+='<a href=\'#\' data-event=\''+g.event+'\' class=\'jc-button '+g.class+'\'>'+g.text+'</a>',d+='</div>'}),d+='</div>',d+='</div>',d},destroy:function(){const d=c.dom_wrapped.data(c.dataAttr);'undefined'!=typeof d&&null!==d&&(d.dom_wrapped.off('touchstart mousedown',d.toggleTooltipHandler),d.dom_wrapped.off('click',d.preventDefaultHandler),a(window).off('resize',d.onResize),d.isVisible()&&d.hide(),d.dom_wrapped.data(d.dataAttr,null))},initialize:function(){return c.dom_wrapped.on('touchstart mousedown',c.toggleTooltipHandler),c.dom_wrapped.on('click',c.preventDefaultHandler),c.dom_wrapped.data(c.dataAttr,c),c.dom},preventDefaultHandler:function(d){return d.preventDefault(),!1},toggleTooltipHandler:function(d){return d.preventDefault(),c.isVisible()?c.hide():c.show(),!1},show:function(d){if(c.isVisible())return!1;null!==a.jConfirm.current&&a.jConfirm.current.hide(),a('body').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 f='jconfirm'+Date.now();c.tooltip.attr('id',f),c.dom.attr('aria-describedby',f),a.jConfirm.current={dom:c.dom,hide:c.hide},('undefined'==typeof d||d)&&c.dom.trigger('jc-show',{tooltip:c.tooltip})},isVisible:function(){return null!==a.jConfirm.current&&c.dom===a.jConfirm.current.dom},hide:function(d){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(),a.jConfirm.current=null,('undefined'==typeof d||d)&&c.dom.trigger('jc-hide'),c.dom},onResize:function(){c.hide(!1),c.show(!1)},onClickOutside:function(d){const f=a(d.target);f.hasClass('jc-tooltip')||f.parents('.jc-tooltip:first').length||c.hide()},attachTooltipHandlers:function(){c.tooltip.find('.jc-button').on('click',function(d){d.preventDefault();const f=a(this);return c.dom_wrapped.trigger(f.data('event')),c.hide(),c.follow_href&&(window.location.href=c.dom_wrapped.prop('href')),!1})},positionTooltip:function(){c.positionDebug('-- Start positioning --');let d=c.tooltip.find('.jc-arrow'),[f,g,h,i,j,k]=c.calculateSafePosition(c.position);return('undefined'==typeof j&&(c.positionDebug('Couldn\'t fit preferred position, downsizing and trying again'),c.tooltip.addClass('jc-tight-fit'),[f,k,j,k,j,k]=c.calculateSafePosition(c.position)),'undefined'==typeof j&&'auto'!==c.position&&(c.positionDebug('Couldn\'t fit preferred position'),[f,k,j,k,j,k]=c.calculateSafePosition('auto')),'undefined'==typeof j)?(c.positionDebug('Doesn\'t appear to fit. Displaying centered'),c.tooltip.addClass('jc-centered').css({top:'50%',left:'50%','margin-left':-(h/2),'margin-top':-(i/2)}),d.remove(),void c.positionDebug('-- Done positioning --')):(c.positionDebug('Setting position: left:'+j+' top:'+k),c.tooltip.css('left',j),c.tooltip.css('top',k),60>g&&(c.positionDebug('Element is less than '+g+'px. Setting arrow to hug the side tighter'),f+=' jc-arrow-super-hug'),d.addClass('jc-arrow-'+f),c.positionDebug('-- Done positioning --'),c)},calculateSafePosition:function(d){let f=c.tooltip.find('.jc-arrow'),g=c.dom_wrapped.position(),h=c.dom_wrapped.outerHeight(),i=c.dom_wrapped.outerWidth(),j=parseInt(c.dom_wrapped.css('marginLeft').replace('px','')),k=parseInt(c.dom_wrapped.css('marginTop').replace('px',''));g.left+=j,g.top+=k;let l=c.tooltip.outerWidth(),m=c.tooltip.outerHeight(),n=document.querySelector('body').offsetWidth,o=document.querySelector('body').offsetHeight,p=f.is(':visible')?f.outerHeight():0,q=f.is(':visible')?f.outerWidth():0,r=5<o-(m+h+g.top),s=5<o-i/2-g.top-m/2,t=5<g.top-m,u=5<g.top-i/2-m/2,v=5<n-(l+i+g.left),w=5<n-g.left-i/2-l/2,x=5<n-g.left-l,y=5<g.left-l,z=5<g.left-i/2-l/2,A=5<g.left-l;c.positionDebug('Clicked element position: left:'+g.left+' top:'+g.top),c.positionDebug('Element dimensions: height:'+h+' width:'+i),c.positionDebug('Tooltip dimensions: height:'+m+' width:'+l),c.positionDebug('Window dimensions: height:'+o+' width:'+n),c.positionDebug('Arrow dimensions: height:'+p+' width:'+q),r&&c.positionDebug('Fits below: '+r),s&&c.positionDebug('Fits below half (for vertical centering): '+s),t&&c.positionDebug('Fits above: '+t),u&&c.positionDebug('Fits above half (for vertical centering): '+u),v&&c.positionDebug('Fits right (to the right of the element):'+v),w&&c.positionDebug('Fits right half (for horizontal centering): '+w),x&&c.positionDebug('Fits right full (starting where element starts): '+x),y&&c.positionDebug('Fits left (to the left of the element): '+y),z&&c.positionDebug('Fits left half (for horizontal centering): '+z),A&&c.positionDebug('Fits left full (starting where element starts): '+A);let B,C,D;return('auto'===d||'bottom'===d)&&r&&z&&w?(c.positionDebug('Displaying below, centered'),B='top',C=g.left-l/2+i/2,D=g.top+h+p/2):('auto'===d||'top'===d)&&t&&z&&w?(c.positionDebug('Displaying above, centered'),B='bottom',C=g.left-l/2+i/2,D=g.top-m-h/2-p/2):('auto'===d||'left'===d)&&y&&s&&u?(c.positionDebug('Displaying left, centered'),B='right',C=g.left-l-q/2,D=g.top+h/2-m/2):('auto'===d||'right'===d)&&v&&s&&u?(c.positionDebug('Displaying right, centered'),B='left',C=g.left+i+q/2,D=g.top+h/2-m/2):('auto'===d||'bottom'===d)&&r&&x?(c.positionDebug('Displaying below, to the right'),B='top jc-arrow-hug-left',C=g.left,D=g.top+h+p/2):('auto'===d||'bottom'===d)&&r&&A?(c.positionDebug('Displaying below, to the left'),B='top jc-arrow-hug-right',C=g.left+i-l,D=g.top+h+p/2):('auto'===d||'top'===d)&&t&&x?(c.positionDebug('Displaying above, to the right'),B='bottom jc-arrow-hug-left',C=g.left,D=g.top-m-h/2-p/2):('auto'==d||'top'==d)&&t&&A&&(c.positionDebug('Displaying above, to the left'),B='bottom jc-arrow-hug-right',C=g.left+i-l,D=g.top-m-h/2-p/2),[B,i,l,m,C,D]},positionDebug:function(d){c.position_debug&&console.log('Position: '+d)}};return c.destroy(),c.initialize()},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,hide_on_click:!0,position:'auto',class:'',show_deny_btn:!0,theme:'black'}})(jQuery); | ||
(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!1;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,btns:b.btns,confirm_text:b.confirm_text,deny_text:b.deny_text,show_deny_btn:b.show_deny_btn,position:b.position,dataAttr:'jConfirm',createTooltipHTML:function(){let d='<div class=\'jc-tooltip '+c.class+'\' role=\'tooltip\'>';return d+='<div class=\'jc-arrow\'></div>',c.question&&0<c.question.length&&(d+='<div class=\'jc-question\'>'+c.question+'</div>'),d+='<div class=\'jc-buttons-wrap\'>',c.btns||(c.btns=[{text:c.confirm_text,class:-1<c.theme.indexOf('bootstrap')?'btn btn-success jc-confirm':'jc-confirm 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 jc-deny':'jc-deny',event:'deny'})),a.each(c.btns,function(f,g){d+='<div class=\'jc-button-wrap\'>',d+='<a href=\'#\' data-event=\''+g.event+'\' class=\'jc-button '+g.class+'\'>'+g.text+'</a>',d+='</div>'}),d+='</div>',d+='</div>',d},destroy:function(){const d=c.dom_wrapped.data(c.dataAttr);'undefined'!=typeof d&&null!==d&&(d.dom_wrapped.off('touchstart mousedown',d.toggleTooltipHandler),d.dom_wrapped.off('click',d.preventDefaultHandler),a(window).off('resize',d.onResize),d.isVisible()&&d.hide(),d.dom_wrapped.data(d.dataAttr,null))},initialize:function(){return c.dom_wrapped.on('touchstart mousedown',c.toggleTooltipHandler),c.dom_wrapped.on('click',c.preventDefaultHandler),c.dom_wrapped.data(c.dataAttr,c),c.dom},preventDefaultHandler:function(d){return d.preventDefault(),!1},toggleTooltipHandler:function(d){return d.preventDefault(),c.isVisible()?c.hide():c.show(),!1},show:function(d){if(c.isVisible())return!1;null!==a.jConfirm.current&&a.jConfirm.current.hide(),a('body').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 f='jconfirm'+Date.now();c.tooltip.attr('id',f),c.dom.attr('aria-describedby',f),a.jConfirm.current={dom:c.dom,hide:c.hide},('undefined'==typeof d||d)&&c.dom.trigger('jc-show',{tooltip:c.tooltip})},isVisible:function(){return null!==a.jConfirm.current&&c.dom===a.jConfirm.current.dom},hide:function(d){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(),a.jConfirm.current=null,('undefined'==typeof d||d)&&c.dom.trigger('jc-hide'),c.dom},onResize:function(){c.hide(!1),c.show(!1)},onClickOutside:function(d){const f=a(d.target);f.hasClass('jc-tooltip')||f.parents('.jc-tooltip:first').length||c.hide()},attachTooltipHandlers:function(){c.tooltip.find('.jc-button').on('click',function(d){d.preventDefault();const f=a(this);return c.dom_wrapped.trigger(f.data('event')),c.hide(),'confirm'===f.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 d=c.tooltip.find('.jc-arrow'),[f,g,h,i,j,k]=c.calculateSafePosition(c.position);return('undefined'==typeof j&&(c.positionDebug('Couldn\'t fit preferred position, downsizing and trying again'),c.tooltip.addClass('jc-tight-fit'),[f,k,j,k,j,k]=c.calculateSafePosition(c.position)),'undefined'==typeof j&&'auto'!==c.position&&(c.positionDebug('Couldn\'t fit preferred position'),[f,k,j,k,j,k]=c.calculateSafePosition('auto')),'undefined'==typeof j)?(c.positionDebug('Doesn\'t appear to fit. Displaying centered'),c.tooltip.addClass('jc-centered').css({top:'50%',left:'50%','margin-left':-(h/2),'margin-top':-(i/2)}),d.remove(),void c.positionDebug('-- Done positioning --')):(c.positionDebug('Setting position: left:'+j+' top:'+k),c.tooltip.css('left',j),c.tooltip.css('top',k),60>g&&(c.positionDebug('Element is less than '+g+'px. Setting arrow to hug the side tighter'),f+=' jc-arrow-super-hug'),d.addClass('jc-arrow-'+f),c.positionDebug('-- Done positioning --'),c)},calculateSafePosition:function(d){let f=c.tooltip.find('.jc-arrow'),g=c.dom_wrapped.offset(),h=c.dom_wrapped.outerHeight(),i=c.dom_wrapped.outerWidth(),j=parseInt(c.dom_wrapped.css('marginLeft').replace('px','')),k=parseInt(c.dom_wrapped.css('marginTop').replace('px',''));g.left+=j,g.top+=k;let l=c.tooltip.outerWidth(),m=c.tooltip.outerHeight(),n=document.querySelector('body').offsetWidth,o=document.querySelector('body').offsetHeight,p=f.is(':visible')?f.outerHeight():0,q=f.is(':visible')?f.outerWidth():0,r=5<o-(m+h+g.top),s=5<o-i/2-g.top-m/2,t=5<g.top-m,u=5<g.top-i/2-m/2,v=5<n-(l+i+g.left),w=5<n-g.left-i/2-l/2,x=5<n-g.left-l,y=5<g.left-l,z=5<g.left-i/2-l/2,A=5<g.left-l;c.positionDebug('Clicked element position: left:'+g.left+' top:'+g.top),c.positionDebug('Element dimensions: height:'+h+' width:'+i),c.positionDebug('Tooltip dimensions: height:'+m+' width:'+l),c.positionDebug('Window dimensions: height:'+o+' width:'+n),c.positionDebug('Arrow dimensions: height:'+p+' width:'+q),r&&c.positionDebug('Fits below: '+r),s&&c.positionDebug('Fits below half (for vertical centering): '+s),t&&c.positionDebug('Fits above: '+t),u&&c.positionDebug('Fits above half (for vertical centering): '+u),v&&c.positionDebug('Fits right (to the right of the element):'+v),w&&c.positionDebug('Fits right half (for horizontal centering): '+w),x&&c.positionDebug('Fits right full (starting where element starts): '+x),y&&c.positionDebug('Fits left (to the left of the element): '+y),z&&c.positionDebug('Fits left half (for horizontal centering): '+z),A&&c.positionDebug('Fits left full (starting where element starts): '+A);let B,C,D;return('auto'===d||'bottom'===d)&&r&&z&&w?(c.positionDebug('Displaying below, centered'),B='top',C=g.left-l/2+i/2,D=g.top+h+p/2):('auto'===d||'top'===d)&&t&&z&&w?(c.positionDebug('Displaying above, centered'),B='bottom',C=g.left-l/2+i/2,D=g.top-m-p/2):('auto'===d||'left'===d)&&y&&s&&u?(c.positionDebug('Displaying left, centered'),B='right',C=g.left-l-q/2,D=g.top+h/2-m/2):('auto'===d||'right'===d)&&v&&s&&u?(c.positionDebug('Displaying right, centered'),B='left',C=g.left+i+q/2,D=g.top+h/2-m/2):('auto'===d||'bottom'===d)&&r&&x?(c.positionDebug('Displaying below, to the right'),B='top jc-arrow-hug-left',C=g.left,D=g.top+h+p/2):('auto'===d||'bottom'===d)&&r&&A?(c.positionDebug('Displaying below, to the left'),B='top jc-arrow-hug-right',C=g.left+i-l,D=g.top+h+p/2):('auto'===d||'top'===d)&&t&&x?(c.positionDebug('Displaying above, to the right'),B='bottom jc-arrow-hug-left',C=g.left,D=g.top-m-p/2):('auto'==d||'top'==d)&&t&&A&&(c.positionDebug('Displaying above, to the left'),B='bottom jc-arrow-hug-right',C=g.left+i-l,D=g.top-m-p/2),[B,i,l,m,C,D]},positionDebug:function(d){c.position_debug&&console.log('Position: '+d)}};return c.destroy(),c.initialize()},a.jConfirm={},a.jConfirm.current=null,a.jConfirm.defaults={btns:!1,position_debug:!0,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'}})(jQuery); |
{ | ||
"name": "jconfirm", | ||
"version": "4.0.4", | ||
"version": "4.1.1", | ||
"description": "jQuery confirmation tooltip plugin", | ||
@@ -5,0 +5,0 @@ "repository": { |
@@ -76,2 +76,4 @@ jConfirm | ||
follow_href: true, | ||
//boolean: if true and follow_href is true, the href will be opened in a new window | ||
open_new_tab: false, | ||
//boolean : if true, the tooltip will be hidden if you click outside of it | ||
@@ -87,2 +89,4 @@ hide_on_click: true, | ||
theme: 'black', | ||
//string ('tiny', 'small', 'medium', 'large') | ||
size: 'small', | ||
}).on('confirm', function(e){ | ||
@@ -166,3 +170,3 @@ var btn = $(this); | ||
class="btn btn-secondary outside-link"> | ||
Send | ||
HTMLGuy.com | ||
</a> | ||
@@ -169,0 +173,0 @@ ``` |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
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
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
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
84701
9
794
225
1