123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208 |
- goog.provide('goog.net.IframeLoadMonitor');
- goog.require('goog.dom');
- goog.require('goog.events');
- goog.require('goog.events.EventTarget');
- goog.require('goog.events.EventType');
- goog.require('goog.userAgent');
- goog.net.IframeLoadMonitor = function(iframe, opt_hasContent) {
- goog.net.IframeLoadMonitor.base(this, 'constructor');
-
- this.iframe_ = iframe;
-
- this.hasContent_ = !!opt_hasContent;
-
- this.isLoaded_ = this.isLoadedHelper_();
- if (!this.isLoaded_) {
-
-
-
-
- var isIe6OrLess =
- goog.userAgent.IE && !goog.userAgent.isVersionOrHigher('7');
- var loadEvtType = isIe6OrLess ? goog.events.EventType.READYSTATECHANGE :
- goog.events.EventType.LOAD;
- this.onloadListenerKey_ = goog.events.listen(
- this.iframe_, loadEvtType, this.handleLoad_, false, this);
-
-
- this.intervalId_ = window.setInterval(
- goog.bind(this.handleLoad_, this),
- goog.net.IframeLoadMonitor.POLL_INTERVAL_MS_);
- }
- };
- goog.inherits(goog.net.IframeLoadMonitor, goog.events.EventTarget);
- goog.net.IframeLoadMonitor.LOAD_EVENT = 'ifload';
- goog.net.IframeLoadMonitor.POLL_INTERVAL_MS_ = 100;
- goog.net.IframeLoadMonitor.prototype.onloadListenerKey_ = null;
- goog.net.IframeLoadMonitor.prototype.isLoaded = function() {
- return this.isLoaded_;
- };
- goog.net.IframeLoadMonitor.prototype.maybeStopTimer_ = function() {
- if (this.intervalId_) {
- window.clearInterval(this.intervalId_);
- this.intervalId_ = null;
- }
- };
- goog.net.IframeLoadMonitor.prototype.getIframe = function() {
- return this.iframe_;
- };
- goog.net.IframeLoadMonitor.prototype.disposeInternal = function() {
- delete this.iframe_;
- this.maybeStopTimer_();
- goog.events.unlistenByKey(this.onloadListenerKey_);
- goog.net.IframeLoadMonitor.superClass_.disposeInternal.call(this);
- };
- goog.net.IframeLoadMonitor.prototype.isLoadedHelper_ = function() {
- var isLoaded = false;
- try {
- if (!this.hasContent_ && goog.userAgent.IE &&
- !goog.userAgent.isVersionOrHigher('11')) {
-
-
- isLoaded = this.iframe_.readyState == 'complete';
- } else {
-
-
-
-
-
-
- var body = goog.dom.getFrameContentDocument(this.iframe_).body;
- isLoaded = this.hasContent_ ? !!body && !!body.firstChild : !!body;
- }
- } catch (e) {
-
-
-
-
-
- }
- return isLoaded;
- };
- goog.net.IframeLoadMonitor.prototype.handleLoad_ = function() {
-
- if (this.isLoadedHelper_()) {
- this.maybeStopTimer_();
- goog.events.unlistenByKey(this.onloadListenerKey_);
- this.onloadListenerKey_ = null;
- this.isLoaded_ = true;
- this.dispatchEvent(goog.net.IframeLoadMonitor.LOAD_EVENT);
- }
- };
|