Skip to content

Commit

Permalink
Use css transition-duration in transitionEndEmulator
Browse files Browse the repository at this point in the history
  • Loading branch information
pvdlg committed Jan 6, 2017
1 parent 65ffb1c commit 3af1b36
Show file tree
Hide file tree
Showing 7 changed files with 15 additions and 20 deletions.
3 changes: 1 addition & 2 deletions js/src/alert.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ const Alert = (($) => {
const EVENT_KEY = `.${DATA_KEY}`
const DATA_API_KEY = '.data-api'
const JQUERY_NO_CONFLICT = $.fn[NAME]
const TRANSITION_DURATION = 150

const Selector = {
DISMISS : '[data-dismiss="alert"]'
Expand Down Expand Up @@ -118,7 +117,7 @@ const Alert = (($) => {

$(element)
.one(Util.TRANSITION_END, (event) => this._destroyElement(element, event))
.emulateTransitionEnd(TRANSITION_DURATION)
.emulateTransitionEnd()
}

_destroyElement(element) {
Expand Down
3 changes: 1 addition & 2 deletions js/src/carousel.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ const Carousel = (($) => {
const EVENT_KEY = `.${DATA_KEY}`
const DATA_API_KEY = '.data-api'
const JQUERY_NO_CONFLICT = $.fn[NAME]
const TRANSITION_DURATION = 600
const ARROW_LEFT_KEYCODE = 37 // KeyboardEvent.which value for left arrow key
const ARROW_RIGHT_KEYCODE = 39 // KeyboardEvent.which value for right arrow key

Expand Down Expand Up @@ -380,7 +379,7 @@ const Carousel = (($) => {
setTimeout(() => $(this._element).trigger(slidEvent), 0)

})
.emulateTransitionEnd(TRANSITION_DURATION)
.emulateTransitionEnd()

} else {
$(activeElement).removeClass(ClassName.ACTIVE)
Expand Down
5 changes: 2 additions & 3 deletions js/src/collapse.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ const Collapse = (($) => {
const EVENT_KEY = `.${DATA_KEY}`
const DATA_API_KEY = '.data-api'
const JQUERY_NO_CONFLICT = $.fn[NAME]
const TRANSITION_DURATION = 600

const Default = {
toggle : true,
Expand Down Expand Up @@ -190,7 +189,7 @@ const Collapse = (($) => {

$(this._element)
.one(Util.TRANSITION_END, complete)
.emulateTransitionEnd(TRANSITION_DURATION)
.emulateTransitionEnd()

this._element.style[dimension] = `${this._element[scrollSize]}px`
}
Expand Down Expand Up @@ -250,7 +249,7 @@ const Collapse = (($) => {

$(this._element)
.one(Util.TRANSITION_END, complete)
.emulateTransitionEnd(TRANSITION_DURATION)
.emulateTransitionEnd()
}

setTransitioning(isTransitioning) {
Expand Down
10 changes: 4 additions & 6 deletions js/src/modal.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@ const Modal = (($) => {
const EVENT_KEY = `.${DATA_KEY}`
const DATA_API_KEY = '.data-api'
const JQUERY_NO_CONFLICT = $.fn[NAME]
const TRANSITION_DURATION = 300
const BACKDROP_TRANSITION_DURATION = 150
const ESCAPE_KEYCODE = 27 // KeyboardEvent.which value for Escape (Esc) key

const Default = {
Expand Down Expand Up @@ -193,7 +191,7 @@ const Modal = (($) => {
if (transition) {
$(this._element)
.one(Util.TRANSITION_END, (event) => this._hideModal(event))
.emulateTransitionEnd(TRANSITION_DURATION)
.emulateTransitionEnd()
} else {
this._hideModal()
}
Expand Down Expand Up @@ -263,7 +261,7 @@ const Modal = (($) => {
if (transition) {
$(this._dialog)
.one(Util.TRANSITION_END, transitionComplete)
.emulateTransitionEnd(TRANSITION_DURATION)
.emulateTransitionEnd()
} else {
transitionComplete()
}
Expand Down Expand Up @@ -369,7 +367,7 @@ const Modal = (($) => {

$(this._backdrop)
.one(Util.TRANSITION_END, callback)
.emulateTransitionEnd(BACKDROP_TRANSITION_DURATION)
.emulateTransitionEnd()

} else if (!this._isShown && this._backdrop) {
$(this._backdrop).removeClass(ClassName.SHOW)
Expand All @@ -385,7 +383,7 @@ const Modal = (($) => {
$(this._element).hasClass(ClassName.FADE)) {
$(this._backdrop)
.one(Util.TRANSITION_END, callbackRemove)
.emulateTransitionEnd(BACKDROP_TRANSITION_DURATION)
.emulateTransitionEnd()
} else {
callbackRemove()
}
Expand Down
3 changes: 1 addition & 2 deletions js/src/tab.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ const Tab = (($) => {
const EVENT_KEY = `.${DATA_KEY}`
const DATA_API_KEY = '.data-api'
const JQUERY_NO_CONFLICT = $.fn[NAME]
const TRANSITION_DURATION = 150

const Event = {
HIDE : `hide${EVENT_KEY}`,
Expand Down Expand Up @@ -168,7 +167,7 @@ const Tab = (($) => {
if (active && isTransitioning) {
$(active)
.one(Util.TRANSITION_END, complete)
.emulateTransitionEnd(TRANSITION_DURATION)
.emulateTransitionEnd()

} else {
complete()
Expand Down
5 changes: 2 additions & 3 deletions js/src/tooltip.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ const Tooltip = (($) => {
const DATA_KEY = 'bs.tooltip'
const EVENT_KEY = `.${DATA_KEY}`
const JQUERY_NO_CONFLICT = $.fn[NAME]
const TRANSITION_DURATION = 150
const CLASS_PREFIX = 'bs-tether'

const Default = {
Expand Down Expand Up @@ -321,7 +320,7 @@ const Tooltip = (($) => {
this._isTransitioning = true
$(this.tip)
.one(Util.TRANSITION_END, complete)
.emulateTransitionEnd(Tooltip._TRANSITION_DURATION)
.emulateTransitionEnd()
return
}

Expand Down Expand Up @@ -367,7 +366,7 @@ const Tooltip = (($) => {
this._isTransitioning = true
$(tip)
.one(Util.TRANSITION_END, complete)
.emulateTransitionEnd(TRANSITION_DURATION)
.emulateTransitionEnd()

} else {
complete()
Expand Down
6 changes: 4 additions & 2 deletions js/src/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ const Util = (($) => {

const MAX_UID = 1000000

const MILLIS = 1000

const TransitionEndEvent = {
WebkitTransition : 'webkitTransitionEnd',
MozTransition : 'transitionend',
Expand Down Expand Up @@ -65,9 +67,9 @@ const Util = (($) => {
return false
}

function transitionEndEmulator(duration) {
function transitionEndEmulator() {
let called = false

const duration = this.length ? parseFloat(this.css('transition-duration') || this.css('-webkit-transition-duration') || this.css('-moz-transition-duration') || this.css('-ms-transition-duration') || this.css('-o-transition-duration') || 0) * MILLIS : 0
$(this).one(Util.TRANSITION_END, () => {
called = true
})
Expand Down

0 comments on commit 3af1b36

Please sign in to comment.