Skip to content

Commit

Permalink
Detects whether transitions are applied to modal element before closi…
Browse files Browse the repository at this point in the history
…ng it with transitions.
  • Loading branch information
Ben Ceglowski committed Feb 3, 2015
1 parent 83e70da commit 2abb4fa
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 7 deletions.
20 changes: 18 additions & 2 deletions dist/vanilla-modal.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ var _prototypeProperties = function (child, staticProps, instanceProps) {

/**
* @class VanillaModal
* @version 1.0.1
* @version 1.1.0
* @author Ben Ceglowski
*/
var VanillaModal = (function () {
Expand Down Expand Up @@ -220,6 +220,21 @@ var VanillaModal = (function () {
enumerable: true,
configurable: true
},
_detectTransition: {
value: function DetectTransition() {
var css = window.getComputedStyle(this.$.modal, null);
var transitionDuration = ["transitionDuration", "oTransitionDuration", "MozTransitionDuration", "webkitTransitionDuration"];
var hasTransition = transitionDuration.filter(function (i) {
if (typeof css[i] === "string" && parseFloat(css[i]) > 0) {
return true;
}
});
return hasTransition.length ? true : false;
},
writable: true,
enumerable: true,
configurable: true
},
_close: {

/**
Expand All @@ -228,7 +243,8 @@ var VanillaModal = (function () {
value: function Close(e) {
if (typeof this.$$.onBeforeClose === "function") this.$$.onBeforeClose.call(this);
this._removeClass(this.$.page, this.$$["class"]);
if (this.$$.transitions && this.$$.transitionEnd) {
var transitions = this._detectTransition();
if (this.$$.transitions && this.$$.transitionEnd && transitions) {
this._closeModalWithTransition();
} else {
this._closeModal();
Expand Down
4 changes: 2 additions & 2 deletions dist/vanilla-modal.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": "vanilla-modal",
"version": "1.0.1",
"version": "1.1.0",
"description": "A dependency-free CSS-driven plain JavaScript modal written in ECMAScript 6.",
"main": "dist/vanilla-modal.js",
"repository": {
Expand Down
16 changes: 14 additions & 2 deletions src/vanilla-modal.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/**
* @class VanillaModal
* @version 1.0.1
* @version 1.1.0
* @author Ben Ceglowski
*/
class VanillaModal {
Expand Down Expand Up @@ -165,13 +165,25 @@ class VanillaModal {
if (typeof this.$$.onOpen === 'function') this.$$.onOpen.call(this);
}

_detectTransition() {
var css = window.getComputedStyle(this.$.modal, null);
var transitionDuration = ['transitionDuration', 'oTransitionDuration', 'MozTransitionDuration', 'webkitTransitionDuration'];
var hasTransition = transitionDuration.filter(function(i) {
if (typeof css[i] === 'string' && parseFloat(css[i]) > 0) {
return true;
}
});
return (hasTransition.length) ? true : false;
}

/**
* @param {Event} e
*/
_close(e) {
if (typeof this.$$.onBeforeClose === 'function') this.$$.onBeforeClose.call(this);
this._removeClass(this.$.page, this.$$.class);
if (this.$$.transitions && this.$$.transitionEnd) {
var transitions = this._detectTransition();
if (this.$$.transitions && this.$$.transitionEnd && transitions) {
this._closeModalWithTransition();
} else {
this._closeModal();
Expand Down

0 comments on commit 2abb4fa

Please sign in to comment.