Skip to content

Instantly share code, notes, and snippets.

@rbarazi
Forked from corbanbrook/gist:1487876
Created December 16, 2011 21:23
Show Gist options
  • Save rbarazi/1488057 to your computer and use it in GitHub Desktop.
Save rbarazi/1488057 to your computer and use it in GitHub Desktop.
(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 */
var devices = [
// White list
{
name: "Apple iPad iOS 4.3+",
pattern: /iPad.+OS\s4_3/,
type: "tablet",
list: "white",
navTracking: true,
adTracking: true
},
{
name: "Apple iPad iOS 5+",
pattern: /iPad.+OS\s5/,
type: "tablet",
list: "white",
navTracking: true,
adTracking: true
},
{
name: "Samsung Galaxy Tab 10 GT-P7510",
pattern: /Android.+GT/,
type: "tablet",
list: "white",
navTracking: true,
adTracking: true
},
{
name: "RIM Playbook",
pattern: /PlayBook.+RIM\sTablet.+AppleWebKit/,
type: "tablet",
list: "white",
navTracking: true,
adTracking: true
},
{
name: "Kindle Fire",
pattern: /Silk.+AppleWebKit/,
type: "tablet",
list: "white",
navTracking: true,
adTracking: true
},
// Grey list
{
name: "Apple iPad iOS 4.2", // iOS 4.2 doesnt work correctly as images stop loading after continued use
pattern: /iPad.+OS\s4_2/,
type: "tablet",
list: "grey",
navTracking: true,
adTracking: false
},
{
name: "HP Touchpad",
pattern: /hp\-tablet.+hpwOS.+AppleWebKit/,
type: "tablet",
list: "grey",
navTracking: true,
adTracking: true
},
{
name: "Motorola Xoom",
pattern: /Xoom.+AppleWebKit/,
type: "tablet",
list: "grey",
navTracking: true,
adTracking: true
},
{
name: "Apple iPhone 4+",
pattern: /iPhone.+OS\s5/,
type: "phone",
list: "grey",
navTracking: true,
adTracking: true // TODO ask if we should track ads for iphone4
}
];
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