(function (exports) {
"use strict";
var
ss = document.styleSheets[0],
body = document.body,
el = document.querySelector('#main');
Object.defineProperties(Array.prototype, {
contains: {
value: function (item) {
return this.indexOf(item) > -1;
}
},
include: {
value: function (item) {
if (!this.contains(item)) {
this.push(item);
}
return this;
}
},
remove: {
value: function (item) {
var remove = function () {
var pos = this.indexOf(item);
if (pos > -1) {
/* THIS MAKES FIREFOX NIGHTLY CRASH AT SOME POINT */
this.splice(pos, 1);
}
};
while (this.contains(item)) {
remove.call(this);
}
return this;
}
}
});
Object.defineProperties(Array, {
from: {
value: function (obj) {
return Array.isArray(obj) ? obj : [obj];
}
}
});
var Animorph = function (el) {
var style = el.style;
return {
setEvent: function (property, value, separator) {
el.addEventListener('transitionend', function remover(e) {
if (e.propertyName === property) {
this.remove(property, value, separator);
this.set(property, val);
el.removeEventListener('transitionend', remover, true);
}
}.bind(this), true);
return this;
},
add: function (property, value, separator) {
separator = separator || ', ';
return this.set(property, (style.getPropertyValue(property) || '').split(separator).remove('').include(value).join(separator));
},
remove: function (property, value, separator) {
separator = separator || ', ';
return this.set(property, (style.getPropertyValue(property) || '').split(separator).remove('').remove(value).join(separator));
},
set: function (property, value, important) {
style.setProperty(property, value, important || '');
return this;
},
configure: function (property, duration) {
return this.setEvent('-moz-transition-property', property)
.setEvent('-moz-transition-duration', duration)
.add('-moz-transition-property', property)
.add('-moz-transition-duration', duration);
},
bgColor: function (color, duration) {
return this.configure('background-color', duration)
.set('background-color', color);
},
left: function (position, duration) {
return this.configure('left', duration)
.set('left', position);
},
skew: function (deg, duration) {
deg = 'skew(' + deg + ')';
return this.setEvent('-moz-transform', deg, ' ')
.configure('-moz-transform', duration)
.add('-moz-transform', deg, ' ');
},
rotate: function (deg, duration) {
deg = 'rotate(' + deg + ')';
return this.setEvent('-moz-transform', deg, ' ')
.configure('-moz-transform', duration)
.add('-moz-transform', deg, ' ');
},
translate: function (translation, duration) {
translation = 'translate(' + translation + ')';
return this.setEvent('-moz-transform', translation, ' ')
.configure('-moz-transform', duration)
.add('-moz-transform', translation, ' ');
}
}
};
ss.insertRule('body {background-color: red;}', 0);
setTimeout(function () {
Animorph(el).bgColor('green', '2s').left('400px', '2s').translate('-100px', '2s');
setTimeout(function () {
Animorph(el).rotate('-15deg', '2s');
//Animorph(el).skew('40deg', '2s');
}, 1000);
el.addEventListener('transitionend', function (e) {
}, true);
}, 100);
}(window));