ContentPane.js 3.9 KB

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