Debian Codegraph @

dojox/mobile/_ContentPaneMixin.js

raw symbols SCIP
1 define([
2 "dojo/_base/declare",
3 "dojo/_base/Deferred",
4 "dojo/_base/lang",
5 "dojo/_base/window",
6 "dojo/_base/xhr",
7 "./_ExecScriptMixin",
8 "./ProgressIndicator",
9 "./lazyLoadUtils"
10 ], function(declare, Deferred, lang, win, xhr, ExecScriptMixin, ProgressIndicator, lazyLoadUtils){
11
12 // module:
13 // dojox/mobile/_ContentPaneMixin
14
15 return declare("dojox.mobile._ContentPaneMixin", ExecScriptMixin, {
16 // summary:
17 // Mixin for a very simple content pane to embed an HTML fragment.
18 // description:
19 // By mixing this class into a widget, the widget can have the ability
20 // to embed an external HTML fragment and to run the parser.
21
22 // href: String
23 // URL of the content to embed.
24 href: "",
25
26 // lazy: String
27 // If true, external content specified with the href property is
28 // not loaded at startup time. It can be loaded by calling load().
29 lazy: false,
30
31 // content: String
32 // An HTML fragment to embed.
33 content: "",
34
35 // parseOnLoad: Boolean
36 // If true, runs the parser when the load completes.
37 parseOnLoad: true,
38
39 // prog: Boolean
40 // If true, shows progress indicator while loading an HTML fragment
41 // specified by href.
42 prog: true,
43
44 // executeScripts: Boolean
45 // If true, executes scripts that is found in the content.
46 executeScripts: true,
47
48 constructor: function(){
49 // summary:
50 // Creates a new instance of the class.
51 // tags:
52 // private
53 if(this.prog){
54 this._p = ProgressIndicator.getInstance();
55 }
56 },
57
58 loadHandler: function(/*String*/response){
59 // summary:
60 // A handler called when load completes.
61 this.set("content", response);
62 },
63
64 errorHandler: function(err){
65 // summary:
66 // An error handler called when load fails.
67 if(this._p){ this._p.stop(); }
68 },
69
70 load: function(){
71 // summary:
72 // Loads external content specified with href.
73 this.lazy = false;
74 this.set("href", this.href);
75 },
76
77 onLoad: function(){
78 // summary:
79 // Stub method to allow the application to connect to the
80 // loading of external content (see load()).
81 // Called when parsing is done and the content is ready.
82 return true;
83 },
84
85 _setHrefAttr: function(/*String*/href){
86 // tags:
87 // private
88 if(this.lazy || !href || href === this._loaded){
89 this.lazy = false;
90 return null;
91 }
92 var p = this._p;
93 if(p){
94 win.body().appendChild(p.domNode);
95 p.start();
96 }
97 this._set("href", href);
98 this._loaded = href;
99 return xhr.get({
100 url: href,
101 handleAs: "text",
102 load: lang.hitch(this, "loadHandler"),
103 error: lang.hitch(this, "errorHandler")
104 });
105 },
106
107 _setContentAttr: function(/*String|DomNode*/data){
108 // tags:
109 // private
110 this.destroyDescendants();
111 if(typeof data === "object"){
112 this.containerNode.appendChild(data);
113 }else{
114 if(this.executeScripts){
115 data = this.execScript(data);
116 }
117 this.containerNode.innerHTML = data;
118 }
119 if(this.parseOnLoad){
120 var _this = this;
121 return Deferred.when(lazyLoadUtils.instantiateLazyWidgets(_this.containerNode), function(){
122 if(_this._p){ _this._p.stop(); }
123 return _this.onLoad();
124 });
125 }
126 if(this._p){ this._p.stop(); }
127 return this.onLoad();
128 }
129 });
130 });