From d398b061babc945bdf3e46e5f5a8e8091753316a Mon Sep 17 00:00:00 2001 From: skx Date: Sat, 12 Apr 2008 16:17:11 +0000 Subject: [PATCH] Added these files git-svn-id: svn+ssh://svn.debian.org/svn/planet-debian/trunk@949 c2f067bf-98e0-425f-9c98-e76020cfa380 --- www/hide.js | 186 ++++++++++++++++++++++++++++++++++++++++++++++++ www/minus-8.png | Bin 0 -> 75 bytes www/plus-8.png | Bin 0 -> 82 bytes 3 files changed, 186 insertions(+) create mode 100644 www/hide.js create mode 100644 www/minus-8.png create mode 100644 www/plus-8.png diff --git a/www/hide.js b/www/hide.js new file mode 100644 index 0000000..b659691 --- /dev/null +++ b/www/hide.js @@ -0,0 +1,186 @@ +/* Log to the console if we can: firebug firefox extension will view these */ +function log( txt) +{ + if ( window.console && window.console.log ) + { + window.console.log( txt ); + } +} + +/* create a cookie */ +function createCookie(name,value,days) +{ + var expires = ""; + if (days) + { + var date = new Date(); + date.setTime(date.getTime()+(days*24*60*60*1000)); + expires = "; expires="+date.toGMTString(); + } + document.cookie = name+"="+value+expires+"; path=/"; + log( "Created cookie: " + document.cookie ); +} + +/* read a cookie */ +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; +} + +/* erase a cookie */ +function eraseCookie(name) +{ + log( "erasingCookie" ); + createCookie(name,"",-1); +} + +/* exclude entries from the same domain as the given URL */ +function exclude( site ) +{ + log( "Excluding: " + site ); + + domain = site.match( /:\/\/(\.*)([^/:]+)/ ); + domain = domain[2]?domain[2]:''; + + var val=readCookie('excludes'); + if ( !val ) + { + val = ''; + } + if ( val.length > 0 ) + { + val = val + ","; + } + val = val + domain + createCookie('excludes',val, 10); +} + +/* un-exclude host */ +function show( site ) +{ + domain = site.match( /:\/\/(\.*)([^/:]+)/ ); + domain = domain[2]?domain[2]:''; + + log( "Showing " + site ); + + /* get the cookie */ + var val=readCookie('excludes'); + if ( !val ) { val = ''; } + + /* new cookie value */ + var n = ''; + + hosts=val.split( ',' ); + for( var i=0 ; i < hosts.length; i++ ) + { + /* the currently excluded host isn't the one we're to show now - so keep it */ + if ( hosts[i] != domain ) + { + if ( n.length > 0 ) { n = n + ',' ; } + n += hosts[i]; + } + else + { + /* the currently excluded host is now supposed to be visible.. */ + c = getElementsByClassNamePrefix( hosts[i] ); + for ( var j = 0; j < c.length; j++ ) + { + showDiv(c[j].id ); + showInlineDiv( ( c[j].id + "_hide" ) ) + hideDiv( ( c[j].id + "_show" ) ) + } + } + } + /* set new cookie */ + createCookie('excludes',n, 10); +} + +/* avoid excluding any sites : clear the cookie */ +function excludeNone() +{ + eraseCookie( 'excludes' ); + window.location.reload(); + hideDiv( 'unhide-all' ); +} + +/* hide the given div, if possible */ +function hideDiv( id ) { + i = document.getElementById(id); + if ( i ) + { + log( "Setting div " + id + " -> display:none;" ); + i.style.display="none"; + } +} + +/* show the given div */ +function showDiv( id ) { + i = document.getElementById(id); + if ( i ) + { + log( "Setting div " + id + " -> display:block;" ); + i.style.display="block"; + } +} +function showInlineDiv( id ) { + i = document.getElementById(id); + if ( i ) + { + log( "Setting div " + id + " -> display:inline;" ); + i.style.display="inline"; + } +} + +/* get elements with a class starting with the given name */ +function getElementsByClassNamePrefix(classname) { + var els = document.getElementsByTagName("*"); + var c = new RegExp("/b^|" + classname ); + final = new Array(); + var n=0; + for (var i=0; i < els.length; i++) { + if (els[i].className) { + if(c.test(els[i].className)) { + final[n] = els[i]; + n++; + } + } + } + return final; +} + +/* hide all the hosts we're supposed to */ +function hideHosts() +{ + var excl=readCookie( 'excludes'); + if ( ! excl ) { excl='' ; } + hosts=excl.split( ',' ); + + for ( var i = 0; i < hosts.length; i++ ) + { + // ok so we have a host. should we hide it? + if ( hosts[i] ) + { + c = getElementsByClassNamePrefix( hosts[i] ); + for ( var j = 0; j < c.length; j++ ) + { + hideDiv(c[j].id ); + showInlineDiv( ( c[j].id + "_show" ) ) + hideDiv( ( c[j].id + "_hide" ) ) + + showDiv( 'unhide-all' ); + } + } + } +} + diff --git a/www/minus-8.png b/www/minus-8.png new file mode 100644 index 0000000000000000000000000000000000000000..8fe9a8d4a7c71beb78e2dd3a8e23a608cb26334b GIT binary patch literal 75 zcmeAS@N?(olHy`uVBq!ia0vp^93afW0wnX;%77$;kf)1d2uE~sf&z1nL-PzK6=sI# WYTS%-PRDHmNqf5bxvXoH-87 dGniDQxfn!@g&l*IPP`0K<>~6@vd$@?2>?jX5lsL9 literal 0 HcmV?d00001 -- 2.39.2