Skip to content
This repository has been archived by the owner on Sep 6, 2018. It is now read-only.

Commit

Permalink
enable persistent mode
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael Sofaer committed Jan 17, 2012
1 parent 0661cb9 commit 7fe3427
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 43 deletions.
24 changes: 3 additions & 21 deletions Readme.md
Expand Up @@ -8,27 +8,9 @@ Put your site on CloudFlare and then add the Stop Censorship application

###What if I'm not on CloudFlare?

To test it out, use this bookmarklet:
To test it out, use the bookmarklet on the main app page:

```javascript
javascript:(function() {try{if(!window.CloudFlare){window.CloudFlare=[];var a=document.createElement("script"),b=document.getElementsByTagName("head")[0];a.type="text/javascript";a.async=!0;a.src="//ajax.cloudflare.com/cdn-cgi/nexp/cloudflare.js";b.appendChild(a)}}catch(c){};var a=window.CloudFlare;a.push({paths:{stop_censorship:"//ajax.cloudflare.com/cdn-cgi/nexp/apps/"}});a.push(function(b,c){c("stop_censorship/config",function(){return {}});b(["stop_censorship"])})})();
```

or run this in your browser's console:

```JavaScript
try{if(!window.CloudFlare){window.CloudFlare=[];var a=document.createElement("script"),b=document.getElementsByTagName("head")[0];a.type="text/javascript";a.async=!0;a.src="//ajax.cloudflare.com/cdn-cgi/nexp/cloudflare.js";b.appendChild(a)}}catch(c){};

var censorshipConfig = {

"twitterHandle" : "MyTwitterHandle",
"position_x" : "right",
"selector" : "p, h1, .censor_me"

}

var a=window.CloudFlare;a.push({paths:{stop_censorship:"//ajax.cloudflare.com/cdn-cgi/nexp/apps/"}});a.push(function(b,c){c("stop_censorship/config",function(){return censorshipConfig});b(["stop_censorship"])});
```
http://mikesofaer.github.com/stop_censorship

If you want to support the efforts to stop American censorship, add this to your page:

