-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
17 changed files
with
355 additions
and
98 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,12 @@ | ||
module.exports = { | ||
|
||
priority: 1000, | ||
isLiteral: true, | ||
|
||
bind: function () { | ||
this.el.__vueTransition = this.expression | ||
this.el.__v_trans = { | ||
id: this.expression | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,128 @@ | ||
var _ = require('../util') | ||
var Batcher = require('../batcher') | ||
var batcher = new Batcher() | ||
var transDurationProp = _.transitionProp + 'Duration' | ||
var animDurationProp = _.animationProp + 'Duration' | ||
|
||
/** | ||
* Force layout before triggering transitions/animations | ||
*/ | ||
|
||
batcher._preFlush = function () { | ||
/* jshint unused: false */ | ||
var f = document.body.offsetHeight | ||
} | ||
|
||
/** | ||
* Get an element's transition type based on the | ||
* calculated styles | ||
* | ||
* @param {Element} el | ||
* @return {Number} | ||
* 1 - transition | ||
* 2 - animation | ||
*/ | ||
|
||
function getTransitionType (el) { | ||
var styles = window.getComputedStyle(el) | ||
if (styles[transDurationProp] !== '0s') { | ||
return 1 | ||
} else if (styles[animDurationProp] !== '0s') { | ||
return 2 | ||
} | ||
} | ||
|
||
/** | ||
* Apply CSS transition to an element. | ||
* | ||
* @param {Element} el | ||
* @param {Number} direction - 1: enter, -1: leave | ||
* @param {Function} op - the actual DOM operation | ||
* @param {Object} data - target element's transition data | ||
*/ | ||
|
||
module.exports = function (el, direction, op, data) { | ||
var classList = el.classList | ||
var callback = data.callback | ||
var prefix = data.id || 'v' | ||
var enterClass = prefix + '-enter' | ||
var leaveClass = prefix + '-leave' | ||
// clean up potential previously running transitions | ||
if (data.callback) { | ||
el.removeEventListener(data.event, callback) | ||
classList.remove(enterClass) | ||
classList.remove(leaveClass) | ||
data.event = data.callback = null | ||
} | ||
var transitionType, onEnd, endEvent | ||
|
||
if (direction > 0) { // enter | ||
|
||
classList.add(enterClass) | ||
op() | ||
transitionType = getTransitionType(el) | ||
if (transitionType === 1) { | ||
// Enter Transition | ||
// | ||
// We need to force a reflow to have the enterClass | ||
// applied before removing it to trigger the | ||
// transition, so they are batched to make sure | ||
// there's only one reflow for everything. | ||
batcher.push({ | ||
run: function () { | ||
classList.remove(enterClass) | ||
} | ||
}) | ||
} else if (transitionType === 2) { | ||
// Enter Animation | ||
// | ||
// Animations are triggered automatically as the | ||
// element is inserted into the DOM, so we just | ||
// listen for the animationend event. | ||
endEvent = data.event = _.animationEndEvent | ||
onEnd = data.callback = function (e) { | ||
if (e.target === el) { | ||
el.removeEventListener(endEvent, onEnd) | ||
data.event = data.callback = null | ||
classList.remove(enterClass) | ||
} | ||
} | ||
el.addEventListener(endEvent, onEnd) | ||
} | ||
|
||
} else { // leave | ||
|
||
transitionType = getTransitionType(el) | ||
if ( | ||
transitionType && | ||
(el.offsetWidth || el.offsetHeight) | ||
) { | ||
// Leave Transition/Animation | ||
// | ||
// We push it to the batcher to ensure it triggers | ||
// in the same frame with other enter transitions | ||
// happening at the same time. | ||
batcher.push({ | ||
run: function () { | ||
classList.add(leaveClass) | ||
} | ||
}) | ||
endEvent = data.event = transitionType === 1 | ||
? _.transitionEndEvent | ||
: _.animationEndEvent | ||
onEnd = data.callback = function (e) { | ||
if (e.target === el) { | ||
el.removeEventListener(endEvent, onEnd) | ||
data.event = data.callback = null | ||
// actually remove node here | ||
op() | ||
classList.remove(leaveClass) | ||
} | ||
} | ||
el.addEventListener(endEvent, onEnd) | ||
} else { | ||
op() | ||
} | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,115 @@ | ||
var _ = require('../util') | ||
var applyCSSTransition = require('./css') | ||
var applyJSTransition = require('./js') | ||
|
||
// TODO | ||
// placeholder for testing | ||
/** | ||
* Append with transition. | ||
* | ||
* @oaram {Element} el | ||
* @param {Element} target | ||
* @param {Function} [cb] | ||
* @param {Vue} vm | ||
*/ | ||
|
||
exports.append = function (el, target, cb, vm) { | ||
target.appendChild(el) | ||
cb && cb() | ||
apply(el, 1, function () { | ||
target.appendChild(el) | ||
if (cb) cb() | ||
}, vm) | ||
} | ||
|
||
/** | ||
* InsertBefore with transition. | ||
* | ||
* @oaram {Element} el | ||
* @param {Element} target | ||
* @param {Function} [cb] | ||
* @param {Vue} vm | ||
*/ | ||
|
||
exports.before = function (el, target, cb, vm) { | ||
_.before(el, target) | ||
cb && cb() | ||
apply(el, 1, function () { | ||
_.before(el, target) | ||
if (cb) cb() | ||
}, vm) | ||
} | ||
|
||
/** | ||
* Remove with transition. | ||
* | ||
* @oaram {Element} el | ||
* @param {Function} [cb] | ||
* @param {Vue} vm | ||
*/ | ||
|
||
exports.remove = function (el, cb, vm) { | ||
_.remove(el) | ||
cb && cb() | ||
apply(el, -1, function () { | ||
_.remove(el) | ||
if (cb) cb() | ||
}, vm) | ||
} | ||
|
||
/** | ||
* Remove by appending to another parent with transition. | ||
* | ||
* @oaram {Element} el | ||
* @param {Element} target | ||
* @param {Function} [cb] | ||
* @param {Vue} vm | ||
*/ | ||
|
||
exports.removeThenAppend = function (el, target, cb, vm) { | ||
target.appendChild(el) | ||
cb && cb() | ||
apply(el, -1, function () { | ||
target.appendChild(el) | ||
if (cb) cb() | ||
}, vm) | ||
} | ||
|
||
exports.apply = function (el, direction, cb, vm) { | ||
|
||
/** | ||
* Apply transitions with an operation callback. | ||
* | ||
* @oaram {Element} el | ||
* @param {Number} direction | ||
* 1: enter | ||
* -1: leave | ||
* @param {Function} op - the actual DOM operation | ||
* @param {Vue} vm | ||
*/ | ||
|
||
var apply = exports.apply = function (el, direction, op, vm) { | ||
function applyOp () { | ||
op() | ||
vm._callHook(direction > 0 ? 'attached' : 'detached') | ||
} | ||
// if the vm is being manipulated by a parent directive | ||
// during the parent's compilation phase, we skip the | ||
// animation. | ||
if (vm.$parent && !vm.$parent._isCompiled) { | ||
applyOp() | ||
return | ||
} | ||
// determine the transition type on the element | ||
var transData = el.__v_trans | ||
var registry = vm.$options.transitions | ||
var jsTransition = transData && registry[transData.id] | ||
if (jsTransition) { | ||
// js | ||
applyJSTransition( | ||
el, | ||
direction, | ||
applyOp, | ||
jsTransition | ||
) | ||
} else if (transData && _.transitionEndEvent) { | ||
// css | ||
applyCSSTransition( | ||
el, | ||
direction, | ||
applyOp, | ||
transData | ||
) | ||
} else { | ||
// not applicable | ||
applyOp() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
module.exports = function () { | ||
|
||
} |
Oops, something went wrong.