Quellcode durchsuchen

Add keyboard shortcut for searching on Google

Thibaut vor 12 Jahren
Ursprung
Commit
94119e1188

+ 3 - 0
assets/javascripts/app/shortcuts.coffee

@@ -101,6 +101,9 @@ class app.Shortcuts
       when 40
         @trigger 'altDown'
         false
+      when 71
+        @trigger 'altG'
+        false
 
   handleKeypressEvent: (event) ->
     if event.which is 63 and not event.target.value

+ 3 - 0
assets/javascripts/templates/pages/help_tmpl.coffee

@@ -77,6 +77,9 @@ app.templates.helpPage = """
   </dl>
   <h3 class="_shortcuts-title">Misc</h3>
   <dl class="_shortcuts-dl">
+    <dt class="_shortcuts-dt">
+      <code class="_shortcut-code">Alt + g</code>
+    <dd class="_shortcuts-dd">Search on Google
     <dt class="_shortcuts-dt">
       <code class="_shortcut-code">escape</code>
     <dd class="_shortcuts-dd">Reset

+ 4 - 1
assets/javascripts/templates/pages/news_tmpl.coffee

@@ -24,7 +24,10 @@ newsItem = (date, news) ->
   result
 
 app.news = [
-  [ 1386979200000, # December 14, 2013
+  [ 1389484800000, # January 12, 2013
+    """ Added <code class="_label">Alt + g</code> shortcut for searching on Google. """
+  ], [
+    1386979200000, # December 14, 2013
     """ New <a href="/postgresql/">PostgreSQL</a> documentation """
   ], [
     1386892800000, # December 13, 2013

+ 7 - 0
assets/javascripts/views/search/search.coffee

@@ -15,6 +15,7 @@ class app.views.Search extends app.View
 
   @shortcuts:
     typing: 'autoFocus'
+    altG: 'google'
 
   @routes:
     root: 'onRoot'
@@ -82,6 +83,12 @@ class app.views.Search extends app.View
     @removeClass @constructor.activeClass
     @trigger 'clear'
 
+  google: =>
+    if @value
+      $.popup "https://www.google.com/search?q=#{encodeURIComponent @value}"
+      @reset()
+    return
+
   onResults: (results) =>
     @trigger 'results', results, @flags
     @flags.initialResults = false