Skip to content

Instantly share code, notes, and snippets.

@jimrubenstein
Last active August 29, 2015 14:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jimrubenstein/479b16385ebbec583a05 to your computer and use it in GitHub Desktop.
Save jimrubenstein/479b16385ebbec583a05 to your computer and use it in GitHub Desktop.
function getPageHistory() {
var hist = $.cookie('history');
try {
hist = JSON.parse(hist);
if (false == $.isArray(hist)) hist = [];
}
catch (e)
{
hist = [];
}
return hist;
}
function setPageHistory(hist) {
$.cookie('history', JSON.stringify(hist), { expires: 30, path: "/" });
}
function appendToHistory(url) {
var history = getPageHistory();
history.splice(0, 0, url);
setPageHistory(history);
}
function findFirst(pages /* an array... e.g. ['channel-management', 'life-sciences'] */) {
var history = getPageHistory();
for (i in history) {
var pg = history[ i ];
for (j in pages) {
if (pg.indexOf( pages[j] ) > -1)
{
return pages[j];
}
}
}
return false;
}
(function($)
{
$(function() {
appendToHistory(window.location.href)
});
})(jQuery);
var lastPage = findFirst(['channel-management', 'life-sciences']);
console.log(lastPage);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment