]>
Commit | Line | Data |
---|---|---|
f0cfe83e AD |
1 | define("dijit/Viewport", [ |
2 | "dojo/Evented", | |
3 | "dojo/on", | |
4 | "dojo/ready", | |
5 | "dojo/sniff", | |
6 | "dojo/_base/window", // global | |
7 | "dojo/window" // getBox() | |
8 | ], function(Evented, on, ready, has, win, winUtils){ | |
9 | ||
10 | // module: | |
11 | // dijit/Viewport | |
12 | ||
13 | /*===== | |
14 | return { | |
15 | // summary: | |
16 | // Utility singleton to watch for viewport resizes, avoiding duplicate notifications | |
17 | // which can lead to infinite loops. | |
18 | // description: | |
19 | // Usage: Viewport.on("resize", myCallback). | |
20 | // | |
21 | // myCallback() is called without arguments in case it's _WidgetBase.resize(), | |
22 | // which would interpret the argument as the size to make the widget. | |
23 | }; | |
24 | =====*/ | |
25 | ||
26 | var Viewport = new Evented(); | |
27 | ||
28 | ready(200, function(){ | |
29 | var oldBox = winUtils.getBox(); | |
30 | Viewport._rlh = on(win.global, "resize", function(){ | |
31 | var newBox = winUtils.getBox(); | |
32 | if(oldBox.h == newBox.h && oldBox.w == newBox.w){ return; } | |
33 | oldBox = newBox; | |
34 | Viewport.emit("resize"); | |
35 | }); | |
36 | ||
37 | // Also catch zoom changes on IE8, since they don't naturally generate resize events | |
38 | if(has("ie") == 8){ | |
39 | var deviceXDPI = screen.deviceXDPI; | |
40 | setInterval(function(){ | |
41 | if(screen.deviceXDPI != deviceXDPI){ | |
42 | deviceXDPI = screen.deviceXDPI; | |
43 | Viewport.emit("resize"); | |
44 | } | |
45 | }, 500); | |
46 | } | |
47 | }); | |
48 | ||
49 | return Viewport; | |
50 | }); |