1 define([ 'util/ensureCallback', 'features', 'Modernizr', 'sprites/renderers/DomContext', 'util/create', 'sprites/container', 'util/quickPromise' ], function (ensureCallback, features, Modernizr, DomContext, create, container, quickPromise) {
2 function RenderContext(sourceData, frameData) {
3 if (!Modernizr.csstransforms3d) {
7 this.loadPromise = quickPromise();
8 DomContext.call(this, sourceData, frameData, this.loadPromise.resolve);
10 this.elements.forEach(function (frameElements) {
11 frameElements.forEach(function (element) {
12 element.style[features.transformOriginStyleProperty] = '0 0';
16 this.transformData = frameData.map(function (objectTransforms) {
17 return objectTransforms.map(function (t) {
18 return t.cssTransform3d;
22 this.containerElement = container();
25 RenderContext.prototype = create(DomContext.prototype);
27 RenderContext.prototype.load = function load(callback) {
28 callback = ensureCallback(callback);
30 if (!Modernizr.csstransforms3d) {
31 callback(new Error('Not supported'));
35 document.body.appendChild(this.containerElement);
37 this.loadPromise.then(function () {
42 RenderContext.prototype.unload = function unload() {
43 this.containerElement.parentNode.removeChild(this.containerElement);
44 DomContext.prototype.unload.call(this);
47 var transformStyleProperty = features.transformStyleProperty;
49 RenderContext.prototype.processElements = function processElements(elements, transforms) {
50 var count = transforms.length;
52 for (i = 0; i < count; ++i) {
53 var element = elements[i];
54 element.style[transformStyleProperty] = transforms[i];
57 // Elements not in the DOM need to be added
58 if (!element.parentNode) {
59 this.containerElement.appendChild(element);
64 return function (element, frameData) {
65 return new RenderContext(element, frameData);