| 1 |
define([ |
| 2 |
"dojo/_base/array", |
| 3 |
"dojo/dom-class", |
| 4 |
"dijit/registry" |
| 5 |
], function(array, domClass, registry){ |
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
var viewRegistry = { |
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
length: 0, |
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
hash: {}, |
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
initialView: null, |
| 25 |
|
| 26 |
add: function( view){ |
| 27 |
|
| 28 |
|
| 29 |
this.hash[view.id] = view; |
| 30 |
this.length++; |
| 31 |
}, |
| 32 |
|
| 33 |
remove: function( id){ |
| 34 |
|
| 35 |
|
| 36 |
if(this.hash[id]){ |
| 37 |
delete this.hash[id]; |
| 38 |
this.length--; |
| 39 |
} |
| 40 |
}, |
| 41 |
|
| 42 |
getViews: function(){ |
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
var arr = []; |
| 47 |
for(var i in this.hash){ |
| 48 |
arr.push(this.hash[i]); |
| 49 |
} |
| 50 |
return arr; |
| 51 |
}, |
| 52 |
|
| 53 |
getParentView: function( view){ |
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
for(var v = view.getParent(); v; v = v.getParent()){ |
| 58 |
if(domClass.contains(v.domNode, "mblView")){ return v; } |
| 59 |
} |
| 60 |
return null; |
| 61 |
}, |
| 62 |
|
| 63 |
getChildViews: function( parent){ |
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
return array.filter(this.getViews(), function(v){ return this.getParentView(v) === parent; }, this); |
| 68 |
}, |
| 69 |
|
| 70 |
getEnclosingView: function( node){ |
| 71 |
|
| 72 |
|
| 73 |
|
| 74 |
for(var n = node; n && n.tagName !== "BODY"; n = n.parentNode){ |
| 75 |
if(n.nodeType === 1 && domClass.contains(n, "mblView")){ |
| 76 |
return registry.byNode(n); |
| 77 |
} |
| 78 |
} |
| 79 |
return null; |
| 80 |
}, |
| 81 |
|
| 82 |
getEnclosingScrollable: function( node){ |
| 83 |
|
| 84 |
|
| 85 |
|
| 86 |
for(var w = registry.getEnclosingWidget(node); w; w = w.getParent()){ |
| 87 |
if(w.scrollableParams && w._v){ return w; } |
| 88 |
} |
| 89 |
return null; |
| 90 |
} |
| 91 |
}; |
| 92 |
|
| 93 |
return viewRegistry; |
| 94 |
}); |