-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathresolve.js
36 lines (33 loc) · 1.21 KB
/
resolve.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
define([
"dojo/_base/lang",
"dijit/registry",
"dojo/Stateful"
], function(lang, registry){
var resolve = function(/*dojo/Stateful|String*/ target, /*dojo/Stateful?*/ parent){
// summary:
// Find a dojo/Stateful for the target.
// description:
// If target is not a string, return target itself.
// If target is "widget:widgetid", returns the widget whose ID is widgetid.
// If target is "rel:object.path", or target is other string, returns an object under parent (if specified) or under global scope.
// target: dojo/Stateful|String
// The data binding to resolve.
// parent: dojo/Stateful?
// The parent data binding. Used when the data binding is defined inside repeat.
if(typeof target == "string"){
var tokens = target.match(/^(expr|rel|widget):(.*)$/) || [];
try{
if(tokens[1] == "rel"){
target = lang.getObject(tokens[2] || "", false, parent);
}else if(tokens[1] == "widget"){
target = registry.byId(tokens[2]);
}else{
target = lang.getObject(tokens[2] || target, false, parent);
}
}catch(e){}
}
return target; // dojo/Stateful
};
// lang.setObject() thing is for back-compat, remove it in 2.0
return lang.setObject("dojox.mvc.resolve", resolve);
});