Skip to content

Instantly share code, notes, and snippets.

@webcracy
Created January 18, 2012 16:55
Show Gist options
  • Save webcracy/1634018 to your computer and use it in GitHub Desktop.
Save webcracy/1634018 to your computer and use it in GitHub Desktop.
SOPA on Wired.com
<!-- SOPA scripts From Wired.com homepage on Jan 18, 2012 -->
<style type="text/css">
#sopa-nav-button {
background: url('/images/home/sopa_nav_button.png?ver=001') no-repeat 0px -30px;
width: 150px;
height: 30px;
overflow: hidden;
cursor: pointer;
}
</style>
<script type="text/javascript">
jQuery(function(){
// SOPA button
jQuery('#sopa-nav-button').data('is_active', true);
jQuery('#sopa-nav-button').bind('click', function() {
toggleSOPA_nav($(this).data('is_active'));
});
});
function toggleSOPA_nav(is_active) {
if(is_active){
removejscssfile_nav('sopa.css', 'css');
jQuery('#sopa-nav-button').css({'background-position':'0px 0px'});
jQuery('#sopa-nav-button').data('is_active', false);
//the utter button
jQuery('#sopa-button').css({'background-position':'-200px -60px'});
jQuery('#sopa-button').data('is_active', false);
} else {
var sopa_css = '<link rel="stylesheet" type="text/css" media="all" href="/css/sopa.css?ver=001" />';
jQuery('body').append(sopa_css);
jQuery('#sopa-nav-button').css({'background-position':'0px -30px'});
jQuery('#sopa-nav-button').data('is_active', true);
//the utter button again
jQuery('#sopa-button').css({'background-position':'0px -60px'});
jQuery('#sopa-button').data('is_active', true);
}
}
function removejscssfile_nav(filename, filetype){
var targetelement=(filetype=="js")? "script" : (filetype=="css")? "link" : "none" //determine element type to create nodelist from
var targetattr=(filetype=="js")? "src" : (filetype=="css")? "href" : "none" //determine corresponding attribute to test for
var allsuspects=document.getElementsByTagName(targetelement)
for (var i=allsuspects.length; i>=0; i--){ //search backwards within nodelist for matching elements to remove
if (allsuspects[i] && allsuspects[i].getAttribute(targetattr)!=null && allsuspects[i].getAttribute(targetattr).indexOf(filename)!=-1)
allsuspects[i].parentNode.removeChild(allsuspects[i]) //remove element by calling parentNode.removeChild()
}
}
</script>
<li>
<div id="sopa-nav-button"></div>
</li>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment