ContentPane.js 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. define("dojox/layout/ContentPane", [
  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. /*===== var ContentPane = dijit.layout.ContentPane =====*/
  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. // adjustPaths: Boolean
  20. // Adjust relative paths in html string content to point to this page.
  21. // Only useful if you grab content from a another folder then the current one
  22. adjustPaths: false,
  23. // cleanContent: Boolean
  24. // summary:
  25. // cleans content to make it less likely to generate DOM/JS errors.
  26. // description:
  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. // renderStyles: Boolean
  34. // trigger/load styles in the content
  35. renderStyles: false,
  36. // executeScripts: Boolean
  37. // Execute (eval) scripts that is found in the content
  38. executeScripts: true,
  39. // scriptHasHooks: Boolean
  40. // replace keyword '_container_' in scripts with 'dijit.byId(this.id)'
  41. // NOTE this name might change in the near future
  42. scriptHasHooks: false,
  43. constructor: function(){
  44. // init per instance properties, initializer doesn't work here because how things is hooked up in dijit._Widget
  45. this.ioArgs = {};
  46. this.ioMethod = xhrUtil.get;
  47. },
  48. onExecError: function(e){
  49. // summary:
  50. // event callback, called on script error or on java handler error
  51. // overide and return your own html string if you want a some text
  52. // displayed within the ContentPane
  53. },
  54. _setContent: function(cont){
  55. // override dijit.layout.ContentPane._setContent, to enable path adjustments
  56. var setter = this._contentSetter;
  57. if(! (setter && setter instanceof htmlUtil._ContentSetter)) {
  58. setter = this._contentSetter = new htmlUtil._ContentSetter({
  59. node: this.containerNode,
  60. _onError: lang.hitch(this, this._onError),
  61. onContentError: lang.hitch(this, function(e){
  62. // fires if a domfault occurs when we are appending this.errorMessage
  63. // like for instance if domNode is a UL and we try append a DIV
  64. var errMess = this.onContentError(e);
  65. try{
  66. this.containerNode.innerHTML = errMess;
  67. }catch(e){
  68. console.error('Fatal '+this.id+' could not change content due to '+e.message, e);
  69. }
  70. })/*,
  71. _onError */
  72. });
  73. };
  74. // stash the params for the contentSetter to allow inheritance to work for _setContent
  75. this._contentSetterParams = {
  76. adjustPaths: Boolean(this.adjustPaths && (this.href||this.referencePath)),
  77. referencePath: this.href || this.referencePath,
  78. renderStyles: this.renderStyles,
  79. executeScripts: this.executeScripts,
  80. scriptHasHooks: this.scriptHasHooks,
  81. scriptHookReplacement: "dijit.byId('"+this.id+"')"
  82. };
  83. this.inherited("_setContent", arguments);
  84. },
  85. // could put back _renderStyles by wrapping/aliasing dojox.html._ContentSetter.prototype._renderStyles
  86. destroy: function () {
  87. var setter = this._contentSetter;
  88. if (setter) {
  89. setter.tearDown();
  90. }
  91. this.inherited(arguments);
  92. }
  93. });
  94. });