1 | define([ |
---|
2 | "dojo/_base/kernel", |
---|
3 | "dojo/_base/array", |
---|
4 | "dojo/_base/declare", |
---|
5 | "dojo/_base/lang", |
---|
6 | "dojo/_base/window", |
---|
7 | "dijit/_Contained", |
---|
8 | "dijit/_WidgetBase", |
---|
9 | "dojo/_base/xhr", |
---|
10 | "./ProgressIndicator" |
---|
11 | ], function(dojo, array, declare, lang, win, Contained, WidgetBase, xhr, ProgressIndicator){ |
---|
12 | |
---|
13 | /*===== |
---|
14 | var Contained = dijit._Contained; |
---|
15 | var WidgetBase = dijit._WidgetBase; |
---|
16 | =====*/ |
---|
17 | |
---|
18 | // module: |
---|
19 | // dojox/mobile/ContentPane |
---|
20 | // summary: |
---|
21 | // A very simple content pane to embed an HTML fragment. |
---|
22 | |
---|
23 | return declare("dojox.mobile.ContentPane", [WidgetBase, Contained],{ |
---|
24 | // summary: |
---|
25 | // A very simple content pane to embed an HTML fragment. |
---|
26 | // description: |
---|
27 | // This widget embeds an HTML fragment and run the parser. onLoad() |
---|
28 | // is called when parsing is done and the content is ready. |
---|
29 | // "dojo/_base/xhr" is in the dependency list. Usually this is not |
---|
30 | // necessary, but there is a case where dojox.mobile custom build |
---|
31 | // does not contain xhr. Note that this widget does not inherit |
---|
32 | // from dijit._Container. |
---|
33 | |
---|
34 | // href: String |
---|
35 | // URL of the content to embed. |
---|
36 | href: "", |
---|
37 | |
---|
38 | // content: String |
---|
39 | // An html fragment to embed. |
---|
40 | content: "", |
---|
41 | |
---|
42 | // parseOnLoad: Boolean |
---|
43 | // If true, runs the parser when the load completes. |
---|
44 | parseOnLoad: true, |
---|
45 | |
---|
46 | // prog: Boolean |
---|
47 | // If true, shows progress indicator. |
---|
48 | prog: true, |
---|
49 | |
---|
50 | buildRendering: function(){ |
---|
51 | this.inherited(arguments); |
---|
52 | this.domNode.className = "mblContentPane"; |
---|
53 | if(!this.containerNode){ |
---|
54 | this.containerNode = this.domNode; |
---|
55 | } |
---|
56 | }, |
---|
57 | |
---|
58 | startup: function(){ |
---|
59 | if(this._started){ return; } |
---|
60 | if(this.prog){ |
---|
61 | this._p = ProgressIndicator.getInstance(); |
---|
62 | } |
---|
63 | var parent = this.getParent && this.getParent(); |
---|
64 | if(!parent || !parent.resize){ // top level widget |
---|
65 | this.resize(); |
---|
66 | } |
---|
67 | this.inherited(arguments); |
---|
68 | }, |
---|
69 | |
---|
70 | resize: function(){ |
---|
71 | // summary: |
---|
72 | // Calls resize() of each child widget. |
---|
73 | array.forEach(this.getChildren(), function(child){ |
---|
74 | if(child.resize){ child.resize(); } |
---|
75 | }); |
---|
76 | }, |
---|
77 | |
---|
78 | loadHandler: function(/*String*/response){ |
---|
79 | // summary: |
---|
80 | // A handler called when load completes. |
---|
81 | this.set("content", response); |
---|
82 | }, |
---|
83 | |
---|
84 | errorHandler: function(err){ |
---|
85 | // summary: |
---|
86 | // An error handler called when load fails. |
---|
87 | if(this._p){ this._p.stop(); } |
---|
88 | }, |
---|
89 | |
---|
90 | onLoad: function(){ |
---|
91 | // summary: |
---|
92 | // Stub method to allow the application to connect to. |
---|
93 | // Called when parsing is done and the content is ready. |
---|
94 | }, |
---|
95 | |
---|
96 | _setHrefAttr: function(/*String*/href){ |
---|
97 | var p = this._p; |
---|
98 | if(p){ |
---|
99 | win.body().appendChild(p.domNode); |
---|
100 | p.start(); |
---|
101 | } |
---|
102 | this.href = href; |
---|
103 | xhr.get({ |
---|
104 | url: href, |
---|
105 | handleAs: "text", |
---|
106 | load: lang.hitch(this, "loadHandler"), |
---|
107 | error: lang.hitch(this, "errorHandler") |
---|
108 | }); |
---|
109 | }, |
---|
110 | |
---|
111 | _setContentAttr: function(/*String|DomNode*/data){ |
---|
112 | this.destroyDescendants(); |
---|
113 | if(typeof data === "object"){ |
---|
114 | this.domNode.appendChild(data); |
---|
115 | }else{ |
---|
116 | this.domNode.innerHTML = data; |
---|
117 | } |
---|
118 | if(this.parseOnLoad){ |
---|
119 | dojo.parser.parse(this.domNode); |
---|
120 | } |
---|
121 | if(this._p){ this._p.stop(); } |
---|
122 | this.onLoad(); |
---|
123 | } |
---|
124 | }); |
---|
125 | }); |
---|