Skip to content

Commit

Permalink
Add manual hide and show events
Browse files Browse the repository at this point in the history
  • Loading branch information
Scott Elwood authored and Scott Elwood committed Aug 14, 2017
1 parent b8af9d0 commit 7653652
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 8 deletions.
23 changes: 19 additions & 4 deletions dist/popover.js
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,8 @@ var defaults = {
hideOn: 'documentClick',
showDelay: 0,
hideDelay: 0,
manualRender: true,
manualShow: false,
manualHide: false,
themeClass: 'popoverjs--default',
unnecessaryRepositioning: false,
resizePositioning: true,
Expand Down Expand Up @@ -761,7 +762,10 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Cons

var defaults = {
showOn: 'click',
hideOn: 'documentClick'
hideOn: 'documentClick',
manualShow: false,
manualHide: false,
onHideEvent: function onHideEvent() {}
};

var Renderer = function () {
Expand Down Expand Up @@ -813,7 +817,7 @@ var Renderer = function () {
}, {
key: 'listenForRender',
value: function listenForRender() {
if (this.options.manualRender) {
if (this.options.manualShow) {
return;
}

Expand Down Expand Up @@ -854,7 +858,7 @@ var Renderer = function () {
key: 'onTriggerLeave',
value: function onTriggerLeave() {
this.triggerElement.removeEventListener(this.options.hideOn, this.onTriggerLeave);
this.shouldHide();
this.onHideEvent('triggerLeave');
}
}, {
key: 'onDocumentClick',
Expand All @@ -863,6 +867,17 @@ var Renderer = function () {
return;
}
document.body.removeEventListener('click', this.onDocumentClick);
this.onHideEvent('documentClick');
}
}, {
key: 'onHideEvent',
value: function onHideEvent(hideEvent) {
this.options.onHideEvent(hideEvent);

if (this.options.manualHide) {
return;
}

this.shouldHide();
}
}, {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "popover.js",
"version": "0.0.8",
"version": "0.0.9",
"description": "",
"main": "dist/popover.js",
"scripts": {
Expand Down
3 changes: 2 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ const defaults = {
hideOn: 'documentClick',
showDelay: 0,
hideDelay: 0,
manualRender: true,
manualShow: false,
manualHide: false,
themeClass: 'popoverjs--default',
unnecessaryRepositioning: false,
resizePositioning: true,
Expand Down
15 changes: 13 additions & 2 deletions src/renderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ import './styles/main.scss';
const defaults = {
showOn: 'click',
hideOn: 'documentClick',
manualShow: false,
manualHide: false,
onHideEvent: () => {},
};

class Renderer {
Expand Down Expand Up @@ -46,7 +49,7 @@ class Renderer {
}

listenForRender() {
if (this.options.manualRender) { return; }
if (this.options.manualShow) { return; }

oneEvent(this.triggerElement, this.options.showOn, this.onTriggerClick);
}
Expand Down Expand Up @@ -81,12 +84,20 @@ class Renderer {

onTriggerLeave() {
this.triggerElement.removeEventListener(this.options.hideOn, this.onTriggerLeave);
this.shouldHide();
this.onHideEvent('triggerLeave');
}

onDocumentClick(e) {
if (this.popoverElement.contains(e.target)) { return; }
document.body.removeEventListener('click', this.onDocumentClick);
this.onHideEvent('documentClick');
}

onHideEvent(hideEvent) {
this.options.onHideEvent(hideEvent);

if (this.options.manualHide) { return; }

this.shouldHide();
}

Expand Down

0 comments on commit 7653652

Please sign in to comment.