DynamicTooltip.js 3.3 KB

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