Jelajahi Sumber

iframe 组件

luoyifan 3 tahun lalu
induk
melakukan
bc505db3bf
2 mengubah file dengan 89 tambahan dan 0 penghapusan
  1. 87 0
      src/controls/iframe.js
  2. 2 0
      src/init.ts

+ 87 - 0
src/controls/iframe.js

@@ -0,0 +1,87 @@
+export default function () {
+    Ext.define('Ext.ux.IFrame', {
+        extend: 'Ext.Component',
+        alias: 'widget.uxiframe',
+        loadMask: 'Loading...',
+        src: 'about:blank',
+        renderTpl: [
+            '<iframe src="{src}" id="{id}-iframeEl" data-ref="iframeEl" name="{frameName}" width="100%" height="100%" frameborder="0"></iframe>'
+        ],
+        childEls: ['iframeEl'],
+
+        initComponent: function () {
+            this.superclass.initComponent.call(this)
+            this.superclass.initEvents.call(this)
+            this.frameName = this.frameName || this.id + '-frame';
+        },
+
+        initEvents: function () {
+            var me = this;
+            this.superclass.initEvents.call(this)
+            me.iframeEl.on('load', me.onLoad, me);
+        },
+
+        initRenderData: function () {
+            return Ext.apply(this.superclass.initRenderData.call(this), {
+                src: this.src,
+                frameName: this.frameName
+            });
+        },
+
+        getBody: function () {
+            var doc = this.getDoc();
+            return doc.body || doc.documentElement;
+        },
+
+        getDoc: function () {
+            try {
+                return this.getWin().document;
+            } catch (ex) {
+                return null;
+            }
+        },
+
+        getWin: function () {
+            var me = this,
+                name = me.frameName,
+                win = Ext.isIE ? me.iframeEl.dom.contentWindow : window.frames[name];
+            return win;
+        },
+
+        getFrame: function () {
+            var me = this;
+            return me.iframeEl.dom;
+        },
+
+        onLoad: function () {
+            var me = this,
+                doc = me.getDoc();
+
+            if (doc) {
+                this.el.unmask();
+                this.fireEvent('load', this);
+
+            } else if (me.src) {
+
+                this.el.unmask();
+                this.fireEvent('error', this);
+            }
+
+
+        },
+
+        load: function (src) {
+            var me = this,
+                text = me.loadMask,
+                frame = me.getFrame();
+
+            if (me.fireEvent('beforeload', me, src) !== false) {
+                if (text && me.el) {
+                    me.el.mask(text);
+                }
+
+                frame.src = me.src = (src || me.src);
+            }
+        }
+    });
+}

+ 2 - 0
src/init.ts

@@ -27,6 +27,7 @@ import initRows from './controls/rows'
 import initForm from './controls/form'
 import initCols from './controls/cols'
 import initButton from './controls/button'
+import initIframe from './controls/iframe'
 import initStores from './controls/stores'
 import {lookupFn, lookupScope} from "./lib/lib"
 import * as SystemLib from './lib/systemLib'
@@ -189,4 +190,5 @@ export function init() {
     initPickerPlus()
     initCombogrid()
     initComboGridMulti()
+    initIframe()
 }