123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258 |
- goog.provide('goog.ui.IframeMask');
- goog.require('goog.Disposable');
- goog.require('goog.Timer');
- goog.require('goog.dom');
- goog.require('goog.dom.iframe');
- goog.require('goog.events.EventHandler');
- goog.require('goog.structs.Pool');
- goog.require('goog.style');
- goog.ui.IframeMask = function(opt_domHelper, opt_iframePool) {
- goog.Disposable.call(this);
-
- this.dom_ = opt_domHelper || goog.dom.getDomHelper();
-
- this.snapElement_ = this.dom_.getDocument().documentElement;
-
- this.handler_ = new goog.events.EventHandler(this);
-
- this.iframePool_ = opt_iframePool;
- };
- goog.inherits(goog.ui.IframeMask, goog.Disposable);
- goog.tagUnsealableClass(goog.ui.IframeMask);
- goog.ui.IframeMask.prototype.iframe_;
- goog.ui.IframeMask.prototype.zIndex_ = 1;
- goog.ui.IframeMask.prototype.opacity_ = 0;
- goog.ui.IframeMask.prototype.disposeInternal = function() {
- if (this.iframePool_) {
- this.iframePool_.releaseObject(
- (this.iframe_));
- } else {
- goog.dom.removeNode(this.iframe_);
- }
- this.iframe_ = null;
- this.handler_.dispose();
- this.handler_ = null;
- goog.ui.IframeMask.superClass_.disposeInternal.call(this);
- };
- goog.ui.IframeMask.HIDDEN_CSS_TEXT_ =
- 'position:absolute;display:none;z-index:1';
- goog.ui.IframeMask.prototype.hideMask = function() {
- if (this.iframe_) {
- this.iframe_.style.cssText = goog.ui.IframeMask.HIDDEN_CSS_TEXT_;
- if (this.iframePool_) {
- this.iframePool_.releaseObject(this.iframe_);
- this.iframe_ = null;
- }
- }
- };
- goog.ui.IframeMask.prototype.getIframe_ = function() {
- if (!this.iframe_) {
- this.iframe_ = this.iframePool_ ?
- (this.iframePool_.getObject()) :
- goog.dom.iframe.createBlank(this.dom_);
- this.iframe_.style.cssText = goog.ui.IframeMask.HIDDEN_CSS_TEXT_;
- this.dom_.getDocument().body.appendChild(this.iframe_);
- }
- return this.iframe_;
- };
- goog.ui.IframeMask.prototype.applyMask = function() {
- var iframe = this.getIframe_();
- var bounds = goog.style.getBounds(this.snapElement_);
- iframe.style.cssText = 'position:absolute;' +
- 'left:' + bounds.left + 'px;' +
- 'top:' + bounds.top + 'px;' +
- 'width:' + bounds.width + 'px;' +
- 'height:' + bounds.height + 'px;' +
- 'z-index:' + this.zIndex_;
- goog.style.setOpacity(iframe, this.opacity_);
- iframe.style.display = 'block';
- };
- goog.ui.IframeMask.prototype.setOpacity = function(opacity) {
- this.opacity_ = opacity;
- };
- goog.ui.IframeMask.prototype.setZIndex = function(zIndex) {
- this.zIndex_ = zIndex;
- };
- goog.ui.IframeMask.prototype.setSnapElement = function(snapElement) {
- this.snapElement_ = snapElement;
- if (this.iframe_ && goog.style.isElementShown(this.iframe_)) {
- this.applyMask();
- }
- };
- goog.ui.IframeMask.prototype.listenOnTarget = function(
- target, showEvent, hideEvent, opt_snapElement) {
- var timerKey;
- this.handler_.listen(target, showEvent, function() {
- if (opt_snapElement) {
- this.setSnapElement(opt_snapElement);
- }
-
-
- timerKey = goog.Timer.callOnce(this.applyMask, 0, this);
- });
- this.handler_.listen(target, hideEvent, function() {
- if (timerKey) {
- goog.Timer.clear(timerKey);
- timerKey = null;
- }
- this.hideMask();
- });
- };
- goog.ui.IframeMask.prototype.removeHandlers = function() {
- this.handler_.removeAll();
- };
|