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] [13/50] Commit 8bfbb24: resolve links on the client whenever possible
Date Fri, 22 Jan 2016 02:40:53 GMT
Commit 8bfbb24b0faab157a45bfbc496f288332ccee709:
    resolve links on the client whenever possible


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

------------------------------------------------------------
views/app.js.rb                                              | ++ 
views/footer.js.rb                                           | +++++++++++++++ 
views/index.js.rb                                            | + -
views/link.js.rb                                             | +++++++++ 
views/main.js.rb                                             | +++ ----------
------------------------------------------------------------
66 changes: 55 additions, 11 deletions.
------------------------------------------------------------


diff --git a/views/app.js.rb b/views/app.js.rb
index e4b3ec5..5ee7c2e 100644
--- a/views/app.js.rb
+++ b/views/app.js.rb
@@ -1,5 +1,7 @@
 require_relative 'main'
+require_relative 'footer'
 require_relative 'index'
 require_relative 'report'
+require_relative 'link'
 
 require_relative 'agenda'
diff --git a/views/footer.js.rb b/views/footer.js.rb
new file mode 100644
index 0000000..3838fb5
--- /dev/null
+++ b/views/footer.js.rb
@@ -0,0 +1,15 @@
+class Footer < React
+  def render
+    _footer.navbar.navbar_fixed_bottom class: @@item.color do
+      if @@item.prev
+        _a.backlink.navbar_brand @@item.prev.title, rel: 'prev', 
+         href: @@item.prev.href
+      end
+
+      if @@item.next
+        _Link.nextlink.navbar_brand text: @@item.next.title, rel: 'next', 
+         href: @@item.next.href
+      end
+    end
+  end
+end
diff --git a/views/index.js.rb b/views/index.js.rb
index 55f962b..96d0850 100644
--- a/views/index.js.rb
+++ b/views/index.js.rb
@@ -16,7 +16,7 @@ def render
 	_tr class: row.color do
 	  _td row.attach
 	  _td do
-	    _a row.title, href: row.href
+	    _Link text: row.title, href: row.href
 	  end
 	  _td row.owner
 	  _td row.shepherd
diff --git a/views/link.js.rb b/views/link.js.rb
new file mode 100644
index 0000000..fb4baef
--- /dev/null
+++ b/views/link.js.rb
@@ -0,0 +1,34 @@
+#
+# Replacement for 'a' element which handles clicks events by calling
+# Main.navigate.
+#
+
+class Link < React
+  def initialize
+    @attrs = {}
+  end
+
+  def componentWillMount()
+    self.componentWillReceiveProps(self.props)
+    @attrs.onClick = self.click
+  end
+
+  def componentWillReceiveProps(props)
+    @text = props.text
+    for attr in props
+      @attrs[attr] = props[attr] unless attr == 'text'
+    end
+  end
+
+  def render
+    React.createElement('a', @attrs, @text)
+  end
+
+  def click(event)
+    href = event.target.getAttribute('href')
+    unless href.start_with? '.'
+      Main.navigate href
+      return false
+    end
+  end
+end
diff --git a/views/main.js.rb b/views/main.js.rb
index 0807186..b273f0d 100644
--- a/views/main.js.rb
+++ b/views/main.js.rb
@@ -21,16 +21,7 @@ def render
       React.createElement(@item.view, data: @item)
     end
 
-    _footer.navbar.navbar_fixed_bottom class: @item.color do
-      if @item.prev
-        _a.backlink.navbar_brand @item.prev.title, rel: 'prev', 
-         href: @item.prev.href
-      end
-      if @item.next
-        _a.nextlink.navbar_brand @item.next.title, rel: 'next', 
-         href: @item.next.href
-      end
-    end
+    _Footer item: @item
   end
 
   def componentWillMount()
@@ -47,7 +38,9 @@ def navigate(path)
   end
 
   def componentDidMount()
+    # export navigate method
     Main.navigate = self.navigate
+
     history.replaceState({path: @@path}, nil, @@path)
     document.getElementsByTagName('title')[0].textContent = @item.title
 

Mime
View raw message