You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@whimsical.apache.org by ru...@apache.org on 2017/07/18 23:25:16 UTC

[whimsy] branch master updated: avoid adding in-page navigation to the browser history

This is an automated email from the ASF dual-hosted git repository.

rubys pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/whimsy.git


The following commit(s) were added to refs/heads/master by this push:
     new 9ccb0cd  avoid adding in-page navigation to the browser history
9ccb0cd is described below

commit 9ccb0cdfe0a5a8aa40e73be80dc51c4f325a90bd
Author: Sam Ruby <ru...@intertwingly.net>
AuthorDate: Tue Jul 18 19:24:43 2017 -0400

    avoid adding in-page navigation to the browser history
---
 www/secretary/workbench/views/parts.js.rb | 24 +++++++++++++++++++++++-
 1 file changed, 23 insertions(+), 1 deletion(-)

diff --git a/www/secretary/workbench/views/parts.js.rb b/www/secretary/workbench/views/parts.js.rb
index ae806da..579a6a2 100644
--- a/www/secretary/workbench/views/parts.js.rb
+++ b/www/secretary/workbench/views/parts.js.rb
@@ -54,7 +54,8 @@ class Parts < React
       end
 
       _li options do
-        _a attachment, href: link, target: 'content', draggable: 'false'
+        _a attachment, href: link, target: 'content', draggable: 'false',
+          onClick: self.navigate
       end
     end
 
@@ -241,6 +242,21 @@ class Parts < React
     self.extractHeaders(@@headers)
 
     window.addEventListener 'message', self.status_update
+
+    # add click handler on all non-part links.  Note: part links may
+    # change, and click handlers are established above
+    parts = Array(document.querySelectorAll('#parts a[target=content'))
+    Array(document.querySelectorAll('a[target=content')).each do |link|
+      next if parts.include? link
+      link.onclick = self.navigate
+    end
+
+    # when back button is clicked, go all of the way back
+    history_length =  window.history.length
+    window.addEventListener 'popstate' do |event|
+      console.log 'popstate'
+      window.history.go(history_length - window.history.length)
+    end
   end
 
   def componentWillReceiveProps()
@@ -555,4 +571,10 @@ class Parts < React
   def dragEnd(event)
     @drag = nil
   end
+
+  # implement content navigation using the history API
+  def navigate(event)
+    destination = event.target.attributes['href'].value
+    window.parent.frames.content.history.replaceState({}, nil, destination)
+  end
 end

-- 
To stop receiving notification emails like this one, please contact
['"commits@whimsical.apache.org" <co...@whimsical.apache.org>'].