npm install jshint
node_modules/jshint/bin/jshint redirector.js
Last active
May 23, 2016 19:57
-
-
Save eeeschwartz/a092332448c45a8c600349319fe73bd8 to your computer and use it in GitHub Desktop.
Javascript-based redirects from lexingtonky.gov to next.lexingtonky.gov
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
node_modules/* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function () { | |
"use strict"; | |
var lib = { | |
param: function (nameParam) { | |
var url = window.location.href, | |
name = nameParam.replace(/[\[\]]/g, "\\$&"), | |
regex = new RegExp("[?&]" + name + "(=([^&#]*)|&|#|$)"), | |
results = regex.exec(url); | |
if (!results) return null; | |
if (!results[2]) return ''; | |
return decodeURIComponent(results[2].replace(/\+/g, " ")); | |
}, | |
width: function() { | |
// vanilla JS window width and height | |
var w=window, | |
d=document, | |
e=d.documentElement, | |
g=d.getElementsByTagName('body')[0], | |
x=w.innerWidth||e.clientWidth||g.clientWidth; | |
return x; | |
} | |
}; | |
var redirector = { | |
maxWidth: 600, | |
shouldRedirect: function (screenWidth, referrer) { | |
if (screenWidth > this.maxWidth) { return false; } | |
// dont redirect internal links | |
if (referrer.indexOf('lexingtonky.gov') > -1) { return false; } | |
return true; | |
}, | |
targetPath: function (pageId) { | |
return redirectTable[pageId]; | |
}, | |
redirectTo: function (targetPath) { | |
window.location = "https://next.lexingtonky.gov" + targetPath; | |
}, | |
redirect: function (pageId, pageWidth, referrer) { | |
var targetPath = this.targetPath(pageId); | |
if (this.shouldRedirect(pageWidth, referrer)) { this.redirectTo(targetPath); } | |
} | |
}; | |
var redirectTable = { | |
200: "/browse/recreation/aquatics", | |
}; | |
redirector.redirect(lib.param("page"), lib.width(), document.referrer); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment