Overlay.js 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. define("dojox/mobile/Overlay", [
  2. "dojo/_base/declare",
  3. "dojo/_base/lang",
  4. "dojo/_base/sniff",
  5. "dojo/_base/window",
  6. "dojo/dom-class",
  7. "dojo/dom-geometry",
  8. "dojo/dom-style",
  9. "dojo/window",
  10. "dijit/_WidgetBase",
  11. "dojo/_base/array",
  12. "dijit/registry"
  13. ], function(declare, lang, has, win, domClass, domGeometry, domStyle, windowUtils, WidgetBase, array, registry){
  14. /*=====
  15. WidgetBase = dijit._WidgetBase;
  16. =====*/
  17. return declare("dojox.mobile.Overlay", WidgetBase, {
  18. // summary:
  19. // A non-templated widget that animates up from the bottom, overlaying the current content
  20. //
  21. baseClass: "mblOverlay mblOverlayHidden",
  22. show: function(/*DomNode?*/aroundNode){
  23. // summary:
  24. // Scroll the overlay up into view
  25. array.forEach(registry.findWidgets(this.domNode), function(w){
  26. if(w && w.height == "auto" && typeof w.resize == "function"){
  27. w.resize();
  28. }
  29. });
  30. var vp, popupPos;
  31. var reposition = lang.hitch(this, function(){
  32. domStyle.set(this.domNode, { position: "", top: "auto", bottom: "0px" });
  33. popupPos = domGeometry.position(this.domNode);
  34. vp = windowUtils.getBox();
  35. if((popupPos.y+popupPos.h) != vp.h // TODO: should be a has() test for position:fixed not scrolling
  36. || has("android") < 3){ // android 2.x supports position:fixed but child transforms don't persist
  37. popupPos.y = vp.t + vp.h - popupPos.h;
  38. domStyle.set(this.domNode, { position: "absolute", top: popupPos.y + "px", bottom: "auto" });
  39. }
  40. });
  41. reposition();
  42. if(aroundNode){
  43. var aroundPos = domGeometry.position(aroundNode);
  44. if(popupPos.y < aroundPos.y){ // if the aroundNode is under the popup, try to scroll it up
  45. win.global.scrollBy(0, aroundPos.y + aroundPos.h - popupPos.y);
  46. reposition();
  47. }
  48. }
  49. domClass.replace(this.domNode, ["mblCoverv", "mblIn"], ["mblOverlayHidden", "mblRevealv", "mblOut", "mblReverse"]);
  50. var _domNode = this.domNode;
  51. setTimeout(function(){
  52. domClass.add(_domNode, "mblTransition");
  53. }, 100);
  54. var timeoutHandler = null;
  55. this._moveHandle = this.connect(win.doc.documentElement, "ontouchmove", function(){
  56. if(timeoutHandler){
  57. clearTimeout(timeoutHandler);
  58. }
  59. timeoutHandler = setTimeout(function(){
  60. reposition();
  61. timeoutHandler = null;
  62. }, 0);
  63. });
  64. },
  65. hide: function(){
  66. // summary:
  67. // Scroll the overlay down and then make it invisible
  68. if(this._moveHandle){
  69. this.disconnect(this._moveHandle);
  70. this._moveHandle = null;
  71. }
  72. if(has("webkit")){
  73. var handler = this.connect(this.domNode, "webkitTransitionEnd", function(){
  74. this.disconnect(handler);
  75. domClass.replace(this.domNode, ["mblOverlayHidden"], ["mblRevealv", "mblOut", "mblReverse", "mblTransition"]);
  76. });
  77. domClass.replace(this.domNode, ["mblRevealv", "mblOut", "mblReverse"], ["mblCoverv", "mblIn", "mblTransition"]);
  78. var _domNode = this.domNode;
  79. setTimeout(function(){
  80. domClass.add(_domNode, "mblTransition");
  81. }, 100);
  82. }else{
  83. domClass.replace(this.domNode, ["mblOverlayHidden"], ["mblCoverv", "mblIn", "mblRevealv", "mblOut", "mblReverse"]);
  84. }
  85. },
  86. onBlur: function(/*Event*/e){
  87. return false; // touching outside the overlay area does not call hide()
  88. }
  89. });
  90. });