Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add the option to close the popup on background click #42

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ Name | Type | Default | Description
**cookieExp** | integer | 30 | The number of days to set the cookie for. A cookie is used to track if the popup has already been shown to a specific visitor. If the popup has been shown, it will not show again until the cookie expires. A value of 0 will always show the popup.
**showOncePerSession** | boolean | false | If true, the popup will only show once per browser session. If false and cookieExp is set to 0, the popup will show multiple times in a single browser session.
**onPopup** | function | null | A callback function to be called when the popup is displayed in the browser.
**closeOnBackgroundClick** | boolean | false | If true, the popup will close when the user clicks the background.

# License

Expand Down
9 changes: 9 additions & 0 deletions js/bioep.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ window.bioEp = {
cookieExp: 30,
showOncePerSession: false,
onPopup: null,
closeOnBackgroundClick: false,

// Object for handling cookies, taken from QuirksMode
// http://www.quirksmode.org/js/cookies.html
Expand Down Expand Up @@ -253,6 +254,13 @@ window.bioEp = {
bioEp.hidePopup();
});

// Handle the background click close event
if(this.closeOnBackgroundClick) {
this.addEvent(this.bgEl, "click", function() {
bioEp.hidePopup();
});
}

// Handle window resizing
this.addEvent(window, "resize", function() {
bioEp.scalePopup();
Expand All @@ -271,6 +279,7 @@ window.bioEp = {
this.cookieExp = (typeof opts.cookieExp === 'undefined') ? this.cookieExp : opts.cookieExp;
this.showOncePerSession = (typeof opts.showOncePerSession === 'undefined') ? this.showOncePerSession : opts.showOncePerSession;
this.onPopup = (typeof opts.onPopup === 'undefined') ? this.onPopup : opts.onPopup;
this.closeOnBackgroundClick = (typeof opts.closeOnBackgroundClick === 'undefined') ? this.closeOnBackgroundClick : opts.closeOnBackgroundClick;
},

// Ensure the DOM has loaded
Expand Down
20 changes: 10 additions & 10 deletions js/bioep.min.js

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