Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Allow the surface element to be passed in
Also expose the tag name that is expected. This specifically allows
React to render the top DOM node as part of it's batching.
  • Loading branch information
sebmarkbage committed Nov 6, 2014
1 parent f5cb1e9 commit 5dcd137
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 8 deletions.
6 changes: 4 additions & 2 deletions modes/canvas/surface.js
Expand Up @@ -20,8 +20,8 @@ var previousHit = null, previousHitSurface = null;

var CanvasSurface = Class(Element, Container, {

initialize: function(width, height){
var element = this.element = document.createElement('canvas');
initialize: function(width, height, existingElement){
var element = this.element = existingElement || document.createElement('canvas');
var context = this.context = element.getContext('2d');
this._valid = true;
if (width != null && height != null) this.resize(width, height);
Expand Down Expand Up @@ -137,4 +137,6 @@ var CanvasSurface = Class(Element, Container, {

});

CanvasSurface.tagName = 'canvas';

module.exports = CanvasSurface;
10 changes: 7 additions & 3 deletions modes/svg/surface.js
Expand Up @@ -3,10 +3,10 @@ var Container = require('../../dom/container');
var Element = require('../../dom/native');
var DOM = require('./dom');

module.exports = Class(Element, Container, {
var SVGSurface = Class(Element, Container, {

initialize: function SVGSurface(width, height){
var element = this.element = DOM.createElement('svg');
initialize: function SVGSurface(width, height, existingElement){
var element = this.element = existingElement || DOM.createElement('svg');
element.setAttribute('xmlns', DOM.NS);
element.setAttribute('version', 1.1);
var defs = this.defs = DOM.createElement('defs');
Expand All @@ -24,3 +24,7 @@ module.exports = Class(Element, Container, {
}

});

SVGSurface.tagName = 'svg';

module.exports = SVGSurface;
10 changes: 7 additions & 3 deletions modes/vml/surface.js
Expand Up @@ -5,10 +5,10 @@ var DOM = require('./dom');

var precision = 100;

module.exports = Class(Element, Container, {
var VMLSurface = Class(Element, Container, {

initialize: function VMLSurface(width, height){
this.element = document.createElement('vml');
initialize: function VMLSurface(width, height, existingElement){
this.element = existingElement || document.createElement('vml');
this.containerElement = DOM.createElement('group');
this.element.appendChild(this.containerElement);
if (width != null && height != null) this.resize(width, height);
Expand All @@ -35,3 +35,7 @@ module.exports = Class(Element, Container, {
}

});

VMLSurface.tagName = 'vml';

module.exports = VMLSurface;

0 comments on commit 5dcd137

Please sign in to comment.