Permalink
Browse files

cpan.js: un-break Shift+Enter -> IFL feature

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...
1 parent 140605c commit bcfec8c9d2cb6e9d9c874f0d9b325689453327d7 @avar avar committed Aug 28, 2011
Showing with 11 additions and 2 deletions.
  1. +11 −2 root/static/js/cpan.js
View
@@ -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();
}
});
@@ -222,4 +231,4 @@ function favDistribution(form) {
}
});
return false;
-}
+}

0 comments on commit bcfec8c

Please sign in to comment.