whimsical-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Sam Ruby <ru...@apache.org>
Subject [whimsy.git] [6/50] Commit 139573f: keyboard navigation
Date Fri, 22 Jan 2016 02:40:52 GMT
Commit 139573f5ef59e0421a01d9fcbafe441f5dfc06c2:
    keyboard navigation


Branch: refs/heads/master
Author: Sam Ruby <rubys@intertwingly.net>
Committer: Sam Ruby <rubys@intertwingly.net>
Pusher: rubys <rubys@apache.org>

------------------------------------------------------------
main.rb                                                      | ++ 
public/stylesheets/app.css                                   | ++++ 
views/main.js.rb                                             | ++++++++ --
------------------------------------------------------------
43 changes: 38 additions, 5 deletions.
------------------------------------------------------------


diff --git a/main.rb b/main.rb
index 2597c32..5f2f1e6 100755
--- a/main.rb
+++ b/main.rb
@@ -33,6 +33,7 @@
   @base = env['PATH_INFO'].chomp(path).untaint
   @path = path
   @agenda = "board_agenda_#{date.gsub('-','_')}.txt"
+  pass unless File.exist? File.join(FOUNDATION_BOARD, @agenda)
 
   if AGENDA_CACHE[@agenda][:mtime] == 0
     Dir.chdir(FOUNDATION_BOARD) do
@@ -73,6 +74,7 @@ def AGENDA_CACHE.parse(file, quick=false)
 
 get %r{(\d\d\d\d-\d\d-\d\d).json} do |file|
   file = "board_agenda_#{file.gsub('-','_')}.txt"
+  pass unless File.exist? File.join(FOUNDATION_BOARD, file)
   _json do
     Dir.chdir(FOUNDATION_BOARD) do
       if Dir['board_agenda_*.txt'].include? file
diff --git a/public/stylesheets/app.css b/public/stylesheets/app.css
index 6c72b8d..20bca72 100644
--- a/public/stylesheets/app.css
+++ b/public/stylesheets/app.css
@@ -77,6 +77,10 @@ pre.report {
   white-space: pre;
 }
 
+main {
+  margin: 50px 0;
+}
+
 main pre {
   font-family: monospace;
   color: #000;
diff --git a/views/main.js.rb b/views/main.js.rb
index dcca558..14a51a5 100644
--- a/views/main.js.rb
+++ b/views/main.js.rb
@@ -1,14 +1,33 @@
 class Main < React
   def initialize
     Agenda.load(@@parsed)
+    Agenda._date = @@agenda[/(\d+_\d+_\d+)/, 1].gsub('_', '-')
+    Agenda._agendas = @@agendas
+  end
+
+  def componentWillMount()
+    Main.navigate = self.navigate
+    self.navigate(@@path, true)
+
+    window.addEventListener :popstate do |event|
+      self.navigate(event.state.path, true)
+    end
+  end
+
+  def navigate(path, replace)
+    if path
+      item = Agenda.find(path)
+    else
+      item = Agenda
+    end
 
-    if @@path
-      @item = Agenda.find(@@path)
+    if replace
+      history.replaceState({path: path}, nil, path)
     else
-      Agenda._date = @@agenda[/(\d+_\d+_\d+)/, 1].gsub('_', '-')
-      Agenda._agendas = @@agendas
-      @item = Agenda
+      history.pushState({path: path}, nil, path)
     end
+
+    @item = item
   end
 
   def render
@@ -48,6 +67,14 @@ def window.onresize()
 
     document.getElementsByTagName('title')[0].textContent = @item.title
     window.onresize()
+
+    def (document.getElementsByTagName('body')[0]).onkeyup(event)
+      if event.keyCode == 37
+        self.navigate document.querySelector("a[rel=prev]").getAttribute('href')
+      elsif event.keyCode == 39
+        self.navigate document.querySelector("a[rel=next]").getAttribute('href')
+      end
+    end
   end
 
   def componentDidUpdate()

Mime
View raw message