From 0b9101f3c5f0fadc2321f31cb221d3d5d059542b Mon Sep 17 00:00:00 2001 From: epriestley Date: Tue, 23 Oct 2012 12:00:45 -0700 Subject: [PATCH] Make lightbox close when the background is clicked Summary: When you click the dark background, close the lightbox. Test Plan: Clicked arrows, image, etc., to make sure it didn't close. Clicked background to close. Reviewers: btrahan, vrana Reviewed By: btrahan CC: aran Differential Revision: https://secure.phabricator.com/D3801 --- src/__celerity_resource_map__.php | 2 +- .../core/behavior-lightbox-attachments.js | 21 ++++++++++++++++++- 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/src/__celerity_resource_map__.php b/src/__celerity_resource_map__.php index 39968d0be2..8602b743bf 100644 --- a/src/__celerity_resource_map__.php +++ b/src/__celerity_resource_map__.php @@ -1385,7 +1385,7 @@ celerity_register_resource_map(array( ), 'javelin-behavior-lightbox-attachments' => array( - 'uri' => '/res/6ddb05f8/rsrc/js/application/core/behavior-lightbox-attachments.js', + 'uri' => '/res/dfc1743a/rsrc/js/application/core/behavior-lightbox-attachments.js', 'type' => 'js', 'requires' => array( diff --git a/webroot/rsrc/js/application/core/behavior-lightbox-attachments.js b/webroot/rsrc/js/application/core/behavior-lightbox-attachments.js index 0cac8eb164..9e3de0b488 100644 --- a/webroot/rsrc/js/application/core/behavior-lightbox-attachments.js +++ b/webroot/rsrc/js/application/core/behavior-lightbox-attachments.js @@ -81,7 +81,8 @@ JX.behavior('lightbox-attachments', function (config) { lightbox = JX.$N('div', { - className : 'lightbox-attachment' + className : 'lightbox-attachment', + sigil: 'lightbox-attachment' }, img ); @@ -283,4 +284,22 @@ JX.behavior('lightbox-attachments', function (config) { lightBoxHandleKeyDown ); + + // When the user clicks the background, close the lightbox. + JX.Stratcom.listen( + 'click', + 'lightbox-attachment', + function (e) { + if (!lightbox) { + return; + } + if (e.getTarget() != e.getNode('lightbox-attachment')) { + // Don't close if they clicked some other element, like the image + // itself or the next/previous arrows. + return; + } + closeLightBox(e); + e.kill(); + }); + });