Skip to content

Commit

Permalink
cpan.js: un-break Shift+Enter -> IFL feature
Browse files Browse the repository at this point in the history
I broke the Shift+Enter IFL feature while solving a bug in
140605c.

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.
  • Loading branch information
avar committed Aug 28, 2011
1 parent 140605c commit bcfec8c
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions root/static/js/cpan.js
Expand Up @@ -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
* <input> 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();
}
});
Expand Down Expand Up @@ -222,4 +231,4 @@ function favDistribution(form) {
}
});
return false;
}
}

0 comments on commit bcfec8c

Please sign in to comment.