|
<!doctype html> |
|
<html> |
|
|
|
<head> |
|
|
|
<meta charset="utf-8"> |
|
|
|
<title></title> |
|
<meta name="description" content=""> |
|
<meta name="keywords" content=""> |
|
|
|
<style> |
|
|
|
|
|
|
|
</style> |
|
|
|
</head> |
|
<body> |
|
|
|
<p id="target"></p> |
|
|
|
<script> |
|
|
|
/* |
|
(function(flavour, window, document, undefined) { |
|
|
|
'use strict'; |
|
|
|
var cookie_value; |
|
|
|
flavour.init = function(value) { |
|
|
|
var $this = this; |
|
|
|
cookie_value = value || 'mobile'; |
|
|
|
var $target = document.getElementById('target'); |
|
var $a = document.createElement('a'); |
|
var text = document.createTextNode('Switcher'); |
|
$a.href = '#'; |
|
$a.appendChild(text); |
|
$a.onclick = function($e) { |
|
|
|
$this.switcher.call($this, $e); |
|
|
|
}; |
|
$target.appendChild($a); |
|
|
|
}; |
|
|
|
flavour.switcher = function($e) { |
|
|
|
var cookie_name = 'flavour'; |
|
|
|
$e.preventDefault(); |
|
|
|
this.createCookie(cookie_name, cookie_value); |
|
|
|
location.reload(true); |
|
|
|
}; |
|
|
|
// http://clubmate.fi/setting-and-reading-cookies-with-javascript/ |
|
|
|
// Create cookie: |
|
flavour.createCookie = function(name, value, days) { |
|
|
|
// flavour.createCookie("cookie-name", "cookie-value", 30); |
|
|
|
var expires; |
|
if (days) { |
|
var date = new Date(); |
|
date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000)); |
|
expires = '; expires=' + date.toGMTString(); |
|
} else { |
|
expires = ''; |
|
} |
|
document.cookie = name + '=' + value + expires + '; path=/'; |
|
|
|
}; |
|
|
|
// Read cookie: |
|
flavour.readCookie = function(name) { |
|
|
|
// flavour.readCookie("cookie-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; |
|
|
|
}; |
|
|
|
// Erase cookie: |
|
flavour.eraseCookie = function(name) { |
|
|
|
// flavour.eraseCookie("cookie-name"); |
|
|
|
this.createCookie(name, '', -1); |
|
|
|
}; |
|
|
|
}((window.flavour = window.flavour || {}), window, document, undefined)); |
|
*/ |
|
|
|
(function(c,b,a,e){var d;c.init=function(h){var i=this;d=h||"mobile";var f=a.getElementById("target");var g=a.createElement("a");var j=a.createTextNode("Switcher");g.href="#";g.appendChild(j);g.onclick=function(k){i.switcher.call(i,k)};f.appendChild(g)};c.switcher=function(f){var g="flavour";f.preventDefault();this.createCookie(g,d);location.reload(true)};c.createCookie=function(h,i,j){var f;if(j){var g=new Date();g.setTime(g.getTime()+(j*24*60*60*1000));f="; expires="+g.toGMTString()}else{f=""}a.cookie=h+"="+i+f+"; path=/"};c.readCookie=function(g){var j=g+"=";var f=a.cookie.split(";");for(var h=0;h<f.length;h++){var k=f[h];while(k.charAt(0)===" "){k=k.substring(1,k.length)}if(k.indexOf(j)===0){return k.substring(j.length,k.length)}}return null};c.eraseCookie=function(f){this.createCookie(f,"",-1)}}((window.flavour=window.flavour||{}),window,document,undefined)); |
|
|
|
//---------------------------------------------------------------------- |
|
|
|
window.onload = function() { |
|
|
|
flavour.init('desktop'); // Passed string argument sets the cookie's value; no argument will default to a value of 'mobile'. |
|
|
|
console.log(flavour.readCookie('flavour')); |
|
|
|
} |
|
|
|
</script> |
|
|
|
</body> |
|
</html> |
Django Mobile app is here.