/public/javascripts/dojo/release/dojo/dojox/layout/ContentPane.js

http://enginey.googlecode.com/
JavaScript | 235 lines | 102 code | 34 blank | 99 comment | 12 complexity | 8f13276e8bf49ff7b7cafe1f242a3e03 MD5 | raw file

✨ Summary
  1. /*
  2. Copyright (c) 2004-2008, 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. (function(){ // private scope, sort of a namespace
  12. /*=====
  13. dojox.layout.ContentPane.DeferredHandle = {
  14. // cancel: Function
  15. cancel: function(){
  16. // summary: cancel a in flight download
  17. },
  18. addOnLoad: function(func){
  19. // summary: add a callback to the onLoad chain
  20. // func: Function
  21. },
  22. addOnUnload: function(func){
  23. // summary: add a callback to the onUnload chain
  24. // func: Function
  25. }
  26. }
  27. =====*/
  28. dojo.declare("dojox.layout.ContentPane", dijit.layout.ContentPane, {
  29. // summary:
  30. // An extended version of dijit.layout.ContentPane
  31. // Supports infile scripts and external ones declared by <script src=''
  32. // relative path adjustments (content fetched from a different folder)
  33. // <style> and <link rel='stylesheet' href='..'> tags,
  34. // css paths inside cssText is adjusted (if you set adjustPaths = true)
  35. //
  36. // NOTE that dojo.require in script in the fetched file isn't recommended
  37. // Many widgets need to be required at page load to work properly
  38. // adjustPaths: Boolean
  39. // Adjust relative paths in html string content to point to this page
  40. // Only usefull if you grab content from a another folder then the current one
  41. adjustPaths: false,
  42. // cleanContent: Boolean
  43. // summary:
  44. // cleans content to make it less likly to generate DOM/JS errors.
  45. // description:
  46. // useful if you send contentpane a complete page, instead of a html fragment
  47. // scans for
  48. //
  49. // * style nodes, inserts in Document head
  50. // * title Node, remove
  51. // * DOCTYPE tag, remove
  52. // * `<!-- *JS code here* -->`
  53. // * `<![CDATA[ *JS code here* ]]>`
  54. cleanContent: false,
  55. // renderStyles: Boolean
  56. // trigger/load styles in the content
  57. renderStyles: false,
  58. // executeScripts: Boolean
  59. // Execute (eval) scripts that is found in the content
  60. executeScripts: true,
  61. // scriptHasHooks: Boolean
  62. // replace keyword '_container_' in scripts with 'dijit.byId(this.id)'
  63. // NOTE this name might change in the near future
  64. scriptHasHooks: false,
  65. /*======
  66. // ioMethod: dojo.xhrGet|dojo.xhrPost
  67. // reference to the method that should grab the content
  68. ioMethod: dojo.xhrGet,
  69. // ioArgs: Object
  70. // makes it possible to add custom args to xhrGet, like ioArgs.headers['X-myHeader'] = 'true'
  71. ioArgs: {},
  72. // onLoadDeferred: dojo.Deferred
  73. // callbackchain will start when onLoad occurs
  74. onLoadDeferred: new dojo.Deferred(),
  75. // onUnloadDeferred: dojo.Deferred
  76. // callbackchain will start when onUnload occurs
  77. onUnloadDeferred: new dojo.Deferred(),
  78. setHref: function(url){
  79. // summary: replace current content with url's content
  80. return ;// dojox.layout.ContentPane.DeferredHandle
  81. },
  82. refresh: function(){
  83. // summary: force a re-download of content
  84. return ;// dojox.layout.ContentPane.DeferredHandle
  85. },
  86. ======*/
  87. constructor: function(){
  88. // init per instance properties, initializer doesn't work here because how things is hooked up in dijit._Widget
  89. this.ioArgs = {};
  90. this.ioMethod = dojo.xhrGet;
  91. this.onLoadDeferred = new dojo.Deferred();
  92. this.onUnloadDeferred = new dojo.Deferred();
  93. },
  94. postCreate: function(){
  95. // override to support loadDeferred
  96. this._setUpDeferreds();
  97. dijit.layout.ContentPane.prototype.postCreate.apply(this, arguments);
  98. },
  99. onExecError: function(e){
  100. // summary
  101. // event callback, called on script error or on java handler error
  102. // overide and return your own html string if you want a some text
  103. // displayed within the ContentPane
  104. },
  105. _setContentAttr: function(data){
  106. var defObj = this._setUpDeferreds();
  107. this.inherited(arguments);
  108. return defObj; // dojox.layout.ContentPane.DeferredHandle
  109. },
  110. cancel: function(){
  111. // summary: cancels a inflight download
  112. if(this._xhrDfd && this._xhrDfd.fired == -1){
  113. // we are still in flight, which means we should reset our DeferredHandle
  114. // otherwise we will trigger onUnLoad chain of the canceled content,
  115. // the canceled content have never gotten onLoad so it shouldn't get onUnload
  116. this.onUnloadDeferred = null;
  117. }
  118. dijit.layout.ContentPane.prototype.cancel.apply(this, arguments);
  119. },
  120. _setUpDeferreds: function(){
  121. var _t = this, cancel = function(){ _t.cancel(); };
  122. var onLoad = (_t.onLoadDeferred = new dojo.Deferred());
  123. var onUnload = (_t._nextUnloadDeferred = new dojo.Deferred());
  124. return {
  125. cancel: cancel,
  126. addOnLoad: function(func){onLoad.addCallback(func);},
  127. addOnUnload: function(func){onUnload.addCallback(func);}
  128. };
  129. },
  130. _onLoadHandler: function(){
  131. dijit.layout.ContentPane.prototype._onLoadHandler.apply(this, arguments);
  132. if(this.onLoadDeferred){
  133. this.onLoadDeferred.callback(true);
  134. }
  135. },
  136. _onUnloadHandler: function(){
  137. this.isLoaded = false;
  138. this.cancel();// need to cancel so we don't get any inflight suprises
  139. if(this.onUnloadDeferred){
  140. this.onUnloadDeferred.callback(true);
  141. }
  142. dijit.layout.ContentPane.prototype._onUnloadHandler.apply(this, arguments);
  143. if(this._nextUnloadDeferred){
  144. this.onUnloadDeferred = this._nextUnloadDeferred;
  145. }
  146. },
  147. _onError: function(type, err){
  148. dijit.layout.ContentPane.prototype._onError.apply(this, arguments);
  149. if(this.onLoadDeferred){
  150. this.onLoadDeferred.errback(err);
  151. }
  152. },
  153. _prepareLoad: function(forceLoad){
  154. // sets up for a xhrLoad, load is deferred until widget is showing
  155. var defObj = this._setUpDeferreds();
  156. dijit.layout.ContentPane.prototype._prepareLoad.apply(this, arguments);
  157. return defObj;
  158. },
  159. _setContent: function(cont){
  160. // override dijit.layout.ContentPane._setContent, to enable path adjustments
  161. var setter = this._contentSetter;
  162. if(! (setter && setter instanceof dojox.html._ContentSetter)) {
  163. setter = this._contentSetter = new dojox.html._ContentSetter({
  164. node: this.containerNode,
  165. _onError: dojo.hitch(this, this._onError),
  166. onContentError: dojo.hitch(this, function(e){
  167. // fires if a domfault occurs when we are appending this.errorMessage
  168. // like for instance if domNode is a UL and we try append a DIV
  169. var errMess = this.onContentError(e);
  170. try{
  171. this.containerNode.innerHTML = errMess;
  172. }catch(e){
  173. console.error('Fatal '+this.id+' could not change content due to '+e.message, e);
  174. }
  175. })/*,
  176. _onError */
  177. });
  178. };
  179. // stash the params for the contentSetter to allow inheritance to work for _setContent
  180. this._contentSetterParams = {
  181. adjustPaths: Boolean(this.adjustPaths && (this.href||this.referencePath)),
  182. referencePath: this.href || this.referencePath,
  183. renderStyles: this.renderStyles,
  184. executeScripts: this.executeScripts,
  185. scriptHasHooks: this.scriptHasHooks,
  186. scriptHookReplacement: "dijit.byId('"+this.id+"')"
  187. };
  188. this.inherited("_setContent", arguments);
  189. }
  190. // could put back _renderStyles by wrapping/aliasing dojox.html._ContentSetter.prototype._renderStyles
  191. });
  192. })();
  193. }