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