-
Notifications
You must be signed in to change notification settings - Fork 12
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
Change timer for opening modal to transitionEnd event listener #7
Changes from all commits
0fe821a
00fcece
c5cb6f2
46841b0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
/** | ||
* Returns whether an element has CSS transitions applied directly on itself. | ||
* | ||
* @method hasTransitions | ||
* @param {Element} element | ||
* @return Boolean | ||
*/ | ||
export default function hasTransitions(element) { | ||
const { transitionProperty, transitionDuration } = window.getComputedStyle(element); | ||
|
||
return !(transitionProperty === 'all' && transitionDuration === '0s'); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import onTransitionEnd from './on-transition-end'; | ||
import hasTransitions from './has-transitions'; | ||
|
||
export { | ||
onTransitionEnd, | ||
hasTransitions | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import Ember from 'ember'; | ||
|
||
const { run } = Ember; | ||
const eventNames = { | ||
transition: 'transitionend', | ||
MozTransition: 'transitionend', | ||
OTransition: 'oTransitionEnd', | ||
WebkitTransition: 'webkitTransitionEnd', | ||
msTransition: 'MSTransitionEnd' | ||
}; | ||
|
||
/** | ||
* Find transition-end event name on current browser. | ||
* | ||
* @method findTransitionEventName | ||
* @return Boolean | ||
* @private | ||
*/ | ||
function findTransitionEventName() { | ||
const div = document.createElement('div'); | ||
const key = Object.keys(eventNames).find((eventName) => eventName in div.style); | ||
|
||
return eventNames[key]; | ||
} | ||
|
||
const transitionEndEventName = findTransitionEventName(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. div por parámetro There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done. |
||
|
||
/** | ||
* Subscribes a callback to a transition-end event by transition property on a given element. | ||
* | ||
* @method onTransitionEnd | ||
* @param {Element} element | ||
* @param {Function} callback | ||
* @param {String} transitionProperty | ||
* @param {Boolean} once | ||
*/ | ||
export default function onTransitionEnd(element, callback, transitionProperty = 'all', once = false) { | ||
const fn = (e) => { | ||
const { propertyName, type } = e; | ||
|
||
if (transitionProperty !== 'all' && propertyName !== transitionProperty) { | ||
return; | ||
} | ||
|
||
if (once) { | ||
element.removeEventListener(type, fn, true); | ||
} | ||
|
||
run(null, callback, e); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. See #9 |
||
}; | ||
|
||
element.addEventListener(transitionEndEventName, fn, true); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export { default } from 'ember-modal-service/utils/css-transitions/has-transitions'; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export { default } from 'ember-modal-service/utils/css-transitions'; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export { default } from 'ember-modal-service/utils/css-transitions/on-transition-end'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Asegura que getComputedStyle funciona en safari
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Link to CanIUse. It seems to work on modern browsers.