Skip to content

Instantly share code, notes, and snippets.

@yoko
Created January 7, 2009 12:34
Show Gist options
  • Save yoko/44264 to your computer and use it in GitHub Desktop.
Save yoko/44264 to your computer and use it in GitHub Desktop.
new Grayback().show();
p = function() {
if (typeof console != 'undefined' && typeof console.log == 'function')
console.log.apply(null, arguments);
};
Grayback = (function() {
var id = 1;
var stack = [];
var memory = null;
var msie6 = ($.browser.msie && $.browser.version < 7);
var Grayback = function(css) {
this.css = $.extend({
zIndex : 1000,
backgroundColor: '#000',
opacity : 0.5
}, css);
this.uid = id++;
this.container = null;
this.forgetSelector = ['iframe', 'select', 'object', 'embed'];
};
Grayback.prototype = {
initialize: function() {
this.container = $('<div class="grayback"/>');
var css = $.extend({}, this.css, {
display: 'none',
top : 0,
left : 0,
width : '100%',
height : '100%'
});
if (msie6) {
css.position = 'absolute';
css.height = Math.max($(window).height(), $().height(), $('body').height());
}
else
css.position = 'fixed';
this.container
.css(css)
.appendTo('body');
},
stat: function() {
if (!p) return;
p({
'this': this,
id : id,
stack : stack,
memory: memory
});
},
show: function() {
if ($.inArray(this.uid, stack) == -1)
stack.push(this.uid);
if (!this.container) {
this.initialize();
this.forget();
}
this.container.show.apply(this.container, arguments);
},
hide: function() {
var n = $.inArray(this.uid, stack);
if (n == -1) return;
stack.splice(n, 1);
this.container.hide.apply(this.container, arguments);
this.remember();
},
remove: function() {
var self = this;
this.container.hide(function() {
$(this).remove();
self.container = null;
});
},
forget: function() {
if (!msie6 || memory) return;
memory = [];
$.each(this.forgetSelector, function() {
$(this).each(function() {
if ($(this).css('visibility') != 'hidden')
memory.push(this);
});
});
$(memory).css('visibility', 'hidden');
},
remember: function() {
if (!msie6 || stack.length || !memory) return;
$(memory).css('visibility', 'visible');
}
};
return Grayback;
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment