Skip to content

Commit

Permalink
Added ability to grab link that transfers favorites to another device
Browse files Browse the repository at this point in the history
  • Loading branch information
Jonathan Penn committed Jan 8, 2013
1 parent d443929 commit 7abb3c9
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 2 deletions.
7 changes: 7 additions & 0 deletions app/assets/javascripts/lib/router.js
Expand Up @@ -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]();
}
Expand Down Expand Up @@ -125,6 +128,10 @@ Router = {
})).render();
},

isLoad: function(id) {
return id.search(/^load-/) !== -1;
},

isSessionId: function(pageId) {
return pageId.search(/^session-/) !== -1;
},
Expand Down
17 changes: 15 additions & 2 deletions app/assets/javascripts/models/favorites.js
Expand Up @@ -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() {
Expand All @@ -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);
},

});

Expand Down
2 changes: 2 additions & 0 deletions app/views/home/index.html.erb
Expand Up @@ -96,6 +96,8 @@

<p>Curious how it works? Download the <a href="https://github.com/jonathanpenn/icodemashschedule">source</a> and enjoy!</p>

<p>Want to copy your favorited sessions to another device? Right click on <a id='saveLink' href='#'>this link</a>, paste in an email, and open on your other device.

<p>Written and directed by <a href="http://twitter.com/jonathanpenn">Jonathan Penn</a></p>

</div>
Expand Down

0 comments on commit 7abb3c9

Please sign in to comment.