Skip to content

Commit

Permalink
_Templated, _TemplatedMixin, _WidgetsInTemplateMixin: remove deprecat…
Browse files Browse the repository at this point in the history
…ed APIs

- remove deprecated _Templated module, refs #1
- _TemplatedMixin: remove support for templatePath etc., refs #4
- _WidgetsInTemplateMixin: remove support for _earlyTemplatedStartup etc., refs #4
  • Loading branch information
wkeese committed May 10, 2013
1 parent a9bec3a commit b0d578c
Show file tree
Hide file tree
Showing 7 changed files with 47 additions and 656 deletions.
23 changes: 6 additions & 17 deletions _AttachMixin.js
Original file line number Diff line number Diff line change
@@ -1,23 +1,21 @@
define([
"require",
"dojo/_base/array", // array.forEach
"dojo/_base/connect", // remove for 2.0
"dojo/_base/declare", // declare
"dojo/_base/lang", // lang.getObject
"dojo/mouse",
"dojo/on",
"dojo/touch",
"./_WidgetBase"
], function(require, array, connect, declare, lang, mouse, on, touch, _WidgetBase){
], function(require, array, declare, lang, mouse, on, touch, _WidgetBase){

// module:
// dijit/_AttachMixin

// Map from string name like "mouseenter" to synthetic event like mouse.enter
var synthEvents = lang.delegate(touch, {
"mouseenter": mouse.enter,
"mouseleave": mouse.leave,
"keypress": connect._keypress // remove for 2.0
"mouseleave": mouse.leave
});

// To be lightweight, _AttachMixin doesn't require() dijit/a11yclick.
Expand Down Expand Up @@ -101,8 +99,8 @@ define([
// the dom node and it's descendants. This function iterates over all
// nodes and looks for these properties:
//
// - dojoAttachPoint/data-dojo-attach-point
// - dojoAttachEvent/data-dojo-attach-event
// - data-dojo-attach-point
// - data-dojo-attach-event
// rootNode: DomNode
// The node to search for properties. All descendants will be searched.
// tags:
Expand Down Expand Up @@ -134,7 +132,7 @@ define([

// Process data-dojo-attach-point
var _attachScope = this.attachScope || this,
attachPoint = getAttrFunc(baseNode, "dojoAttachPoint") || getAttrFunc(baseNode, "data-dojo-attach-point");
attachPoint = getAttrFunc(baseNode, "data-dojo-attach-point");
if(attachPoint){
var point, points = attachPoint.split(/\s*,\s*/);
while((point = points.shift())){
Expand All @@ -149,7 +147,7 @@ define([
}

// Process data-dojo-attach-event
var attachEvent = getAttrFunc(baseNode, "dojoAttachEvent") || getAttrFunc(baseNode, "data-dojo-attach-event");
var attachEvent = getAttrFunc(baseNode, "data-dojo-attach-event");
if(attachEvent){
// NOTE: we want to support attributes that have the form
// "domEvent: nativeEvent; ..."
Expand Down Expand Up @@ -225,14 +223,5 @@ define([
}
});

// These arguments can be specified for widgets which are used in templates.
// Since any widget can be specified as sub widgets in template, mix it
// into the base widget class. (This is a hack, but it's effective.).
// Remove for 2.0. Also, hide from API doc parser.
lang.extend(_WidgetBase, /*===== {} || =====*/ {
dojoAttachEvent: "",
dojoAttachPoint: ""
});

return _AttachMixin;
});
58 changes: 0 additions & 58 deletions _Templated.js

This file was deleted.

27 changes: 1 addition & 26 deletions _TemplatedMixin.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
define([
"dojo/cache", // dojo.cache
"dojo/_base/declare", // declare
"dojo/dom-construct", // domConstruct.destroy, domConstruct.toDom
"dojo/_base/lang", // lang.getObject
"dojo/on",
"dojo/sniff", // has("ie")
"dojo/string", // string.substitute string.trim
"./_AttachMixin"
], function(cache, declare, domConstruct, lang, on, has, string, _AttachMixin){
], function(declare, domConstruct, lang, string, _AttachMixin){

// module:
// dijit/_TemplatedMixin
Expand All @@ -21,11 +18,6 @@ define([
// Use in conjunction with dojo.cache() to load from a file.
templateString: null,

// templatePath: [protected deprecated] String
// Path to template (HTML file) for this widget relative to dojo.baseUrl.
// Deprecated: use templateString with require([... "dojo/text!..."], ...) instead
templatePath: null,

// skipNodeCache: [protected] Boolean
// If using a cached widget template nodes poses issues for a
// particular widget class, it can set this property to ensure
Expand Down Expand Up @@ -73,10 +65,6 @@ define([
// protected

if(!this._rendered){
if(!this.templateString){
this.templateString = cache(this.templatePath, {sanitize: true});
}

// Lookup cached version of template, and download to cache if it
// isn't there already. Returns either a DomNode or a string, depending on
// whether or not the template contains ${foo} replacement parameters.
Expand Down Expand Up @@ -172,18 +160,5 @@ define([
}
};

if(has("ie")){
on(window, "unload", function(){
var cache = _TemplatedMixin._templateCache;
for(var key in cache){
var value = cache[key];
if(typeof value == "object"){ // value is either a string or a DOM node template
domConstruct.destroy(value);
}
delete cache[key];
}
});
}

return _TemplatedMixin;
});
98 changes: 37 additions & 61 deletions _WidgetsInTemplateMixin.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,84 +13,60 @@ define([
// summary:
// Mixin to supplement _TemplatedMixin when template contains widgets

// _earlyTemplatedStartup: Boolean
// A fallback to preserve the 1.0 - 1.3 behavior of children in
// templates having their startup called before the parent widget
// fires postCreate. Defaults to 'false', causing child widgets to
// have their .startup() called immediately before a parent widget
// .startup(), but always after the parent .postCreate(). Set to
// 'true' to re-enable to previous, arguably broken, behavior.
_earlyTemplatedStartup: false,

// widgetsInTemplate: [protected] Boolean
// Should we parse the template to find widgets that might be
// declared in markup inside it? (Remove for 2.0 and assume true)
widgetsInTemplate: true,

// contextRequire: Function
// Used to provide a context require to the dojo/parser in order to be
// able to use relative MIDs (e.g. `./Widget`) in the widget's template.
contextRequire: null,

_beforeFillContent: function(){
if(this.widgetsInTemplate){
// Before copying over content, instantiate widgets in template
var node = this.domNode;

if(this.containerNode && !this.searchContainerNode){
// Tell parse call below not to look for widgets inside of this.containerNode
this.containerNode.stopParser = true;
}

parser.parse(node, {
noStart: !this._earlyTemplatedStartup,
template: true,
inherited: {dir: this.dir, lang: this.lang, textDir: this.textDir},
propsThis: this, // so data-dojo-props of widgets in the template can reference "this" to refer to me
contextRequire: this.contextRequire,
scope: "dojo" // even in multi-version mode templates use dojoType/data-dojo-type
}).then(lang.hitch(this, function(widgets){
this._startupWidgets = widgets;
// Before copying over content, instantiate widgets in template
var node = this.domNode;

// _WidgetBase::destroy() will destroy any supporting widgets under this.domNode.
// If we wanted to, we could call this.own() on anything in this._startupWidgets that was moved outside
// of this.domNode (like Dialog, which is moved to <body>).

// Hook up attach points and events for nodes that were converted to widgets
for(var i = 0; i < widgets.length; i++){
this._processTemplateNode(widgets[i], function(n,p){
// callback to get a property of a widget
return n[p];
}, function(widget, type, callback){
// callback to do data-dojo-attach-event to a widget
if(type in widget){
// back-compat, remove for 2.0
return widget.connect(widget, type, callback);
}else{
// 1.x may never hit this branch, but it's the default for 2.0
return widget.on(type, callback, true);
}
});
}
if(this.containerNode && !this.searchContainerNode){
// Tell parse call below not to look for widgets inside of this.containerNode
this.containerNode.stopParser = true;
}

// Cleanup flag set above, just in case
if(this.containerNode && this.containerNode.stopParser){
delete this.containerNode.stopParser;
}
}));
parser.parse(node, {
template: true,
inherited: {dir: this.dir, lang: this.lang, textDir: this.textDir},
propsThis: this, // so data-dojo-props of widgets in the template can reference "this" to refer to me
contextRequire: this.contextRequire
}).then(lang.hitch(this, function(widgets){
this._startupWidgets = widgets;

// _WidgetBase::destroy() will destroy any supporting widgets under this.domNode.
// If we wanted to, we could call this.own() on anything in this._startupWidgets that was moved outside
// of this.domNode (like Dialog, which is moved to <body>).

// Hook up attach points and events for nodes that were converted to widgets
for(var i = 0; i < widgets.length; i++){
this._processTemplateNode(widgets[i], function(n,p){
// callback to get a property of a widget
return n[p];
}, function(widget, type, callback){
// callback to do data-dojo-attach-event to a widget
return widget.on(type, callback, true);
});
}

if(!this._startupWidgets){
throw new Error(this.declaredClass + ": parser returned unfilled promise (probably waiting for module auto-load), " +
"unsupported by _WidgetsInTemplateMixin. Must pre-load all supporting widgets before instantiation.");
// Cleanup flag set above, just in case
if(this.containerNode && this.containerNode.stopParser){
delete this.containerNode.stopParser;
}
}));

if(!this._startupWidgets){
throw new Error(this.declaredClass + ": parser returned unfilled promise (probably waiting for module auto-load), " +
"unsupported by _WidgetsInTemplateMixin. Must pre-load all supporting widgets before instantiation.");
}
},

_processTemplateNode: function(/*DOMNode|Widget*/ baseNode, getAttrFunc, attachFunc){
// Override _AttachMixin._processNode to skip DOMNodes with data-dojo-type set. They are handled separately
// in the _beforeFillContent() code above.

if(getAttrFunc(baseNode, "dojoType") || getAttrFunc(baseNode, "data-dojo-type")){
if(baseNode.hasAttribute && baseNode.hasAttribute("data-dojo-type")){
return true;
}

Expand Down
Loading

0 comments on commit b0d578c

Please sign in to comment.