Opener.js 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. define("dojox/mobile/Opener", [
  2. "dojo/_base/declare",
  3. "dojo/_base/lang",
  4. "dojo/_base/window",
  5. "dojo/dom-class",
  6. "dojo/dom-construct",
  7. "dojo/dom-style",
  8. "dojo/dom-geometry",
  9. "./Tooltip",
  10. "./Overlay"
  11. ], function(declare, lang, win, domClass, domConstruct, domStyle, domGeometry, Tooltip, Overlay){
  12. /*=====
  13. Tooltip = dojox.mobile.Tooltip;
  14. Overlay = dojox.mobile.Overlay;
  15. =====*/
  16. var isOverlay = domClass.contains(win.doc.documentElement, "dj_phone");
  17. var cls = declare("dojox.mobile.Opener", isOverlay ? Overlay : Tooltip, {
  18. // summary:
  19. // A non-templated popup widget that will use either Tooltip or Overlay depending on screen size
  20. //
  21. buildRendering: function(){
  22. this.inherited(arguments);
  23. this.cover = domConstruct.create('div', { onclick: lang.hitch(this, '_onBlur'), 'class': 'mblOpenerUnderlay', style: { top:'0px', left:'0px', width:'0px', height:'0px', position: isOverlay ? 'absolute' : 'fixed', backgroundColor:'transparent', overflow:'hidden', zIndex:'-1' }}, this.domNode, 'first');
  24. this.connect(null, win.global.onorientationchange !== undefined ? "onorientationchange" : "onresize", lang.hitch(this, function(){
  25. if(domStyle.get(this.cover, "height") !== '0px'){ // resize cover when shown
  26. this._resizeCover();
  27. }
  28. }));
  29. },
  30. onShow: function(/*DomNode*/node){},
  31. onHide: function(/*DomNode*/node, /*Anything*/v){},
  32. show: function(node, positions){
  33. this.node = node;
  34. this.onShow(node);
  35. this._resizeCover();
  36. return this.inherited(arguments);
  37. },
  38. hide: function(/*Anything*/ val){
  39. this.inherited(arguments);
  40. domStyle.set(this.cover, { height:'0px' });
  41. this.onHide(this.node, val);
  42. },
  43. _resizeCover: function(){
  44. if(isOverlay){
  45. domStyle.set(this.cover, { height:'0px' }); // hide cover temporarily to calculate domNode size
  46. setTimeout(lang.hitch(this, function(){ // show cover after positioning popup
  47. var pos = domGeometry.position(this.domNode, false);
  48. domStyle.set(this.cover, { top:-pos.y+'px', left:-pos.x+'px', width:(pos.w+pos.x)+'px', height:(pos.h+pos.y)+'px' });
  49. }), 0);
  50. }else{
  51. domStyle.set(this.cover, {
  52. width:Math.max(win.doc.documentElement.scrollWidth || win.body().scrollWidth || win.doc.documentElement.clientWidth)+'px',
  53. height:Math.max(win.doc.documentElement.scrollHeight || win.body().scrollHeight || win.doc.documentElement.clientHeight)+'px'
  54. });
  55. }
  56. },
  57. _onBlur: function(e){
  58. var ret = this.onBlur(e);
  59. if(ret !== false){ // only exactly false prevents hide()
  60. this.hide(e);
  61. }
  62. return ret;
  63. }
  64. });
  65. cls.prototype.baseClass += " mblOpener"; // add to either mblOverlay or mblTooltip
  66. return cls;
  67. });