Skip to content

Instantly share code, notes, and snippets.

@csuwildcat
Created November 4, 2013 21:40
Show Gist options
  • Select an option

  • Save csuwildcat/7309632 to your computer and use it in GitHub Desktop.

Select an option

Save csuwildcat/7309632 to your computer and use it in GitHub Desktop.
Transitionall event and transition mixin
var replaceSpaces = / /g;
xtag.customEvents.transitionall = {
observe: { transitionend: document },
condition: function(e, tap){
var element = e.target;
if (!element.__transall__ && (element.__tranend__ ? element.__tranend__ > e.elapsedTime : true)) {
delete element.__transtime__;
var trans = element.__transall__ = { duration: 0 };
style = getComputedStyle(element),
props = (style.transitionProperty || style[xtag.prefix.js + 'TransitionProperty']).replace(replaceSpaces, '').split(','),
i = props.length;
trans.props = {};
trans.count = 0;
while (i--) if (!trans.props[props[i]]) {
trans.props[props[i]] = props[i];
trans.count++;
}
}
if (element.__transall__) {
var trans = element.__transall__,
prop = trans.props[e.propertyName] || trans.props[e.propertyName.split('-')[e.propertyName[0] == '-' ? 2 : 0]];
if (prop) {
trans.props[prop] = 0;
trans.count--;
}
if (!trans.count) {
element.__tranend__ = e.elapsedTime;
delete element.__transall__;
return true;
}
}
}
};
xtag.mixins.transition = {
events: {
'transitionall': function(e){
console.log(e.currentTarget == e.target);
if (this == e.target && !this.hasAttribute('transitioned')) {
console.log('transitionall');
this.removeAttribute('transition');
this.removeAttribute('transitioned');
}
}
},
accessors: {
transition: {
attribute: { unlink: true },
set: function(val){
this.xtag.transition = val;
if (!this.xtag.transitionraf) {
delete this.xtag.transitionProps;
if (!val) this.removeAttribute('transitioned');
else {
var element = this;
this.setAttribute('transition', val);
this.xtag.transitionraf = xtag.requestFrame(function(){
xtag.requestFrame(function(){
element.xtag.transitionraf = false;
if (element.xtag.transition) element.setAttribute('transitioned', '');
});
});
}
}
}
}
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment