Created
December 16, 2011 20:39
-
-
Save corbanbrook/1487876 to your computer and use it in GitHub Desktop.
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() { | |
// Usage: | |
// | |
// <script src='http://pressly.com/redirect.js' type='text/javascript'></script> | |
// <script>Pressly.redirect("http://tablet.domain.com");</script> | |
// | |
/* >> Generated code from Issue Config */ | |
// Supported devices to redirect | |
// var devices = [ | |
// { | |
// name: "Apple iPad iOS 5+", | |
// pattern: /iPad.+OS\s5/, | |
// type: "tablet", | |
// list: "white", | |
// navTracking: true, | |
// adTracking: true | |
// }, | |
// { | |
// name: "Chrome", | |
// pattern: /Chrome/, | |
// type: "desktop", | |
// list: "white", | |
// navTracking: true, | |
// adTracking: true | |
// } | |
// ]; | |
/* >> End Generated code block */ | |
function isSupported() { | |
var uagent = navigator.userAgent, result; | |
function is(device) { return device.list === "white" && device.pattern && uagent.search(device.pattern) !== -1; } | |
for (var i = 0; i < devices.length; result = is(devices[i++]) || result); | |
return result; | |
} | |
function readCookie(name) { | |
var nameEQ = name + "="; | |
var ca = document.cookie.split(';'); | |
for (var i = 0; i < ca.length; i++) { | |
var c = ca[i]; | |
while (c.charAt(0) == ' ') { | |
c = c.substring(1, c.length); | |
} | |
if (c.indexOf(nameEQ) == 0) { | |
return c.substring(nameEQ.length, c.length); | |
} | |
} | |
return null; | |
} | |
function createCookie(name, value, days) { | |
var expires; | |
if (days) { | |
var date = new Date(); | |
//date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000)); | |
// TODO: Hardcoded to 1 minute. This value should probably be set by an options param | |
date.setTime(date.getTime() + (60 * 1000)); | |
expires = "; expires=" + date.toGMTString(); | |
} else { | |
expires = ""; | |
} | |
document.cookie = name + "=" + value + expires + "; path=/"; | |
} | |
window.Pressly = { | |
redirect: function(url) { | |
if (window.location.search.substr(1).indexOf('fullsite=true') !== -1) { | |
createCookie("pressly-view-full-site", "true", 1); | |
} | |
if (isSupported() && readCookie("pressly-view-full-site") !== "true") { | |
window.location = url; | |
} | |
} | |
}; | |
}()); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment