Skip to content

Commit

Permalink
Reason for close robinparisi#169
Browse files Browse the repository at this point in the history
  • Loading branch information
joho1968 committed Sep 2, 2021
1 parent 9eadca7 commit f0360d2
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions src/tingle.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
root.tingle = factory()
}
}(this, function () {

/* ----------------------------------------------------------- */
/* == modal */
/* ----------------------------------------------------------- */
Expand All @@ -30,6 +31,8 @@
// extends config
this.opts = extend({}, defaults, options)

this._reasonForClose = this.tingleCloseNone();

// init modal
this.init()
}
Expand Down Expand Up @@ -79,6 +82,22 @@
this.modal = null
}

Modal.prototype.reasonForClose = function () {
return this._reasonForClose
}
Modal.prototype.tingleCloseNone = function () {
return(0);
}
Modal.prototype.tingleCloseKeyboard = function () {
return(1);
}
Modal.prototype.tingleCloseButton = function () {
return(2);
}
Modal.prototype.tingleCloseClickOutside = function () {
return(3);
}

Modal.prototype.isOpen = function () {
return !!this.modal.classList.contains('tingle-modal--visible')
}
Expand Down Expand Up @@ -124,6 +143,7 @@
// check if modal is bigger than screen height
this.checkOverflow()

this._reasonForClose = this.tingleCloseNone();
return this
}

Expand All @@ -139,6 +159,9 @@
this._busy(false)
return
}
if (this._reasonForClose == this.tingleCloseNone()) {
this._reasonForClose = this.tingleCloseButton();
}
}

document.body.classList.remove('tingle-enabled')
Expand Down Expand Up @@ -378,6 +401,7 @@
function _handleKeyboardNav (event) {
// escape key
if (this.opts.closeMethods.indexOf('escape') !== -1 && event.which === 27 && this.isOpen()) {
this._reasonForClose = this.tingleCloseKeyboard();
this.close()
}
}
Expand All @@ -394,6 +418,7 @@
// if click is outside the modal
if (this.opts.closeMethods.indexOf('overlay') !== -1 && !_findAncestor(event.target, 'tingle-modal') &&
event.clientX < this.modal.clientWidth) {
this._reasonForClose = this.tingleCloseClickOutside();
this.close()
}
}
Expand Down

0 comments on commit f0360d2

Please sign in to comment.