[483] | 1 | define([ |
---|
| 2 | "dojo/_base/array", |
---|
| 3 | "dojo/dom-class", |
---|
| 4 | "dijit/registry" |
---|
| 5 | ], function(array, domClass, registry){ |
---|
| 6 | |
---|
| 7 | // module: |
---|
| 8 | // dojox/mobile/viewRegistry |
---|
| 9 | |
---|
| 10 | var viewRegistry = { |
---|
| 11 | // summary: |
---|
| 12 | // A registry of existing views. |
---|
| 13 | |
---|
| 14 | // length: Number |
---|
| 15 | // The number of registered views. |
---|
| 16 | length: 0, |
---|
| 17 | |
---|
| 18 | // hash: [private] Object |
---|
| 19 | // The object used to register views. |
---|
| 20 | hash: {}, |
---|
| 21 | |
---|
| 22 | // initialView: [private] dojox/mobile/View |
---|
| 23 | // The initial view. |
---|
| 24 | initialView: null, |
---|
| 25 | |
---|
| 26 | add: function(/*dojox/mobile/View*/ view){ |
---|
| 27 | // summary: |
---|
| 28 | // Adds a view to the registry. |
---|
| 29 | this.hash[view.id] = view; |
---|
| 30 | this.length++; |
---|
| 31 | }, |
---|
| 32 | |
---|
| 33 | remove: function(/*String*/ id){ |
---|
| 34 | // summary: |
---|
| 35 | // Removes a view from the registry. |
---|
| 36 | if(this.hash[id]){ |
---|
| 37 | delete this.hash[id]; |
---|
| 38 | this.length--; |
---|
| 39 | } |
---|
| 40 | }, |
---|
| 41 | |
---|
| 42 | getViews: function(){ |
---|
| 43 | // summary: |
---|
| 44 | // Gets all registered views. |
---|
| 45 | // returns: Array |
---|
| 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(/*dojox/mobile/View*/ view){ |
---|
| 54 | // summary: |
---|
| 55 | // Gets the parent view of the specified view. |
---|
| 56 | // returns: dojox/mobile/View |
---|
| 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(/*dojox/mobile/View*/ parent){ |
---|
| 64 | // summary: |
---|
| 65 | // Gets the children views of the specified view. |
---|
| 66 | // returns: Array |
---|
| 67 | return array.filter(this.getViews(), function(v){ return this.getParentView(v) === parent; }, this); |
---|
| 68 | }, |
---|
| 69 | |
---|
| 70 | getEnclosingView: function(/*DomNode*/ node){ |
---|
| 71 | // summary: |
---|
| 72 | // Gets the view containing the specified DOM node. |
---|
| 73 | // returns: dojox/mobile/View |
---|
| 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(/*DomNode*/ node){ |
---|
| 83 | // summary: |
---|
| 84 | // Gets the dojox/mobile/scrollable object containing the specified DOM node. |
---|
| 85 | // returns: dojox/mobile/scrollable |
---|
| 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 | }); |
---|