Expand All @@ -40,7 +22,7 @@ If you want to support the efforts to stop American censorship, add this to your
var censorshipConfig = {
"twitterHandle" : "MyTwitterHandle", // Your Twitter handle; if not provided, your website domain will be used.
"twitterHandle" : null, // Your Twitter handle; if not provided, your website domain will be used.
"position_x" : "right", // Badge position - right or left
"selector" : "p, h1, .censor_me" // Optional selector for elements to censor. Remove for default.
Expand Down
3 changes: 2 additions & 1 deletion index.html
Expand Up @@ -15,10 +15,11 @@ <h1>Stop Censorship</h1>
&lt;script type="text/javascript" src="//ajax.cloudflare.com/cdn-cgi/nexp/cloudflare.js" async&gt;&lt;/script&gt;
&lt;script type="text/javascript"&gt;
var censorshipConfig = {
"twitterHandle" : "MyTwitterHandle", // Your Twitter handle; if not provided, your website domain will be used.
"twitterHandle" : "", // Your Twitter handle; if not provided, your website domain will be used.
"position_x" : "right", // Badge position - right or left
"selector" : "p, h1, .censor_me", // Optional selector for elements to censor. Remove for default.
"regex" : ".{5}" //In case you like Regexes, and want to change the logic for how to black out text.
"persistent" : false //Make this true if you want the bars to appear on every page view, and not fade away when the box pops up.
}
var a=window.CloudFlare;a.push({paths:{stop_censorship:"//ajax.cloudflare.com/cdn-cgi/nexp/apps/"}});a.push(function(b,c){c("stop_censorship/config",function(){return censorshipConfig});b(["stop_censorship"])});
&lt;/script&gt;
Expand Down
15 changes: 10 additions & 5 deletions public/javascripts/stop_censorship.js
Expand Up @@ -155,9 +155,11 @@ CloudFlare.define(
},

inspirationalDialog : function() {
$("span.sopafied").each(function(i, item){
$(item).replaceWith($(item).html())
})
if(!this.config.persistent) {
$("span.sopafied").each(function(i, item){
$(item).replaceWith($(item).html())
})
}

this.placeBadge();

Expand Down Expand Up @@ -212,8 +214,11 @@ CloudFlare.define(
var cookie = sopaProtest.config.cookie;

sopaProtest.placeBadge()
if((cookie && !user.getCookie(cookie)) || user.getCookie("cf_sopa")) {
return
if(!sopaProtest.config.persistent) {
if ((cookie && !user.getCookie(cookie)) || user.getCookie("cf_sopa")) {
console.info(sopaProtest.config)
return
}
}

this.each(
Expand Down
62 changes: 46 additions & 16 deletions spec/javascripts/stop_censorship_spec.js
Expand Up @@ -82,39 +82,69 @@ describe("#sopafy", function(){
beforeEach(function(){
user.setCookie("__cfduid", "something")
user.setCookie("cf_sopa", "true")
this.target.sopafy()
this.sopa_wrappers = $("span.sopafied", this.target)
})
it("should not wrap the text in anchor tags", function(){
expect(this.sopa_wrappers.text()).toBe("")
expect(this.target.text()).toBe("Hello I am a target for censorship. This anchor should not be censored!")
})
it("should create a reminder badge", function(){
expect($(".sopa_badge").length).toBe(1);
describe("and persistent mode is not on", function(){
beforeEach(function(){
this.target.sopafy()
this.sopa_wrappers = $("span.sopafied", this.target)
})
it("should not wrap the text in anchor tags", function(){
expect(this.sopa_wrappers.text()).toBe("")
expect(this.target.text()).toBe("Hello I am a target for censorship. This anchor should not be censored!")
})
it("should create a reminder badge", function(){
expect($(".sopa_badge").length).toBe(1);
})
})
describe("and persistent mode is on", function(){
beforeEach(function(){
this.sopa.config.persistent = true
this.target.sopafy()
this.sopa_wrappers = $("span.sopafied", this.target)
})
it("should wrap the text in anchor tags", function(){
expect(this.sopa_wrappers.text()).toBe("Hellotargetcensorship")
expect(this.target.text()).toBe("Hello I am a target for censorship. This anchor should not be censored!")
})
it("should create a reminder badge", function(){
expect($(".sopa_badge").length).toBe(1);
})
})

})
})

describe("inspirationalDialog", function(){
beforeEach(function(){
spyOn($, "liteDialog");
this.target = $("<span class='sopafied'>Hello I am a target for censorship.</a>")
$("#jasmine_content").html(this.target)
})
it("should create a dialog", function(){
this.sopa.inspirationalDialog();
expect($.liteDialog).toHaveBeenCalled();
})
it("should unsopafy the page", function(){
this.target = $("<span class='sopafied'>Hello I am a target for censorship.</a>")
$("#jasmine_content").append(this.target)
this.sopa.inspirationalDialog();
expect($("#jasmine_content span.sopafied").length).toBe(0);
expect($("#jasmine_content").text()).toBe("Hello I am a target for censorship.")
})
it("should create a reminder badge", function(){
this.sopa.inspirationalDialog();
expect($(".sopa_badge").length).toBe(1);
})

describe("when not in persistent mode", function(){
it("should unsopafy the page", function(){
this.sopa.config.persistent = false
this.sopa.inspirationalDialog()
expect($("#jasmine_content span.sopafied").length).toBe(0)
expect($("#jasmine_content").text()).toBe("Hello I am a target for censorship.")
})
})
describe("when in persistent mode", function(){
it("should unsopafy the page", function(){
this.sopa.config.persistent = true
this.sopa.inspirationalDialog()
console.info($("#jasmine_content span.sopafied"))
expect($("#jasmine_content span.sopafied").length).toBe(1)
expect($("#jasmine_content").text()).toBe("Hello I am a target for censorship.")
})
})
})

describe("protestContent", function(){
Expand Down

0 comments on commit 7fe3427

Please sign in to comment.