Skip to content

Instantly share code, notes, and snippets.

@ewillhite
Created June 10, 2013 16:33
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ewillhite/5750195 to your computer and use it in GitHub Desktop.
Save ewillhite/5750195 to your computer and use it in GitHub Desktop.
Lightbox AJAX javascript
// 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