Skip to content

Commit

Permalink
Remove DOM calls on canvas only platforms
Browse files Browse the repository at this point in the history
  • Loading branch information
tonistiigi committed Nov 4, 2013
1 parent 6bcedbe commit f572dc5
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 6 deletions.
11 changes: 7 additions & 4 deletions lime/src/director.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ goog.require('goog.math.Vec2');
goog.require('goog.style');
goog.require('lime');
goog.require('lime.Node');
goog.require('lime.dom');
goog.require('lime.events.EventDispatcher');
goog.require('lime.helper.PauseScene');
goog.require('lime.Renderer.CANVAS');
Expand Down Expand Up @@ -58,7 +59,8 @@ lime.Director = function(parentElement, opt_width, opt_height) {

this.domClassName = goog.getCssName('lime-director');

if (parentElement.tagName === 'CANVAS') {
if (parentElement.getContext) {
this.container.tagName = 'CANVAS'; // Ejecta hack.
this.setRenderer(lime.Renderer.CANVAS);
this.domElement = this.container;
}
Expand Down Expand Up @@ -243,7 +245,7 @@ lime.Director.prototype.setDisplayFPS = function(value) {
this.frames_ = 0;
this.accumDt_ = 0;

if (!this.domElement) return;
if (!lime.dom.isDOMSupported()) return;

this.fpsElement_ = goog.dom.createDom('div');
goog.dom.classes.add(this.fpsElement_, goog.getCssName('lime-fps'));
Expand Down Expand Up @@ -324,10 +326,10 @@ lime.Director.prototype.replaceScene = function(scene, opt_transition,
this.sceneStack_.length = 0;

this.sceneStack_.push(scene);
if (scene.domElement) {
/*if (scene.domElement) {
// scene.domElement.style['display']='none';
// this.domElement.appendChild(scene.domElement);
}
}*/
this.appendChild(scene);

//scene.parent_ = this;
Expand Down Expand Up @@ -577,6 +579,7 @@ lime.Director.prototype.invalidateSize_ = function() {
* web application on iOS devices
*/
lime.Director.prototype.makeMobileWebAppCapable = function() {
if (!lime.dom.isDOMSupported()) return;

var meta = document.createElement('meta');
meta.name = 'apple-mobile-web-app-capable';
Expand Down
12 changes: 12 additions & 0 deletions lime/src/helper/dom.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
goog.provide('lime.dom');
goog.require('goog.dom');

lime.dom.isDOMSupported = function() {
// This works for Ejecta. Probably not for others. Pull request!
return !!document.head.parentNode;

This comment has been minimized.

Copy link
@stringa

stringa Mar 19, 2014

Contributor

I was looking at the Ejecta source and they define window.ejecta as an object in the scene. Is it good to check for window.ejecta instead of your current check?

The following is in Ejecta.js

// The 'ej' object provides some basic info and utility functions
var ej = window.ejecta = new Ejecta.EjectaCore();

This comment has been minimized.

Copy link
@tonistiigi

tonistiigi Mar 19, 2014

Author Member

Can you also test CocoonJS?

This comment has been minimized.

Copy link
@stringa

stringa Mar 20, 2014

Contributor

I just commented here because it was the original changeset. lime.dom.IsDOMSupported currently has a check for cocoon.

I'm just suggesting that we could change that line of code. The current function is a follows...

lime.dom.isDOMSupported = function() {
if (goog.global['CocoonJS_ENV'] === true) return false;
// This works for Ejecta. Probably not for others. Pull request!
return !!document.head.parentNode;
}

}

var old = goog.dom.getOwnerDocument;
goog.dom.getOwnerDocument = function() {
return old.apply(goog.dom, arguments) || document;
}
6 changes: 4 additions & 2 deletions lime/src/lime.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ goog.provide('lime');

goog.require('goog.style');
goog.require('lime.css');
goog.require('lime.dom');
goog.require('lime.userAgent');

(function() {
Expand Down Expand Up @@ -107,6 +108,7 @@ lime.Transition = {
OPACITY: 5
};


goog.style.installStyles(lime.css.css(null, null));
if (lime.dom.isDOMSupported()) {
goog.style.installStyles(lime.css.css(null, null));
}

0 comments on commit f572dc5

Please sign in to comment.