Skip to content

Instantly share code, notes, and snippets.

@fixlr
Created November 3, 2010 20:19
Show Gist options
  • Save fixlr/661645 to your computer and use it in GitHub Desktop.
Save fixlr/661645 to your computer and use it in GitHub Desktop.
modal stuff
// Modal Window //
$('#dialog').hide;
//select all the a tag with name equal to modal
$('a[name=modal]').click(function(e) {
$('#dialog').show;
//Cancel the link behavior
e.preventDefault();
var divid = "#dialog";
var lnk = $(this).attr('href');
var title = $(this).attr('title');
var qkey = parseUri(lnk).queryKey;
var ekid = $(qkey).attr("id");
// var h3id = "#dialog-h3";
var ssid = "#dialog-content";
var loadss = '<iframe id="modal-iframe" name="modal-iframe" frameborder="0" scrolling="no" src="/box.aspx?id=' + ekid + '" />';
// $(h3id).html(title);
$(ssid).html(loadss);
//Get the screen height and width
var maskHeight = $(document).height();
var maskWidth = $(window).width();
//Set height and width to mask to fill up the whole screen
$('#mask').css({'width':maskWidth,'height':maskHeight});
//transition effect
$('#mask').fadeTo("slow",0.8);
//Get the window height and width
var winH = $(window).height();
var winW = $(window).width();
//Set the popup window to center
$(divid).css('top', winH/2-$(divid).height()/2);
$(divid).css('left', winW/2-$(divid).width()/2);
//transition effect
$(divid).fadeIn(100);
$(document).keypress(function(e) {
if (e.keyCode == 27) { $('.window .close').click(); } // esc
});
});
//if close button is clicked
$('.window .close').click(function (e) {
//Cancel the link behavior
e.preventDefault();
$("#dialog-content").html("")
$('#mask, .window').hide();
});
//if mask is clicked
$('#mask').click(function () {
$(this).hide();
$("#dialog-content").html("")
$('.window').hide();
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment