From bcfec8c9d2cb6e9d9c874f0d9b325689453327d7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=86var=20Arnfj=C3=B6r=C3=B0=20Bjarmason?= Date: Sun, 28 Aug 2011 19:30:16 +0000 Subject: [PATCH] cpan.js: un-break Shift+Enter -> IFL feature I broke the Shift+Enter IFL feature while solving a bug in 140605c9d8a812a37b9bf11e7f94dbacb155249c. Now we can: * Shift+Enter to do IFL * Click the IFL button *Without* implicitly adding a "1" to search queries and thus throwing them off. I've only tested this in Chrome but it's using some pretty basic W3C core API to append the element, so it probably shouldn't break anywhere. --- root/static/js/cpan.js | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/root/static/js/cpan.js b/root/static/js/cpan.js index 26247b40dd..8f15e63cdc 100644 --- a/root/static/js/cpan.js +++ b/root/static/js/cpan.js @@ -88,7 +88,16 @@ $(document).ready(function() { $('#search-input').keydown(function(event) { if (event.keyCode == '13' && event.shiftKey) { event.preventDefault(); - document.forms[0].q.name = 'lucky'; + + /* To make this a lucky search we have to create a new + * element to pass along lucky=1. + */ + var luckyField = document.createElement("input"); + luckyField.type = 'hidden'; + luckyField.name = 'lucky'; + luckyField.value = '1'; + document.forms[0].appendChild(luckyField); + document.forms[0].submit(); } }); @@ -222,4 +231,4 @@ function favDistribution(form) { } }); return false; -} \ No newline at end of file +}