vgquotes/Src/VideoGameQuotes.Web/media/js/jquery.refresh.js

32 lines
918 B
JavaScript
Raw Normal View History

/**
* (c) 2010 Tommy Montgomery
* http://tommymontgomery.com/stuff/snippets/javascript/javascript-refresh
* Licensed under WTFPL: http://sam.zoy.org/wtfpl/COPYING
*/
(function($, window){
var refreshCookie = "jquery.refresh.fragment";
var refresh = function() {
var url = window.location.href;
var fragmentPosition = url.lastIndexOf("#");
if (fragmentPosition >= 0) {
if (fragmentPosition !== url.length - 1) {
$.cookie(refreshCookie, url.substring(fragmentPosition + 1)); //store the fragment in a cookie
}
url = url.substring(0, fragmentPosition);
}
window.location.href = url;
};
var applyFragmentFromCookie = function() {
var fragment = $.cookie(refreshCookie);
if (fragment !== null) {
window.location.href += "#" + fragment;
$.cookie(refreshCookie, null); //delete cookie
}
};
$(document).ready(applyFragmentFromCookie);
$.refresh = refresh;
}(jQuery, window));