Created
January 14, 2012 21:41
-
-
Save evantahler/1612996 to your computer and use it in GitHub Desktop.
SOPA blackout for ModCloth
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// I am a script which can be used to modify the DOM of modcloth.com in support of SPOA, by blacking out a portion of the site and explaining the message. | |
// I should be used as follows: | |
// javascript:(function () { | |
// var newScript = document.createElement('script'); | |
// newScript.type = 'text/javascript'; | |
// newScript.src = 'https://raw.github.com/gist/1612996/sopa.js'; | |
// document.getElementsByTagName('body')[0].appendChild(newScript); | |
// })(); | |
if(typeof modcloth == "undefined"){modcloth = {};} | |
modcloth.sopa = {}; | |
modcloth.sopa.showTime = 3000; | |
modcloth.sopa.fadeTime = 3000; | |
modcloth.sopa.divCounter = 0; | |
// for all pages: monitate style placement | |
modcloth.sopa.monetateHeader = function(){ | |
var monetateDiv = $("#header-monetate-container"); | |
if(monetateDiv.length > 0){ | |
var original = monetateDiv.html(); | |
var newContent = '<a style="display:block;width:100%;height:39px;vertical-align:middle;text-align:center;background-color:#000;background-image:url(http://americancensorship.org/images/stop-censorship-small.png);background-position:center;center;background-repeat:no-repeat;" href="http://americancensorship.org"></a>'; | |
modcloth.sopa.showThenFadeBack(monetateDiv, original, newContent); | |
} | |
} | |
// for categoy pages, update product images | |
modcloth.sopa.categoryImages = function(){ | |
// coming soon | |
} | |
// for PDP pages: overlay a sopa banner | |
modcloth.sopa.pdpImages = function(){ | |
var imgDiv = $("#product_main_image"); | |
if(imgDiv.length > 0){ | |
var height = imgDiv.height(); | |
var width = imgDiv.width(); | |
var newContent = '<div id="sopaPDPImage"><a style="display:block;width:'+width+'px;height:'+height+'px;vertical-align:middle;text-align:center;background-color:#000;background-image:url(http://americancensorship.org/images/stop-censorship-small.png);background-position:center;center;background-repeat:no-repeat;" href="http://americancensorship.org"></a></div>' | |
var original = imgDiv.html(); | |
modcloth.sopa.showThenFadeBack(imgDiv, original, newContent); | |
} | |
} | |
// utils | |
modcloth.sopa.showThenFadeBack = function(div, originalContet, newContent){ | |
var containerID = "SOPA_" + modcloth.sopa.divCounter; | |
modcloth.sopa.divCounter++; | |
var containedDiv = "<div id=\""+containerID+"\">" + newContent + "</div>"; | |
div.html(containedDiv); | |
setTimeout(function(){ | |
$("#"+containerID+"").fadeOut(modcloth.sopa.fadeTime, function(){ | |
div.html(originalContet); | |
}); | |
}, modcloth.sopa.showTime) | |
} | |
// init container | |
$(document).ready(function() { | |
modcloth.sopa.monetateHeader(); | |
modcloth.sopa.categoryImages(); | |
modcloth.sopa.pdpImages(); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment