Created
June 10, 2013 16:33
-
-
Save ewillhite/5750195 to your computer and use it in GitHub Desktop.
Lightbox AJAX javascript
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Open in Lightbox when clicked | |
Drupal.behaviors.popupLink = function (context) { | |
$('LINK').click(function() { | |
var url = $(this).attr('href') + ' .node .content'; | |
$('#overlay, .popup').remove(); | |
$('<div id="overlay"></div>').appendTo('body').css('opacity','0').show().animate({opacity:.5}); | |
$('<div class="popup"></div>').appendTo('body'); | |
$('.popup').load(url, function() { | |
var topCenter = ($(window).height() - $('.popup').outerHeight()) / 2; | |
var leftCenter = ($(window).width() - $('.popup').outerWidth()) / 2; | |
$('.popup').css({ | |
'top': topCenter + 'px', | |
'left': leftCenter + 'px' | |
}).fadeIn(function() { | |
$('#close-overlay').remove(); | |
$('<a id="close-overlay">Close X</a>').prependTo('.popup').fadeIn(); | |
Drupal.attachBehaviors('#close-overlay'); | |
}); | |
}); | |
return false; | |
}); | |
} | |
// Close Popup Behavior | |
Drupal.behaviors.closePopup = function (context) { | |
$('#close-overlay, #overlay').click(function() { | |
$('#overlay, .popup').fadeOut('fast').remove(); | |
}); | |
$(document).keyup(function(e) { | |
if (e.keyCode == 27) { | |
$('#overlay, .popup').fadeOut('fast').remove(); | |
} | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment