IFrame.js 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. /**
  2. * Barebones iframe implementation.
  3. */
  4. Ext.define('Ext.ux.IFrame', {
  5. extend: 'Ext.Component',
  6. alias: 'widget.uxiframe',
  7. loadMask: 'Loading...',
  8. src: 'about:blank',
  9. renderTpl: [
  10. '<iframe src="{src}" id="{id}-iframeEl" data-ref="iframeEl" name="{frameName}" width="100%" height="100%" frameborder="0"></iframe>'
  11. ],
  12. childEls: ['iframeEl'],
  13. initComponent: function () {
  14. this.callParent();
  15. this.frameName = this.frameName || this.id + '-frame';
  16. },
  17. initEvents : function() {
  18. var me = this;
  19. me.callParent();
  20. me.iframeEl.on('load', me.onLoad, me);
  21. },
  22. initRenderData: function() {
  23. return Ext.apply(this.callParent(), {
  24. src: this.src,
  25. frameName: this.frameName
  26. });
  27. },
  28. getBody: function() {
  29. var doc = this.getDoc();
  30. return doc.body || doc.documentElement;
  31. },
  32. getDoc: function() {
  33. try {
  34. return this.getWin().document;
  35. } catch (ex) {
  36. return null;
  37. }
  38. },
  39. getWin: function() {
  40. var me = this,
  41. name = me.frameName,
  42. win = Ext.isIE ? me.iframeEl.dom.contentWindow : window.frames[name];
  43. return win;
  44. },
  45. getFrame: function() {
  46. var me = this;
  47. return me.iframeEl.dom;
  48. },
  49. onLoad: function() {
  50. var me = this,
  51. doc = me.getDoc();
  52. if (doc) {
  53. this.el.unmask();
  54. this.fireEvent('load', this);
  55. } else if (me.src) {
  56. this.el.unmask();
  57. this.fireEvent('error', this);
  58. }
  59. },
  60. load: function (src) {
  61. var me = this,
  62. text = me.loadMask,
  63. frame = me.getFrame();
  64. if (me.fireEvent('beforeload', me, src) !== false) {
  65. if (text && me.el) {
  66. me.el.mask(text);
  67. }
  68. frame.src = me.src = (src || me.src);
  69. }
  70. }
  71. });
  72. /*
  73. * Note: Event relayers are not needed here because the combination of the gesture system and
  74. * normal focus/blur will handle it.
  75. * Tested with the examples/classic/desktop app.
  76. */
  77. /*
  78. * TODO items:
  79. *
  80. * Iframe should clean up any Ext.dom.Element wrappers around its window, document
  81. * documentElement and body when it is destroyed. This helps prevent "Permission Denied"
  82. * errors in IE when Ext.dom.GarbageCollector tries to access those objects on an orphaned
  83. * iframe. Permission Denied errors can occur in one of the following 2 scenarios:
  84. *
  85. * a. When an iframe is removed from the document, and all references to it have been
  86. * removed, IE will "clear" the window object. At this point the window object becomes
  87. * completely inaccessible - accessing any of its properties results in a "Permission
  88. * Denied" error. http://msdn.microsoft.com/en-us/library/ie/hh180174(v=vs.85).aspx
  89. *
  90. * b. When an iframe is unloaded (either by navigating to a new url, or via document.open/
  91. * document.write, new html and body elements are created and the old the html and body
  92. * elements are orphaned. Accessing the html and body elements or any of their properties
  93. * results in a "Permission Denied" error.
  94. */