Skip to content

Instantly share code, notes, and snippets.

@royalsflush
Created November 21, 2012 15:37
Show Gist options
  • Save royalsflush/4125492 to your computer and use it in GitHub Desktop.
Save royalsflush/4125492 to your computer and use it in GitHub Desktop.
dialogView centralize example
function DialogView() {
var contentView=null;
var show=false;
var me = this;
var dialogDiv = document.createElement('div');
$(dialogDiv).addClass("dialog");
var coverDiv = document.createElement('div');
$(coverDiv).addClass("coverPage");
coverDiv.onclick = function() {
me.setDisplay(false);
}
this.centralize = function() {
var winW = $(window).width();
var winH = $(window).height();
var w = $(dialogDiv).width();
var h = $(dialogDiv).height();
$(dialogDiv).css('left',winW/2-w/2);
$(dialogDiv).css('top',winH/2-h/2);
}
this.setContentView = function(pView) {
contentView = pView;
$(dialogDiv).empty();
contentView.display(dialogDiv);
this.centralize();
}
this.setDisplay = function(pDisplayMode) {
if (pDisplayMode==true) {
$(dialogDiv).css('display','block');
$(coverDiv).css('display', 'block');
}
else {
$(coverDiv).css('display','none');
$(dialogDiv).css('display','none');
}
}
this.attachTo = function(pDivId) {
$(pDivId).append(dialogDiv);
$(pDivId).append(coverDiv);
this.centralize();
}
this.detach = function() {
$(dialogDiv).detach();
$(coverDiv).detach();
}
this.setDisplay(false);
$(window).resize(function() {
me.centralize();
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment