Skip to content

Instantly share code, notes, and snippets.

@bryanforbes
Created May 13, 2011 16:05
Show Gist options
  • Select an option

  • Save bryanforbes/970808 to your computer and use it in GitHub Desktop.

Select an option

Save bryanforbes/970808 to your computer and use it in GitHub Desktop.
gfx situation
// dojox/gfx.js
define(['dojo/_base/kernel'], function(dojo){
var gfx = dojo.getObject("gfx", true, dojox);
// this is actualy added in dojox/gfx/_base.js
dojo.mixin(gfx, {
switchTo: function(renderer){
var ns = gfx[renderer];
if(ns){
dojo.mixin(gfx, ns);
}
}
});
// this is actually set by checking a few different
// renderer types
gfx.renderer = 'svg';
if(gfx[gfx.renderer]){
// already loaded
gfx.switchTo(gfx.renderer);
}else{
// load
gfx.loadAndSwitch = gfx.renderer;
require(['./' + gfx.renderer], function(renderer){
if(dojo.config.isDebug){
console.debug("loaded gfx renderer:",renderer);
}
});
}
return gfx;
});
<!DOCTYPE HTML>
<html lang="en">
<head>
<meta charset="utf-8">
<title>GFX situation</title>
<script>
var dojoConfig = {
async: true
};
</script>
<script src="dojo/dojo.js"></script>
<script>
require(['dojox/gfx'], function(gfx){
console.log("Is the createSurface function defined? " + !!gfx.createSurface);
});
</script>
</head>
</html>
// dojox/gfx/svg.js
define(['dojox/gfx'], function(gfx){
var svg = dojo.getObject("gfx.svg", true, dojox);
svg.createSurface = function(){};
// see if we are required to initilize
if(gfx.loadAndSwitch === "svg"){
gfx.switchTo("svg");
delete gfx.loadAndSwitch;
}
return svg;
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment