Skip to content

Commit

Permalink
Add js to keep track of last visited index page and load it when visi…
Browse files Browse the repository at this point in the history
…ting /
  • Loading branch information
lsegal committed Feb 18, 2011
1 parent ade7fb8 commit e78e0b6
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 1 deletion.
4 changes: 4 additions & 0 deletions templates/featured_index.erb
@@ -1,3 +1,7 @@
<script type="text/javascript" charset="utf-8">
$(function() { saveIndex('featured'); });
</script>

<div id="content">
<ul id="nav">
<li class="selected">Featured</li>
Expand Down
3 changes: 2 additions & 1 deletion templates/gems_index.erb
Expand Up @@ -7,7 +7,8 @@
}
});
}


$(function() { saveIndex('gems'); });
$(fixGemLinks);
</script>

Expand Down
24 changes: 24 additions & 0 deletions templates/home.erb
@@ -1,3 +1,27 @@
<script type="text/javascript" charset="utf-8">
$(function() {
if (document.referrer) {
var refurl = document.referrer;
var re = new RegExp("^" + window.location.protocol + "//" + window.location.host + "/");
if (refurl.match(re)) {
saveIndex('');
return;
}
}

var list = document.cookie.split(/\s*;\s*/);
for (var i = 0; i < list.length; i++) {
var key = list[i].split('=', 1)[0];
if (key == 'defaultIndex') {
var name = list[i].substr(key.length + 1);
window.location = '/' + name;
saveIndex('');
return;
}
}
});
</script>

<div id="content">
<ul id="nav">
<li><a href="/featured">Featured</a></li>
Expand Down
6 changes: 6 additions & 0 deletions templates/layout.erb
Expand Up @@ -76,6 +76,12 @@
$(this).find('img').attr('src', '/images/loading.gif');
});
}

function saveIndex(url) {
var date = new Date();
date.setDate(date.getDate() + (url == '' ? -999 : 99999));
document.cookie = "defaultIndex=" + escape(url) + ";expires=" + date.toUTCString();
}

$(framesLinks);
$(searchClick);
Expand Down
4 changes: 4 additions & 0 deletions templates/scm_index.erb
@@ -1,3 +1,7 @@
<script type="text/javascript" charset="utf-8">
$(function() { saveIndex('github'); });
</script>

<div id="content">
<ul id="nav">
<li><a href="/featured">Featured</a></li>
Expand Down
4 changes: 4 additions & 0 deletions templates/stdlib_index.erb
@@ -1,3 +1,7 @@
<script type="text/javascript" charset="utf-8">
$(function() { saveIndex('stdlib'); });
</script>

<div id="content">
<ul id="nav">
<li><a href="/featured">Featured</a></li>
Expand Down

0 comments on commit e78e0b6

Please sign in to comment.