Created
February 25, 2010 16:54
-
-
Save neonstalwart/314720 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<html> | |
<head> | |
<title>Dojo Test Page</title> | |
<link rel='stylesheet' type='text/css' href='http://ajax.googleapis.com/ajax/libs/dojo/1.4/dojo/resources/dojo.css'> | |
<link rel='stylesheet' type='text/css' href='http://ajax.googleapis.com/ajax/libs/dojo/1.4/dijit/themes/tundra/tundra.css'> | |
<script type="text/javascript" src='http://ajax.googleapis.com/ajax/libs/dojo/1.4/dojo/dojo.xd.js'></script> | |
<script type="text/javascript"> | |
dojo.require('dijit._Widget'); | |
dojo.require('dijit._Templated'); | |
dojo.require('dojo.parser'); | |
dojo.require('dijit.form.Button'); | |
dojo.addOnLoad(function(){ | |
console.log(dojo.version); | |
dijit._Widget.extend({ | |
buildRendering: function(){ | |
// this allows dijit._Templated to call this.inherited | |
if (!this.domNode) { | |
this.domNode = this.srcNodeRef || dojo.create('div'); | |
} | |
} | |
}); | |
// this is just the same buildRendering with a call to this.inherited at the end | |
dijit._Templated.extend({ | |
buildRendering: function(){ | |
console.log('i am the new buildRendering'); | |
var cached = dijit._Templated.getCachedTemplate(this.templatePath, this.templateString, this._skipNodeCache); | |
var node; | |
if (dojo.isString(cached)) { | |
node = dojo._toDom(this._stringRepl(cached)); | |
if (node.nodeType != 1) { | |
// Flag common problems such as templates with multiple top level nodes (nodeType == 11) | |
throw new Error("Invalid template: " + cached); | |
} | |
} | |
else { | |
// if it's a node, all we have to do is clone it | |
node = cached.cloneNode(true); | |
} | |
this.domNode = node; | |
// recurse through the node, looking for, and attaching to, our | |
// attachment points and events, which should be defined on the template node. | |
this._attachTemplateNodes(node); | |
if (this.widgetsInTemplate) { | |
// Make sure dojoType is used for parsing widgets in template. | |
// The dojo.parser.query could be changed from multiversion support. | |
var parser = dojo.parser, qry, attr; | |
if (parser._query != "[dojoType]") { | |
qry = parser._query; | |
attr = parser._attrName; | |
parser._query = "[dojoType]"; | |
parser._attrName = "dojoType"; | |
} | |
// Store widgets that we need to start at a later point in time | |
var cw = (this._startupWidgets = dojo.parser.parse(node, { | |
noStart: !this._earlyTemplatedStartup | |
})); | |
// Restore the query. | |
if (qry) { | |
parser._query = qry; | |
parser._attrName = attr; | |
} | |
this._supportingWidgets = dijit.findWidgets(node); | |
this._attachTemplateNodes(cw, function(n, p){ | |
return n[p]; | |
}); | |
} | |
this._fillContent(this.srcNodeRef); | |
this.inherited(arguments); | |
} | |
}); | |
dojo.declare('my.foo', [dijit._Widget, dijit._Templated], { | |
templateString: "<div><div dojoType='dijit.form.Button'>Do Nothing</div></div>", | |
// adding this gives the desired behavior | |
/*buildRendering: function(){ | |
this.inherited(arguments); | |
},*/ | |
widgetsInTemplate: true | |
}); | |
console.log('parsing...'); | |
dojo.parser.parse(); | |
console.log('programmatic'); | |
var button = new my.foo().placeAt('prog'); | |
}); | |
</script> | |
</head> | |
<body class="tundra"> | |
<div id='foo' dojoType='my.foo'></div> | |
<div id='prog'></div> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment