diff --git a/app/assets/javascripts/lib/router.js b/app/assets/javascripts/lib/router.js index edccef1..c4c9b4a 100644 --- a/app/assets/javascripts/lib/router.js +++ b/app/assets/javascripts/lib/router.js @@ -66,6 +66,9 @@ Router = { this.displaySession(pageId); } else if (this.isSessionSlotId(pageId)) { this.displaySessionSlot(pageId); + } else if (this.isLoad(pageId)) { + Favorites.parse(pageId); + location.reload(); } else { this[pageId](); } @@ -125,6 +128,10 @@ Router = { })).render(); }, + isLoad: function(id) { + return id.search(/^load-/) !== -1; + }, + isSessionId: function(pageId) { return pageId.search(/^session-/) !== -1; }, diff --git a/app/assets/javascripts/models/favorites.js b/app/assets/javascripts/models/favorites.js index a84973b..9a30d82 100644 --- a/app/assets/javascripts/models/favorites.js +++ b/app/assets/javascripts/models/favorites.js @@ -32,7 +32,15 @@ var FavoritesCollection = Backbone.Model.extend({ }, save: function() { - window.localStorage['favorites'] = JSON.stringify(this._favorites); + var favoritesString = JSON.stringify(this._favorites); + window.localStorage['favorites'] = favoritesString; + var transferUrl = [ + location.protocol + "//", + location.host, + location.pathname, + "#load-" + escape(favoritesString) + ]; + $("a#saveLink").attr("href", transferUrl.join('')); }, load: function() { @@ -41,7 +49,12 @@ var FavoritesCollection = Backbone.Model.extend({ var parsed = JSON.parse(data); if (parsed) this._favorites = parsed; } - } + }, + + parse: function(hashId) { + var escaped = hashId.replace(/^load-/, ''); + window.localStorage['favorites'] = unescape(escaped); + }, }); diff --git a/app/views/home/index.html.erb b/app/views/home/index.html.erb index 0c58e16..a4190df 100644 --- a/app/views/home/index.html.erb +++ b/app/views/home/index.html.erb @@ -96,6 +96,8 @@

Curious how it works? Download the source and enjoy!

+

Want to copy your favorited sessions to another device? Right click on this link, paste in an email, and open on your other device. +

Written and directed by Jonathan Penn