1 | define([ |
---|
2 | "dojo/_base/lang", |
---|
3 | "dojo/_base/xhr", |
---|
4 | "dijit/layout/ContentPane", |
---|
5 | "dojox/html/_base", |
---|
6 | "dojo/_base/declare" |
---|
7 | ], function (lang, xhrUtil, ContentPane, htmlUtil, declare) { |
---|
8 | |
---|
9 | return declare("dojox.layout.ContentPane", ContentPane, { |
---|
10 | // summary: |
---|
11 | // An extended version of dijit.layout.ContentPane. |
---|
12 | // Supports infile scripts and external ones declared by `<script src=''...>` |
---|
13 | // relative path adjustments (content fetched from a different folder) |
---|
14 | // `<style>` and `<link rel='stylesheet' href='..'>` tags, |
---|
15 | // css paths inside cssText is adjusted (if you set adjustPaths = true) |
---|
16 | // |
---|
17 | // NOTE that dojo.require in script in the fetched file isn't recommended |
---|
18 | // Many widgets need to be required at page load to work properly |
---|
19 | |
---|
20 | // adjustPaths: Boolean |
---|
21 | // Adjust relative paths in html string content to point to this page. |
---|
22 | // Only useful if you grab content from a another folder then the current one |
---|
23 | adjustPaths: false, |
---|
24 | |
---|
25 | // cleanContent: Boolean |
---|
26 | // Cleans content to make it less likely to generate DOM/JS errors. |
---|
27 | // Useful if you send ContentPane a complete page, instead of a html fragment |
---|
28 | // scans for: |
---|
29 | // |
---|
30 | // - title Node, remove |
---|
31 | // - DOCTYPE tag, remove |
---|
32 | cleanContent: false, |
---|
33 | |
---|
34 | // renderStyles: Boolean |
---|
35 | // trigger/load styles in the content |
---|
36 | renderStyles: false, |
---|
37 | |
---|
38 | // executeScripts: Boolean |
---|
39 | // Execute (eval) scripts that is found in the content |
---|
40 | executeScripts: true, |
---|
41 | |
---|
42 | // scriptHasHooks: Boolean |
---|
43 | // replace keyword '_container_' in scripts with 'dijit.byId(this.id)' |
---|
44 | // NOTE this name might change in the near future |
---|
45 | scriptHasHooks: false, |
---|
46 | |
---|
47 | ioMethod: xhrUtil.get, |
---|
48 | |
---|
49 | ioArgs: {}, |
---|
50 | |
---|
51 | onExecError: function(/*Event*/ e){ |
---|
52 | // summary: |
---|
53 | // event callback, called on script error or on java handler error |
---|
54 | // override and return your own html string if you want a some text |
---|
55 | // displayed within the ContentPane |
---|
56 | }, |
---|
57 | |
---|
58 | _setContent: function(cont){ |
---|
59 | // override dijit.layout.ContentPane._setContent, to enable path adjustments |
---|
60 | |
---|
61 | var setter = this._contentSetter; |
---|
62 | if(! (setter && setter instanceof htmlUtil._ContentSetter)) { |
---|
63 | setter = this._contentSetter = new htmlUtil._ContentSetter({ |
---|
64 | node: this.containerNode, |
---|
65 | _onError: lang.hitch(this, this._onError), |
---|
66 | onContentError: lang.hitch(this, function(e){ |
---|
67 | // fires if a domfault occurs when we are appending this.errorMessage |
---|
68 | // like for instance if domNode is a UL and we try append a DIV |
---|
69 | var errMess = this.onContentError(e); |
---|
70 | try{ |
---|
71 | this.containerNode.innerHTML = errMess; |
---|
72 | }catch(e){ |
---|
73 | console.error('Fatal '+this.id+' could not change content due to '+e.message, e); |
---|
74 | } |
---|
75 | })/*, |
---|
76 | _onError */ |
---|
77 | }); |
---|
78 | }; |
---|
79 | |
---|
80 | // stash the params for the contentSetter to allow inheritance to work for _setContent |
---|
81 | this._contentSetterParams = { |
---|
82 | adjustPaths: Boolean(this.adjustPaths && (this.href||this.referencePath)), |
---|
83 | referencePath: this.href || this.referencePath, |
---|
84 | renderStyles: this.renderStyles, |
---|
85 | executeScripts: this.executeScripts, |
---|
86 | scriptHasHooks: this.scriptHasHooks, |
---|
87 | scriptHookReplacement: "dijit.byId('"+this.id+"')" |
---|
88 | }; |
---|
89 | |
---|
90 | this.inherited("_setContent", arguments); |
---|
91 | } |
---|
92 | // could put back _renderStyles by wrapping/aliasing dojox.html._ContentSetter.prototype._renderStyles |
---|
93 | }); |
---|
94 | }); |
---|