DynamicTooltip.js 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. // wrapped by build app
  2. define("dojox/widget/DynamicTooltip", ["dijit","dojo","dojox","dojo/i18n!dijit/nls/loading","dojo/require!dijit/Tooltip"], function(dijit,dojo,dojox){
  3. dojo.provide("dojox.widget.DynamicTooltip");
  4. dojo.experimental("dojox.widget.DynamicTooltip");
  5. dojo.require("dijit.Tooltip");
  6. dojo.requireLocalization("dijit", "loading");
  7. dojo.declare("dojox.widget.DynamicTooltip", dijit.Tooltip,
  8. {
  9. // summary:
  10. // Extention of dijit.Tooltip providing content set via XHR
  11. // request via href param
  12. // hasLoaded: Boolean
  13. // false if the contents are yet to be loaded from the HTTP request
  14. hasLoaded: false,
  15. // href: String
  16. // location from where to fetch the contents
  17. href: "",
  18. // label: String
  19. // contents to diplay in the tooltip. Initialized to a loading icon.
  20. label: "",
  21. // preventCache: Boolean
  22. // Cache content retreived externally
  23. preventCache: false,
  24. postMixInProperties: function(){
  25. this.inherited(arguments);
  26. this._setLoadingLabel();
  27. },
  28. _setLoadingLabel: function(){
  29. // summary:
  30. // Changes the tooltip label / contents to loading message, only if
  31. // there's an href param, otherwise acts as normal tooltip
  32. if(this.href){
  33. this.label = dojo.i18n.getLocalization("dijit", "loading", this.lang).loadingState;
  34. }
  35. },
  36. // MOW: this is a new widget, do we really need a deprecated stub?
  37. // setHref: function(/*String|Uri*/ href){
  38. // // summary:
  39. // // Deprecated. Use set('href', ...) instead.
  40. // dojo.deprecated("dojox.widget.DynamicTooltip.setHref() is deprecated. Use set('href', ...) instead.", "", "2.0");
  41. // return this.set("href", href);
  42. // },
  43. _setHrefAttr: function(/*String|Uri*/ href){
  44. // summary:
  45. // Hook so attr("href", ...) works.
  46. // description:
  47. // resets so next show loads new href
  48. // href:
  49. // url to the content you want to show, must be within the same domain as your mainpage
  50. this.href = href;
  51. this.hasLoaded = false;
  52. },
  53. loadContent: function(node){
  54. // summary:
  55. // Download contents of href via XHR and display
  56. // description:
  57. // 1. checks if content already loaded
  58. // 2. if not, sends XHR to download new data
  59. if(!this.hasLoaded && this.href){
  60. this._setLoadingLabel();
  61. this.hasLoaded = true;
  62. dojo.xhrGet({
  63. url: this.href,
  64. handleAs: "text",
  65. tooltipWidget: this,
  66. load: function(response, ioArgs){
  67. this.tooltipWidget.label = response;
  68. this.tooltipWidget.close();
  69. this.tooltipWidget.open(node);
  70. },
  71. preventCache: this.preventCache
  72. });
  73. }
  74. },
  75. refresh: function(){
  76. // summary:
  77. // Allows re-download of contents of href and display
  78. // Useful with preventCache = true
  79. this.hasLoaded = false;
  80. },
  81. open: function(/*DomNode*/ target){
  82. // summary:
  83. // Display the tooltip; usually not called directly.
  84. target = target || (this._connectNodes && this._connectNodes[0]);
  85. if(!target){ return; }
  86. this.loadContent(target);
  87. this.inherited(arguments);
  88. }
  89. }
  90. );
  91. });