Viewport.js.uncompressed.js 1.2 KB

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