From 9e901485ee80cce9b1841e409d0aaa9cf3ff8af6 Mon Sep 17 00:00:00 2001 From: Lapo Luchini Date: Sat, 31 May 2014 13:45:10 +0200 Subject: [PATCH] Allow closing pinry with ESC or clicking on header. On close, remove the script as well as the images. --- pinry/static/js/bookmarklet.js | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/pinry/static/js/bookmarklet.js b/pinry/static/js/bookmarklet.js index 394cf96..4055bcc 100644 --- a/pinry/static/js/bookmarklet.js +++ b/pinry/static/js/bookmarklet.js @@ -24,6 +24,10 @@ if (!window.jQuery) { function main() { var $ = jQuery; + function closePinry() { + $('#pinry-images').add('#pinry-bookmarklet').remove(); + } + // Start Helper Functions function getFormUrl() { var hostUrl = $('#pinry-bookmarklet').attr('src').split('/')[2]; @@ -65,7 +69,11 @@ function main() { }); $('body').append(pinryImages); $('#pinry-images').append(pinryBar); - $('#pinry-bar').html('Pinry Bookmarklet'); + $('#pinry-bar').html('Pinry Bookmarklet').click(closePinry); + $(document).keyup(function (e) { + if (e.keyCode == 27) // ESC key + closePinry(); + }); $(window).scrollTop(0); } @@ -86,7 +94,7 @@ function main() { $(image).click(function() { var popUrl = getFormUrl()+encodeURIComponent(imageUrl); window.open(popUrl); - $('#pinry-images').remove(); + closePinry(); }); return $('#pinry-images').append(image); }