Permalink
Browse files

enable persistent mode

  • Loading branch information...
1 parent 0661cb9 commit 7fe34275c9a2da0d67334bd2d1665f061477990c Michael Sofaer committed Jan 17, 2012
Showing with 61 additions and 43 deletions.
  1. +3 −21 Readme.md
  2. +2 −1 index.html
  3. +10 −5 public/javascripts/stop_censorship.js
  4. +46 −16 spec/javascripts/stop_censorship_spec.js
View
24 Readme.md
@@ -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:
@@ -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.
View
3 index.html
@@ -15,10 +15,11 @@
<script type="text/javascript" src="//ajax.cloudflare.com/cdn-cgi/nexp/cloudflare.js" async></script>
<script type="text/javascript">
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"])});
</script>
View
15 public/javascripts/stop_censorship.js
@@ -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();
@@ -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(
View
62 spec/javascripts/stop_censorship_spec.js
@@ -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(){

0 comments on commit 7fe3427

Please sign in to comment.