PageRenderTime 49ms CodeModel.GetById 40ms app.highlight 7ms RepoModel.GetById 1ms app.codeStats 0ms

/static/genetrack/genetrack.js

https://bitbucket.org/cistrome/cistrome-harvard/
JavaScript | 79 lines | 60 code | 9 blank | 10 comment | 11 complexity | e6c9a37a7fc1aacfb65145e7f92b8fa3 MD5 | raw file
 1var cookie_name = "genetrack_ui"
 2var now = new Date();
 3now.setTime(now.getTime() + 365 * 24 * 60 * 60 * 1000);
 4
 5// this toggles between none and block
 6function toggle(name){
 7	var elem = get(name)
 8	if (elem) {
 9		if (elem.style.display=="none"){
10			elem.style.display="block"
11			setCookie(cookie_name, name, now)
12		} else {
13			elem.style.display="none"
14			setCookie(cookie_name, '', now)
15		}
16		
17	}
18}
19
20function main(){
21	//executed upon main body load
22	var value = getCookie(cookie_name);
23	toggle(	value )		
24}
25
26// this toggles between visible and hidden
27function show(name){
28	var elem = get(name)
29    if (elem.style.visibility=="hidden"){
30        elem.style.visibility="visible";
31    } else {
32        elem.style.visibility="hidden";
33    }
34}
35
36// utility function to get the length of on object 
37function len(obj){
38	return obj.length;
39}
40
41// utility function to get an element by id
42function get(name){
43	return document.getElementById(name);
44}
45
46// pops up a window
47function pop_up(url) {
48	day = new Date();
49	id = day.getTime();
50	eval("page" + id + " = window.open(url, '" + id + "', 'toolbar=0,scrollbars=1,location=0,statusbar=1,menubar=0,resizable=1,width=500,height=300');");
51}
52
53// 
54// cookie management off the web
55// http://www.webreference.com/js/column8/property.html
56//
57function setCookie(name, value, expires, path, domain, secure) {
58  var curCookie = name + "=" + escape(value) +
59      ((expires) ? "; expires=" + expires.toGMTString() : "") +
60      ((path) ? "; path=" + path : "") +
61      ((domain) ? "; domain=" + domain : "") +
62      ((secure) ? "; secure" : "");
63  document.cookie = curCookie;
64}
65
66function getCookie(name) {
67  var dc = document.cookie;
68  var prefix = name + "=";
69  var begin = dc.indexOf("; " + prefix);
70  if (begin == -1) {
71    begin = dc.indexOf(prefix);
72    if (begin != 0) return null;
73  } else
74    begin += 2;
75  var end = document.cookie.indexOf(";", begin);
76  if (end == -1)
77    end = dc.length;
78  return unescape(dc.substring(begin + prefix.length, end));
79}