BackgroundIframe.js 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. define("dijit/BackgroundIframe", [
  2. "require", // require.toUrl
  3. ".", // to export dijit.BackgroundIframe
  4. "dojo/_base/config",
  5. "dojo/dom-construct", // domConstruct.create
  6. "dojo/dom-style", // domStyle.set
  7. "dojo/_base/lang", // lang.extend lang.hitch
  8. "dojo/on",
  9. "dojo/_base/sniff", // has("ie"), has("mozilla"), has("quirks")
  10. "dojo/_base/window" // win.doc.createElement
  11. ], function(require, dijit, config, domConstruct, domStyle, lang, on, has, win){
  12. // module:
  13. // dijit/BackgroundIFrame
  14. // Flag for whether to create background iframe behind popups like Menus and Dialog.
  15. // A background iframe is useful to prevent problems with popups appearing behind applets/pdf files,
  16. // and is also useful on older versions of IE (IE6 and IE7) to prevent the "bleed through select" problem.
  17. // TODO: For 2.0, make this false by default. Also, possibly move definition to has.js so that this module can be
  18. // conditionally required via dojo/has!bgIfame?dijit/BackgroundIframe
  19. has.add("bgIframe", has("ie") || has("mozilla"));
  20. // summary:
  21. // new dijit.BackgroundIframe(node)
  22. // Makes a background iframe as a child of node, that fills
  23. // area (and position) of node
  24. // TODO: remove _frames, it isn't being used much, since popups never release their
  25. // iframes (see [22236])
  26. var _frames = new function(){
  27. // summary:
  28. // cache of iframes
  29. var queue = [];
  30. this.pop = function(){
  31. var iframe;
  32. if(queue.length){
  33. iframe = queue.pop();
  34. iframe.style.display="";
  35. }else{
  36. if(has("ie") < 9){
  37. var burl = config["dojoBlankHtmlUrl"] || require.toUrl("dojo/resources/blank.html") || "javascript:\"\"";
  38. var html="<iframe src='" + burl + "' role='presentation'"
  39. + " style='position: absolute; left: 0px; top: 0px;"
  40. + "z-index: -1; filter:Alpha(Opacity=\"0\");'>";
  41. iframe = win.doc.createElement(html);
  42. }else{
  43. iframe = domConstruct.create("iframe");
  44. iframe.src = 'javascript:""';
  45. iframe.className = "dijitBackgroundIframe";
  46. iframe.setAttribute("role", "presentation");
  47. domStyle.set(iframe, "opacity", 0.1);
  48. }
  49. iframe.tabIndex = -1; // Magic to prevent iframe from getting focus on tab keypress - as style didn't work.
  50. }
  51. return iframe;
  52. };
  53. this.push = function(iframe){
  54. iframe.style.display="none";
  55. queue.push(iframe);
  56. }
  57. }();
  58. dijit.BackgroundIframe = function(/*DomNode*/ node){
  59. // summary:
  60. // For IE/FF z-index schenanigans. id attribute is required.
  61. //
  62. // description:
  63. // new dijit.BackgroundIframe(node)
  64. // Makes a background iframe as a child of node, that fills
  65. // area (and position) of node
  66. if(!node.id){ throw new Error("no id"); }
  67. if(has("bgIframe")){
  68. var iframe = (this.iframe = _frames.pop());
  69. node.appendChild(iframe);
  70. if(has("ie")<7 || has("quirks")){
  71. this.resize(node);
  72. this._conn = on(node, 'resize', lang.hitch(this, function(){
  73. this.resize(node);
  74. }));
  75. }else{
  76. domStyle.set(iframe, {
  77. width: '100%',
  78. height: '100%'
  79. });
  80. }
  81. }
  82. };
  83. lang.extend(dijit.BackgroundIframe, {
  84. resize: function(node){
  85. // summary:
  86. // Resize the iframe so it's the same size as node.
  87. // Needed on IE6 and IE/quirks because height:100% doesn't work right.
  88. if(this.iframe){
  89. domStyle.set(this.iframe, {
  90. width: node.offsetWidth + 'px',
  91. height: node.offsetHeight + 'px'
  92. });
  93. }
  94. },
  95. destroy: function(){
  96. // summary:
  97. // destroy the iframe
  98. if(this._conn){
  99. this._conn.remove();
  100. this._conn = null;
  101. }
  102. if(this.iframe){
  103. _frames.push(this.iframe);
  104. delete this.iframe;
  105. }
  106. }
  107. });
  108. return dijit.BackgroundIframe;
  109. });