Skip to content

Commit

Permalink
fix for chainability (return this instead of false), added new option…
Browse files Browse the repository at this point in the history
…s 'target' and 'open_now'
  • Loading branch information
HTMLGuyLLC committed Oct 25, 2018
1 parent f5a8ed4 commit 7762861
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 11 deletions.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,11 @@ $(function(){
theme: 'black',
//string ('tiny', 'small', 'medium', 'large')
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){
Expand Down
5 changes: 5 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,11 @@ <h4>All options and events with defaults:</h4>
theme: 'black',
//string ('tiny', 'small', 'medium', 'large')
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){
Expand Down
24 changes: 18 additions & 6 deletions jConfirm.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
//if there's nothing being passed
if( typeof this === 'undefined' || this.length !== 1 )
{
return false;
return this;
}

//get list of options
Expand All @@ -47,6 +47,8 @@
deny_text: options.deny_text,
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(){
Expand Down Expand Up @@ -103,8 +105,8 @@
if( typeof existing !== 'undefined' && existing !== null ) {

//disable handler
existing.dom_wrapped.off('touchstart mousedown', existing.toggleTooltipHandler);
existing.dom_wrapped.off('click', existing.preventDefaultHandler);
existing.dom_wrapped.off('touchstart mousedown', helper.target, existing.toggleTooltipHandler);
existing.dom_wrapped.off('click', helper.target, existing.preventDefaultHandler);

//attach resize handler to reposition tooltip
$(window).off('resize', existing.onResize);
Expand All @@ -121,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.toggleTooltipHandler);
helper.dom_wrapped.on('click', helper.preventDefaultHandler);
helper.dom_wrapped.on('touchstart mousedown', helper.target, helper.toggleTooltipHandler);
helper.dom_wrapped.on('click', helper.target, helper.preventDefaultHandler);

//attach to dom for easy access later
helper.dom_wrapped.data(helper.dataAttr, helper);
Expand Down Expand Up @@ -474,7 +476,15 @@

helper.destroy();

return helper.initialize();
var initialized = helper.initialize();

//if showing immediately, do it!
if( helper.show_now )
{
helper.show();
}

return initialized;
};

$.jConfirm = {};
Expand All @@ -496,6 +506,8 @@
theme: 'black',
size: 'small',
backdrop: false,
show_now: false,
target: null,
}

})(jQuery);
8 changes: 4 additions & 4 deletions jConfirm.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "jconfirm",
"version": "4.2.2",
"version": "4.3.0",
"description": "jQuery confirmation tooltip plugin",
"repository": {
"type": "git",
Expand Down

0 comments on commit 7762861

Please sign in to comment.