2
0
Fork 0
mirror of https://github.com/discourse/discourse.git synced 2025-09-06 10:50:21 +08:00

Convert all CoffeeScript to Javascript. See:

http://meta.discourse.org/t/is-it-better-for-discourse-to-use-javascript-or-coffeescript/3153
This commit is contained in:
Robin Ward 2013-02-20 13:15:50 -05:00
parent 68ad545f0f
commit f661fa609e
407 changed files with 13226 additions and 8953 deletions

View file

@ -43,8 +43,8 @@ U=d("es"),s,D=0;s=function(a,b){p.a(b)&&(D|=a)};s(1,"");s(2,"");s(4,"");s(8,"");
function Fb(a){"number"==typeof a&&(a+="");return"string"==typeof a?a.replace(".","%2E").replace(",","%2C"):a}v=Eb;q("il",v,x);var Gb={};y.il=Gb;var Hb=function(a,b,c,d,g,f,j,k,l,n){E(function(){m.paa(a,b,c,d,g,f,j,k,l,n)})},Ib=function(){E(function(){m.prm()})},Jb=function(a){E(function(){m.spn(a)})},Kb=function(a){E(function(){m.sps(a)})},Lb=function(a){E(function(){m.spp(a)})},Mb={"27":"//ssl.gstatic.com/gb/images/silhouette_24.png","27":"//ssl.gstatic.com/gb/images/silhouette_24.png","27":"//ssl.gstatic.com/gb/images/silhouette_24.png"},Nb=function(a){return(a=Mb[a])||"//ssl.gstatic.com/gb/images/silhouette_24.png"},
Ob=function(){E(function(){m.spd()})};q("spn",Jb);q("spp",Lb);q("sps",Kb);q("spd",Ob);q("paa",Hb);q("prm",Ib);cb("gbd4",Ib);
if(p.a("")){var Pb={d:p.a(""),e:"",sanw:p.a(""),p:"//ssl.gstatic.com/gb/images/silhouette_96.png",cp:"1",xp:p.a("1"),mg:"%1$s (delegada)",md:"%1$s (predeterminada)",mh:"220",s:"1",pp:Nb,ppl:p.a(""),ppa:p.a(""),ppm:"Página de Google+"};
y.prf=Pb};var X,Qb,Y,Rb,Z=0,Sb=function(a,b,c){if(a.indexOf)return a.indexOf(b,c);if(Array.indexOf)return Array.indexOf(a,b,c);for(c=c==h?0:0>c?Math.max(0,a.length+c):c;c<a.length;c++)if(c in a&&a[c]===b)return c;return-1},$=function(a,b){return-1==Sb(a,Z)?(r(Error(Z+"_"+b),"up","caa"),i):e},Ub=function(a,b){$([1,2],"r")&&(X[a]=X[a]||[],X[a].push(b),2==Z&&window.setTimeout(function(){b(Tb(a))},0))},Vb=function(a,b,c){if($([1],"nap")&&c){for(var d=0;d<c.length;d++)Qb[c[d]]=e;m.up.spl(a,b,"nap",c)}},Wb=function(a,
b,c){if($([1],"aop")&&c){if(Y)for(var d in Y)Y[d]=Y[d]&&-1!=Sb(c,d);else{Y={};for(d=0;d<c.length;d++)Y[c[d]]=e}m.up.spl(a,b,"aop",c)}},Xb=function(){try{if(Z=2,!Rb){Rb=e;for(var a in X)for(var b=X[a],c=0;c<b.length;c++)try{b[c](Tb(a))}catch(d){r(d,"up","tp")}}}catch(g){r(g,"up","mtp")}},Tb=function(a){if($([2],"ssp")){var b=!Qb[a];Y&&(b=b&&!!Y[a]);return b}};Rb=i;X={};Qb={};Y=h;
y.prf=Pb};var X,Qb,Y,Rb,Z=0,Sb=function(a,b,c){if(a.indexOf)return a.indexOf(b,c);if(Array.indexOf)return Array.indexOf(a,b,c);for(c=c==h?0:0>c?Math.max(0,a.length+c):c;c<a.length;c++)if(c in a&&a[c]===b)return c;return-1},$=function(a,b){return-1==Sb(a,Z)?(r(Error(Z+"_"+b),"up","caa"),i):e},Ub=function(a,b){jQuery([1,2],"r")&&(X[a]=X[a]||[],X[a].push(b),2==Z&&window.setTimeout(function(){b(Tb(a))},0))},Vb=function(a,b,c){if(jQuery([1],"nap")&&c){for(var d=0;d<c.length;d++)Qb[c[d]]=e;m.up.spl(a,b,"nap",c)}},Wb=function(a,
b,c){if(jQuery([1],"aop")&&c){if(Y)for(var d in Y)Y[d]=Y[d]&&-1!=Sb(c,d);else{Y={};for(d=0;d<c.length;d++)Y[c[d]]=e}m.up.spl(a,b,"aop",c)}},Xb=function(){try{if(Z=2,!Rb){Rb=e;for(var a in X)for(var b=X[a],c=0;c<b.length;c++)try{b[c](Tb(a))}catch(d){r(d,"up","tp")}}}catch(g){r(g,"up","mtp")}},Tb=function(a){if(jQuery([2],"ssp")){var b=!Qb[a];Y&&(b=b&&!!Y[a]);return b}};Rb=i;X={};Qb={};Y=h;
var Z=1,Yb=function(){try{return!!window.localStorage&&"object"==typeof window.localStorage}catch(a){return i}},Zb=function(a){return a&&a.style&&a.style.g&&"undefined"!=typeof a.load},$b=function(a,b,c,d){try{d||(b="og-up-"+b),Yb()?window.localStorage.setItem(b,c):Zb(a)&&(a.setAttribute(b,c),a.save(a.id))}catch(g){g.code!=DOMException.QUOTA_EXCEEDED_ERR&&r(g,"up","spd")}},ac=function(a,b,c){try{c||(b="og-up-"+b);if(Yb())return window.localStorage.getItem(b);if(Zb(a))return a.load(a.id),a.getAttribute(b)}catch(d){d.code!=
DOMException.QUOTA_EXCEEDED_ERR&&r(d,"up","gpd")}return""},bc=function(a,b,c){a.addEventListener?a.addEventListener(b,c,i):a.attachEvent&&a.attachEvent("on"+b,c)},cc=function(a){for(var b=0,c;c=a[b];b++){var d=m.up;c=c in d&&d[c];if(!c)return i}return e};q("up",{r:Ub,nap:Vb,aop:Wb,tp:Xb,ssp:Tb,spd:$b,gpd:ac,aeh:bc,aal:cc});var dc=function(a,b){a[b]=function(c){var d=arguments;m.qm(function(){a[b].apply(this,d)})}};dc(m.up,"sl");dc(m.up,"si");dc(m.up,"spl");
m.mcf("up",{sp:p.b("0.01",1)});function ec(){function a(){for(var b;(b=f[j++])&&!("m"==b[0]||b[1].auto););b&&(F(2,b[0]),b[1].url&&na(b[1].url,b[0]),b[1].libs&&G&&G(b[1].libs));j<f.length&&setTimeout(a,0)}function b(){0<g--?setTimeout(b,0):a()}var c=p.a("1"),d=p.a(""),g=3,f=A,j=0,k=window.gbarOnReady;if(k)try{k()}catch(l){r(l,"ml","or")}if(d)q("ldb",a);else if(c){var c=window,d="load",n=b,k="on"+d;if(c.addEventListener)c.addEventListener(d,n,i);else if(c.attachEvent)c.attachEvent(k,

View file

@ -0,0 +1,181 @@
/*global waitsFor:true expect:true describe:true beforeEach:true it:true */
(function() {
describe("Discourse.BBCode", function() {
var format;
format = Discourse.BBCode.format;
describe('default replacer', function() {
describe("simple tags", function() {
it("bolds text", function() {
return expect(format("[b]strong[/b]")).toBe("<span class='bbcode-b'>strong</span>");
});
it("italics text", function() {
return expect(format("[i]emphasis[/i]")).toBe("<span class='bbcode-i'>emphasis</span>");
});
it("underlines text", function() {
return expect(format("[u]underlined[/u]")).toBe("<span class='bbcode-u'>underlined</span>");
});
it("strikes-through text", function() {
return expect(format("[s]strikethrough[/s]")).toBe("<span class='bbcode-s'>strikethrough</span>");
});
it("makes code into pre", function() {
return expect(format("[code]\nx++\n[/code]")).toBe("<pre>\nx++\n</pre>");
});
it("supports spoiler tags", function() {
return expect(format("[spoiler]it's a sled[/spoiler]")).toBe("<span class=\"spoiler\">it's a sled</span>");
});
it("links images", function() {
return expect(format("[img]http://eviltrout.com/eviltrout.png[/img]")).toBe("<img src=\"http://eviltrout.com/eviltrout.png\">");
});
it("supports [url] without a title", function() {
return expect(format("[url]http://bettercallsaul.com[/url]")).toBe("<a href=\"http://bettercallsaul.com\">http://bettercallsaul.com</a>");
});
return it("supports [email] without a title", function() {
return expect(format("[email]eviltrout@mailinator.com[/email]")).toBe("<a href=\"mailto:eviltrout@mailinator.com\">eviltrout@mailinator.com</a>");
});
});
describe("lists", function() {
it("creates an ul", function() {
return expect(format("[ul][li]option one[/li][/ul]")).toBe("<ul><li>option one</li></ul>");
});
return it("creates an ol", function() {
return expect(format("[ol][li]option one[/li][/ol]")).toBe("<ol><li>option one</li></ol>");
});
});
describe("color", function() {
it("supports [color=] with a short hex value", function() {
return expect(format("[color=#00f]blue[/color]")).toBe("<span style=\"color: #00f\">blue</span>");
});
it("supports [color=] with a long hex value", function() {
return expect(format("[color=#ffff00]yellow[/color]")).toBe("<span style=\"color: #ffff00\">yellow</span>");
});
it("supports [color=] with an html color", function() {
return expect(format("[color=red]red[/color]")).toBe("<span style=\"color: red\">red</span>");
});
return it("it performs a noop on invalid input", function() {
return expect(format("[color=javascript:alert('wat')]noop[/color]")).toBe("noop");
});
});
describe("tags with arguments", function() {
it("supports [size=]", function() {
return expect(format("[size=35]BIG[/size]")).toBe("<span class=\"bbcode-size-35\">BIG</span>");
});
it("supports [url] with a title", function() {
return expect(format("[url=http://bettercallsaul.com]better call![/url]")).toBe("<a href=\"http://bettercallsaul.com\">better call!</a>");
});
return it("supports [email] with a title", function() {
return expect(format("[email=eviltrout@mailinator.com]evil trout[/email]")).toBe("<a href=\"mailto:eviltrout@mailinator.com\">evil trout</a>");
});
});
return describe("more complicated", function() {
it("can nest tags", function() {
return expect(format("[u][i]abc[/i][/u]")).toBe("<span class='bbcode-u'><span class='bbcode-i'>abc</span></span>");
});
return it("can bold two things on the same line", function() {
return expect(format("[b]first[/b] [b]second[/b]")).toBe("<span class='bbcode-b'>first</span> <span class='bbcode-b'>second</span>");
});
});
});
return describe('email environment', function() {
describe("simple tags", function() {
it("bolds text", function() {
return expect(format("[b]strong[/b]", {
environment: 'email'
})).toBe("<b>strong</b>");
});
it("italics text", function() {
return expect(format("[i]emphasis[/i]", {
environment: 'email'
})).toBe("<i>emphasis</i>");
});
it("underlines text", function() {
return expect(format("[u]underlined[/u]", {
environment: 'email'
})).toBe("<u>underlined</u>");
});
it("strikes-through text", function() {
return expect(format("[s]strikethrough[/s]", {
environment: 'email'
})).toBe("<s>strikethrough</s>");
});
it("makes code into pre", function() {
return expect(format("[code]\nx++\n[/code]", {
environment: 'email'
})).toBe("<pre>\nx++\n</pre>");
});
it("supports spoiler tags", function() {
return expect(format("[spoiler]it's a sled[/spoiler]", {
environment: 'email'
})).toBe("<span style='background-color: #000'>it's a sled</span>");
});
it("links images", function() {
return expect(format("[img]http://eviltrout.com/eviltrout.png[/img]", {
environment: 'email'
})).toBe("<img src=\"http://eviltrout.com/eviltrout.png\">");
});
it("supports [url] without a title", function() {
return expect(format("[url]http://bettercallsaul.com[/url]", {
environment: 'email'
})).toBe("<a href=\"http://bettercallsaul.com\">http://bettercallsaul.com</a>");
});
return it("supports [email] without a title", function() {
return expect(format("[email]eviltrout@mailinator.com[/email]", {
environment: 'email'
})).toBe("<a href=\"mailto:eviltrout@mailinator.com\">eviltrout@mailinator.com</a>");
});
});
describe("lists", function() {
it("creates an ul", function() {
return expect(format("[ul][li]option one[/li][/ul]", {
environment: 'email'
})).toBe("<ul><li>option one</li></ul>");
});
return it("creates an ol", function() {
return expect(format("[ol][li]option one[/li][/ol]", {
environment: 'email'
})).toBe("<ol><li>option one</li></ol>");
});
});
describe("color", function() {
it("supports [color=] with a short hex value", function() {
return expect(format("[color=#00f]blue[/color]", {
environment: 'email'
})).toBe("<span style=\"color: #00f\">blue</span>");
});
it("supports [color=] with a long hex value", function() {
return expect(format("[color=#ffff00]yellow[/color]", {
environment: 'email'
})).toBe("<span style=\"color: #ffff00\">yellow</span>");
});
it("supports [color=] with an html color", function() {
return expect(format("[color=red]red[/color]", {
environment: 'email'
})).toBe("<span style=\"color: red\">red</span>");
});
return it("it performs a noop on invalid input", function() {
return expect(format("[color=javascript:alert('wat')]noop[/color]", {
environment: 'email'
})).toBe("noop");
});
});
return describe("tags with arguments", function() {
it("supports [size=]", function() {
return expect(format("[size=35]BIG[/size]", {
environment: 'email'
})).toBe("<span style=\"font-size: 35px\">BIG</span>");
});
it("supports [url] with a title", function() {
return expect(format("[url=http://bettercallsaul.com]better call![/url]", {
environment: 'email'
})).toBe("<a href=\"http://bettercallsaul.com\">better call!</a>");
});
return it("supports [email] with a title", function() {
return expect(format("[email=eviltrout@mailinator.com]evil trout[/email]", {
environment: 'email'
})).toBe("<a href=\"mailto:eviltrout@mailinator.com\">evil trout</a>");
});
});
});
});
}).call(this);

View file

@ -1,138 +0,0 @@
describe "Discourse.BBCode", ->
format = Discourse.BBCode.format
describe 'default replacer', ->
describe "simple tags", ->
it "bolds text", ->
expect(format("[b]strong[/b]")).toBe("<span class='bbcode-b'>strong</span>")
it "italics text", ->
expect(format("[i]emphasis[/i]")).toBe("<span class='bbcode-i'>emphasis</span>")
it "underlines text", ->
expect(format("[u]underlined[/u]")).toBe("<span class='bbcode-u'>underlined</span>")
it "strikes-through text", ->
expect(format("[s]strikethrough[/s]")).toBe("<span class='bbcode-s'>strikethrough</span>")
it "makes code into pre", ->
expect(format("[code]\nx++\n[/code]")).toBe("<pre>\nx++\n</pre>")
it "supports spoiler tags", ->
expect(format("[spoiler]it's a sled[/spoiler]")).toBe("<span class=\"spoiler\">it's a sled</span>")
it "links images", ->
expect(format("[img]http://eviltrout.com/eviltrout.png[/img]")).toBe("<img src=\"http://eviltrout.com/eviltrout.png\">")
it "supports [url] without a title", ->
expect(format("[url]http://bettercallsaul.com[/url]")).toBe("<a href=\"http://bettercallsaul.com\">http://bettercallsaul.com</a>")
it "supports [email] without a title", ->
expect(format("[email]eviltrout@mailinator.com[/email]")).toBe("<a href=\"mailto:eviltrout@mailinator.com\">eviltrout@mailinator.com</a>")
describe "lists", ->
it "creates an ul", ->
expect(format("[ul][li]option one[/li][/ul]")).toBe("<ul><li>option one</li></ul>")
it "creates an ol", ->
expect(format("[ol][li]option one[/li][/ol]")).toBe("<ol><li>option one</li></ol>")
describe "color", ->
it "supports [color=] with a short hex value", ->
expect(format("[color=#00f]blue[/color]")).toBe("<span style=\"color: #00f\">blue</span>")
it "supports [color=] with a long hex value", ->
expect(format("[color=#ffff00]yellow[/color]")).toBe("<span style=\"color: #ffff00\">yellow</span>")
it "supports [color=] with an html color", ->
expect(format("[color=red]red[/color]")).toBe("<span style=\"color: red\">red</span>")
it "it performs a noop on invalid input", ->
expect(format("[color=javascript:alert('wat')]noop[/color]")).toBe("noop")
describe "tags with arguments", ->
it "supports [size=]", ->
expect(format("[size=35]BIG[/size]")).toBe("<span class=\"bbcode-size-35\">BIG</span>")
it "supports [url] with a title", ->
expect(format("[url=http://bettercallsaul.com]better call![/url]")).toBe("<a href=\"http://bettercallsaul.com\">better call!</a>")
it "supports [email] with a title", ->
expect(format("[email=eviltrout@mailinator.com]evil trout[/email]")).toBe("<a href=\"mailto:eviltrout@mailinator.com\">evil trout</a>")
describe "more complicated", ->
it "can nest tags", ->
expect(format("[u][i]abc[/i][/u]")).toBe("<span class='bbcode-u'><span class='bbcode-i'>abc</span></span>")
it "can bold two things on the same line", ->
expect(format("[b]first[/b] [b]second[/b]")).toBe("<span class='bbcode-b'>first</span> <span class='bbcode-b'>second</span>")
describe 'email environment', ->
describe "simple tags", ->
it "bolds text", ->
expect(format("[b]strong[/b]", environment: 'email')).toBe("<b>strong</b>")
it "italics text", ->
expect(format("[i]emphasis[/i]", environment: 'email')).toBe("<i>emphasis</i>")
it "underlines text", ->
expect(format("[u]underlined[/u]", environment: 'email')).toBe("<u>underlined</u>")
it "strikes-through text", ->
expect(format("[s]strikethrough[/s]", environment: 'email')).toBe("<s>strikethrough</s>")
it "makes code into pre", ->
expect(format("[code]\nx++\n[/code]", environment: 'email')).toBe("<pre>\nx++\n</pre>")
it "supports spoiler tags", ->
expect(format("[spoiler]it's a sled[/spoiler]", environment: 'email')).toBe("<span style='background-color: #000'>it's a sled</span>")
it "links images", ->
expect(format("[img]http://eviltrout.com/eviltrout.png[/img]", environment: 'email')).toBe("<img src=\"http://eviltrout.com/eviltrout.png\">")
it "supports [url] without a title", ->
expect(format("[url]http://bettercallsaul.com[/url]", environment: 'email')).toBe("<a href=\"http://bettercallsaul.com\">http://bettercallsaul.com</a>")
it "supports [email] without a title", ->
expect(format("[email]eviltrout@mailinator.com[/email]", environment: 'email')).toBe("<a href=\"mailto:eviltrout@mailinator.com\">eviltrout@mailinator.com</a>")
describe "lists", ->
it "creates an ul", ->
expect(format("[ul][li]option one[/li][/ul]", environment: 'email')).toBe("<ul><li>option one</li></ul>")
it "creates an ol", ->
expect(format("[ol][li]option one[/li][/ol]", environment: 'email')).toBe("<ol><li>option one</li></ol>")
describe "color", ->
it "supports [color=] with a short hex value", ->
expect(format("[color=#00f]blue[/color]", environment: 'email')).toBe("<span style=\"color: #00f\">blue</span>")
it "supports [color=] with a long hex value", ->
expect(format("[color=#ffff00]yellow[/color]", environment: 'email')).toBe("<span style=\"color: #ffff00\">yellow</span>")
it "supports [color=] with an html color", ->
expect(format("[color=red]red[/color]", environment: 'email')).toBe("<span style=\"color: red\">red</span>")
it "it performs a noop on invalid input", ->
expect(format("[color=javascript:alert('wat')]noop[/color]", environment: 'email')).toBe("noop")
describe "tags with arguments", ->
it "supports [size=]", ->
expect(format("[size=35]BIG[/size]", environment: 'email')).toBe("<span style=\"font-size: 35px\">BIG</span>")
it "supports [url] with a title", ->
expect(format("[url=http://bettercallsaul.com]better call![/url]", environment: 'email')).toBe("<a href=\"http://bettercallsaul.com\">better call!</a>")
it "supports [email] with a title", ->
expect(format("[email=eviltrout@mailinator.com]evil trout[/email]", environment: 'email')).toBe("<a href=\"mailto:eviltrout@mailinator.com\">evil trout</a>")

View file

@ -8,7 +8,7 @@
currentWindowOnload();
}
$('<div id="main"><div class="rootElement"></div></div>').appendTo($('body')).hide();
jQuery('<div id="main"><div class="rootElement"></div></div>').appendTo(jQuery('body')).hide();
Discourse.SiteSettings = {}

View file

@ -0,0 +1,30 @@
/*global waitsFor:true expect:true describe:true beforeEach:true it:true */
(function() {
describe("Discourse.KeyValueStore", function() {
return describe("Setting values", function() {
var store;
store = Discourse.KeyValueStore;
store.init("test");
it("able to get the value back from the store", function() {
store.set({
key: "bob",
value: "uncle"
});
return expect(store.get("bob")).toBe("uncle");
});
return it("able to nuke the store", function() {
store.set({
key: "bob1",
value: "uncle"
});
store.abandonLocal();
localStorage.a = 1;
expect(store.get("bob1")).toBe(void 0);
return expect(localStorage.a).toBe("1");
});
});
});
}).call(this);

View file

@ -1,17 +0,0 @@
describe "Discourse.KeyValueStore", ->
describe "Setting values", ->
store = Discourse.KeyValueStore
store.init("test")
it "able to get the value back from the store", ->
store.set(key: "bob", value: "uncle")
expect(store.get("bob")).toBe("uncle")
it "able to nuke the store", ->
store.set(key: "bob1", value: "uncle")
store.abandonLocal()
localStorage["a"] = 1
expect(store.get("bob1")).toBe(undefined)
expect(localStorage["a"]).toBe("1")

View file

@ -0,0 +1,13 @@
/*global waitsFor:true expect:true describe:true beforeEach:true it:true */
(function() {
describe("Discourse.MessageBus", function() {
return describe("Long polling", function() {
var bus;
bus = Discourse.MessageBus;
return bus.start();
});
});
}).call(this);

View file

@ -1,24 +0,0 @@
describe "Discourse.MessageBus", ->
describe "Long polling", ->
bus = Discourse.MessageBus
bus.start()
# PENDING: Fix to allow these to run in jasmine-guard
#it "is able to get a response from the echo server", ->
# response = null
# bus.send("/echo", "hello world", (r) -> response = r)
# # give it some time to spin up
# waitsFor((-> response == "hello world"),"gotEcho",500)
#it "should get responses from broadcast channel", ->
# response = null
# # note /message_bus/broadcast is dev only
# bus.subscribe("/animals", (r) -> response = r)
# $.ajax
# url: '/message-bus/broadcast'
# data: {channel: "/animals", data: "kitten"}
# cache: false
# waitsFor((-> response == "kitten"),"gotBroadcast", 500)

View file

@ -1,14 +0,0 @@
describe "Discourse.Onebox", ->
beforeEach ->
spyOn($, 'ajax').andCallThrough()
it "Stops rapid calls with cache true", ->
Discourse.Onebox.lookup('http://bla.com', true, (c) -> c)
Discourse.Onebox.lookup('http://bla.com', true, (c) -> c)
expect($.ajax.calls.length).toBe(1)
it "Stops rapid calls with cache false", ->
Discourse.Onebox.lookup('http://bla.com/a', false, (c) -> c)
Discourse.Onebox.lookup('http://bla.com/a', false, (c) -> c)
expect($.ajax.calls.length).toBe(1)

View file

@ -0,0 +1,28 @@
/*global waitsFor:true expect:true describe:true beforeEach:true it:true spyOn:true */
(function() {
describe("Discourse.Onebox", function() {
beforeEach(function() {
return spyOn(jQuery, 'ajax').andCallThrough();
});
it("Stops rapid calls with cache true", function() {
Discourse.Onebox.lookup('http://bla.com', true, function(c) {
return c;
});
Discourse.Onebox.lookup('http://bla.com', true, function(c) {
return c;
});
return expect(jQuery.ajax.calls.length).toBe(1);
});
return it("Stops rapid calls with cache false", function() {
Discourse.Onebox.lookup('http://bla.com/a', false, function(c) {
return c;
});
Discourse.Onebox.lookup('http://bla.com/a', false, function(c) {
return c;
});
return expect(jQuery.ajax.calls.length).toBe(1);
});
});
}).call(this);

View file

@ -0,0 +1,118 @@
/*global waitsFor:true expect:true describe:true beforeEach:true it:true runs:true */
(function() {
describe("PreloadStore", function() {
beforeEach(function() {
return PreloadStore.store('bane', 'evil');
});
describe("contains", function() {
it("returns false for a key that doesn't exist", function() {
return expect(PreloadStore.contains('joker')).toBe(false);
});
return it("returns true for a stored key", function() {
return expect(PreloadStore.contains('bane')).toBe(true);
});
});
describe('getStatic', function() {
it("returns undefined if the key doesn't exist", function() {
return expect(PreloadStore.getStatic('joker')).toBe(void 0);
});
it("returns the the key if it exists", function() {
return expect(PreloadStore.getStatic('bane')).toBe('evil');
});
return it("removes the key after being called", function() {
PreloadStore.getStatic('bane');
return expect(PreloadStore.getStatic('bane')).toBe(void 0);
});
});
return describe('get', function() {
it("returns a promise that resolves to undefined", function() {
var done, storeResult;
done = storeResult = null;
PreloadStore.get('joker').then(function(result) {
done = true;
storeResult = result;
});
waitsFor((function() {
return done;
}), "Promise never resolved", 1000);
return runs(function() {
return expect(storeResult).toBe(void 0);
});
});
it("returns a promise that resolves to the result of the finder", function() {
var done, finder, storeResult;
done = storeResult = null;
finder = function() {
return 'evil';
};
PreloadStore.get('joker', finder).then(function(result) {
done = true;
storeResult = result;
});
waitsFor((function() {
return done;
}), "Promise never resolved", 1000);
return runs(function() {
return expect(storeResult).toBe('evil');
});
});
it("returns a promise that resolves to the result of the finder's promise", function() {
var done, finder, storeResult;
done = storeResult = null;
finder = function() {
var promise;
promise = new RSVP.Promise();
promise.resolve('evil');
return promise;
};
PreloadStore.get('joker', finder).then(function(result) {
done = true;
storeResult = result;
});
waitsFor((function() {
return done;
}), "Promise never resolved", 1000);
return runs(function() {
return expect(storeResult).toBe('evil');
});
});
it("returns a promise that resolves to the result of the finder's rejected promise", function() {
var done, finder, storeResult;
done = storeResult = null;
finder = function() {
var promise;
promise = new RSVP.Promise();
promise.reject('evil');
return promise;
};
PreloadStore.get('joker', finder).then(null, function(rejectedResult) {
done = true;
storeResult = rejectedResult;
});
waitsFor((function() {
return done;
}), "Promise never rejected", 1000);
return runs(function() {
return expect(storeResult).toBe('evil');
});
});
return it("returns a promise that resolves to 'evil'", function() {
var done, storeResult;
done = storeResult = null;
PreloadStore.get('bane').then(function(result) {
done = true;
storeResult = result;
});
waitsFor((function() {
return done;
}), "Promise never resolved", 1000);
return runs(function() {
return expect(storeResult).toBe('evil');
});
});
});
});
}).call(this);

View file

@ -1,81 +0,0 @@
describe "PreloadStore", ->
beforeEach ->
PreloadStore.store('bane', 'evil')
describe "contains", ->
it "returns false for a key that doesn't exist", ->
expect(PreloadStore.contains('joker')).toBe(false)
it "returns true for a stored key", ->
expect(PreloadStore.contains('bane')).toBe(true)
describe 'getStatic', ->
it "returns undefined if the key doesn't exist", ->
expect(PreloadStore.getStatic('joker')).toBe(undefined)
it "returns the the key if it exists", ->
expect(PreloadStore.getStatic('bane')).toBe('evil')
it "removes the key after being called", ->
PreloadStore.getStatic('bane')
expect(PreloadStore.getStatic('bane')).toBe(undefined)
describe 'get', ->
it "returns a promise that resolves to undefined", ->
done = storeResult = null
PreloadStore.get('joker').then (result) ->
done = true
storeResult = result
waitsFor (-> return done), "Promise never resolved", 1000
runs -> expect(storeResult).toBe(undefined)
it "returns a promise that resolves to the result of the finder", ->
done = storeResult = null
finder = -> 'evil'
PreloadStore.get('joker', finder).then (result) ->
done = true
storeResult = result
waitsFor (-> return done), "Promise never resolved", 1000
runs -> expect(storeResult).toBe('evil')
it "returns a promise that resolves to the result of the finder's promise", ->
done = storeResult = null
finder = ->
promise = new RSVP.Promise
promise.resolve('evil')
promise
PreloadStore.get('joker', finder).then (result) ->
done = true
storeResult = result
waitsFor (-> return done), "Promise never resolved", 1000
runs -> expect(storeResult).toBe('evil')
it "returns a promise that resolves to the result of the finder's rejected promise", ->
done = storeResult = null
finder = ->
promise = new RSVP.Promise
promise.reject('evil')
promise
PreloadStore.get('joker', finder).then null, (rejectedResult) ->
done = true
storeResult = rejectedResult
waitsFor (-> return done), "Promise never rejected", 1000
runs -> expect(storeResult).toBe('evil')
it "returns a promise that resolves to 'evil'", ->
done = storeResult = null
PreloadStore.get('bane').then (result) ->
done = true
storeResult = result
waitsFor (-> return done), "Promise never resolved", 1000
runs -> expect(storeResult).toBe('evil')

View file

@ -1,15 +1,17 @@
/*global waitsFor:true expect:true describe:true beforeEach:true it:true sanitizeHtml:true */
describe("sanitize", function(){
it("strips all script tags", function(){
sanitized = sanitizeHtml("<div><script>alert('hi');</script></div>");
var sanitized = sanitizeHtml("<div><script>alert('hi');</script></div>");
expect(sanitized)
.toBe("<div></div>");
});
it("strips disallowed attributes", function(){
sanitized = sanitizeHtml("<div><p class=\"funky\" wrong='1'>hello</p></div>");
var sanitized = sanitizeHtml("<div><p class=\"funky\" wrong='1'>hello</p></div>");
expect(sanitized)
.toBe("<div><p class=\"funky\">hello</p></div>");

View file

@ -0,0 +1,34 @@
/*global waitsFor:true expect:true describe:true beforeEach:true it:true */
(function() {
describe("Discourse.UserAction", function() {
return describe("collapseStream", function() {
return it("collapses all likes", function() {
var actions;
actions = [
Discourse.UserAction.create({
action_type: Discourse.UserAction.LIKE,
topic_id: 1,
user_id: 1,
post_number: 1
}), Discourse.UserAction.create({
action_type: Discourse.UserAction.EDIT,
topic_id: 2,
user_id: 1,
post_number: 1
}), Discourse.UserAction.create({
action_type: Discourse.UserAction.LIKE,
topic_id: 1,
user_id: 2,
post_number: 1
})
];
actions = Discourse.UserAction.collapseStream(actions);
expect(actions.length).toBe(2);
expect(actions[0].get("children").length).toBe(1);
return expect(actions[0].get("children")[0].items.length).toBe(2);
});
});
});
}).call(this);

View file

@ -1,16 +0,0 @@
describe "Discourse.UserAction", ->
describe "collapseStream", ->
it "collapses all likes", ->
actions = [
Discourse.UserAction.create(action_type: Discourse.UserAction.LIKE, topic_id:1, user_id:1, post_number:1)
Discourse.UserAction.create(action_type: Discourse.UserAction.EDIT, topic_id:2, user_id:1, post_number:1)
Discourse.UserAction.create(action_type: Discourse.UserAction.LIKE, topic_id:1, user_id:2, post_number:1)
]
actions = Discourse.UserAction.collapseStream(actions)
expect(actions.length).toBe(2)
expect(actions[0].get("children").length).toBe(1)
expect(actions[0].get("children")[0].items.length).toBe(2)

View file

@ -0,0 +1,136 @@
/*global waitsFor:true expect:true describe:true beforeEach:true it:true */
(function() {
describe("Discourse.Utilities", function() {
describe("categoryUrlId", function() {
it("returns the slug when it exists", function() {
return expect(Discourse.Utilities.categoryUrlId({
slug: 'hello'
})).toBe("hello");
});
it("returns id-category when slug is an empty string", function() {
return expect(Discourse.Utilities.categoryUrlId({
id: 123,
slug: ''
})).toBe("123-category");
});
return it("returns id-category without a slug", function() {
return expect(Discourse.Utilities.categoryUrlId({
id: 456
})).toBe("456-category");
});
});
describe("Cooking", function() {
var cook;
cook = function(contents, opts) {
opts = opts || {};
opts.mentionLookup = opts.mentionLookup || (function() {
return false;
});
return Discourse.Utilities.cook(contents, opts);
};
it("surrounds text with paragraphs", function() {
return expect(cook("hello")).toBe("<p>hello</p>");
});
it("automatically handles trivial newlines", function() {
return expect(cook("1\n2\n3")).toBe("<p>1 <br>\n2 <br>\n3</p>");
});
it("handles quotes properly", function() {
var cooked;
cooked = cook("1[quote=\"bob, post:1\"]my quote[/quote]2", {
topicId: 2,
lookupAvatar: function(name) {
return "" + name;
}
});
return expect(cooked).toBe("<p>1</p><aside class='quote' data-post=\"1\" >\n <div class='title'>\n <div class='quote-controls'></div>\n" +
" bob\n bob\n said:\n </div>\n <blockquote>my quote</blockquote>\n</aside>\n<p>2</p>");
});
it("includes no avatar if none is found", function() {
var cooked;
cooked = cook("1[quote=\"bob, post:1\"]my quote[/quote]2", {
topicId: 2,
lookupAvatar: function(name) {
return null;
}
});
return expect(cooked).toBe("<p>1</p><aside class='quote' data-post=\"1\" >\n <div class='title'>\n <div class='quote-controls'></div>\n" +
" \n bob\n said:\n </div>\n <blockquote>my quote</blockquote>\n</aside>\n<p>2</p>");
});
describe("Links", function() {
it("allows links to contain query params", function() {
expect(cook("Youtube: http://www.youtube.com/watch?v=1MrpeBRkM5A")).
toBe('<p>Youtube: <a href="http://www.youtube.com/watch?v=1MrpeBRkM5A">http://www.youtube.com/watch?v=1MrpeBRkM5A</a></p>');
});
it("escapes double underscores in URLs", function() {
return expect(cook("Derpy: http://derp.com?__test=1")).toBe('<p>Derpy: <a href="http://derp.com?%5F%5Ftest=1">http://derp.com?__test=1</a></p>');
});
it("autolinks something that begins with www", function() {
return expect(cook("Atwood: www.codinghorror.com")).toBe('<p>Atwood: <a href="http://www.codinghorror.com">www.codinghorror.com</a></p>');
});
it("autolinks a URL with http://www", function() {
return expect(cook("Atwood: http://www.codinghorror.com")).toBe('<p>Atwood: <a href="http://www.codinghorror.com">http://www.codinghorror.com</a></p>');
});
it("autolinks a URL", function() {
return expect(cook("EvilTrout: http://eviltrout.com")).toBe('<p>EvilTrout: <a href="http://eviltrout.com">http://eviltrout.com</a></p>');
});
it("supports markdown style links", function() {
return expect(cook("here is [an example](http://twitter.com)")).toBe('<p>here is <a href="http://twitter.com">an example</a></p>');
});
return it("autolinks a URL with parentheses (like Wikipedia)", function() {
return expect(cook("Batman: http://en.wikipedia.org/wiki/The_Dark_Knight_(film)"))
.toBe('<p>Batman: <a href="http://en.wikipedia.org/wiki/The_Dark_Knight_(film)">http://en.wikipedia.org/wiki/The_Dark_Knight_(film)</a></p>');
});
});
describe("Mentioning", function() {
it("translates mentions to links", function() {
return expect(cook("Hello @sam", {
mentionLookup: (function() {
return true;
})
})).toBe("<p>Hello <a href='/users/sam' class='mention'>@sam</a></p>");
});
it("adds a mention class", function() {
return expect(cook("Hello @EvilTrout")).toBe("<p>Hello <span class='mention'>@EvilTrout</span></p>");
});
it("won't add mention class to an email address", function() {
return expect(cook("robin@email.host")).toBe("<p>robin@email.host</p>");
});
it("won't be affected by email addresses that have a number before the @ symbol", function() {
return expect(cook("hanzo55@yahoo.com")).toBe("<p>hanzo55@yahoo.com</p>");
});
return it("supports a @mention at the beginning of a post", function() {
return expect(cook("@EvilTrout yo")).toBe("<p><span class='mention'>@EvilTrout</span> yo</p>");
});
});
return describe("Oneboxing", function() {
it("doesn't onebox a link within a list", function() {
return expect(cook("- http://www.textfiles.com/bbs/MINDVOX/FORUMS/ethics\n\n- http://drupal.org")).not.toMatch(/onebox/);
});
it("adds a onebox class to a link on its own line", function() {
return expect(cook("http://test.com")).toMatch(/onebox/);
});
it("supports multiple links", function() {
return expect(cook("http://test.com\nhttp://test2.com")).toMatch(/onebox[\s\S]+onebox/m);
});
it("doesn't onebox links that have trailing text", function() {
return expect(cook("http://test.com bob")).not.toMatch(/onebox/);
});
return it("works with links that have underscores in them", function() {
return expect(cook("http://en.wikipedia.org/wiki/Homicide:_Life_on_the_Street")).
toBe("<p><a href=\"http://en.wikipedia.org/wiki/Homicide:_Life_on_the_Street\" class=\"onebox\" target=\"_blank\">http://en.wikipedia.org/wiki/Homicide:_Life_on_the_Street</a></p>");
});
});
});
return describe("emailValid", function() {
it("allows upper case in first part of emails", function() {
return expect(Discourse.Utilities.emailValid('Bob@example.com')).toBe(true);
});
return it("allows upper case in domain of emails", function() {
return expect(Discourse.Utilities.emailValid('bob@EXAMPLE.com')).toBe(true);
});
});
});
}).call(this);

View file

@ -1,101 +0,0 @@
describe "Discourse.Utilities", ->
describe "categoryUrlId", ->
it "returns the slug when it exists", ->
expect(Discourse.Utilities.categoryUrlId(slug: 'hello')).toBe("hello")
it "returns id-category when slug is an empty string", ->
expect(Discourse.Utilities.categoryUrlId(id: 123, slug: '')).toBe("123-category")
it "returns id-category without a slug", ->
expect(Discourse.Utilities.categoryUrlId(id: 456)).toBe("456-category")
describe "Cooking", ->
cook = (contents, opts) ->
opts = opts || {}
opts.mentionLookup = opts.mentionLookup || (() -> false)
Discourse.Utilities.cook(contents, opts)
it "surrounds text with paragraphs", ->
expect(cook("hello")).toBe("<p>hello</p>")
it "automatically handles trivial newlines", ->
expect(cook("1\n2\n3")).toBe("<p>1 <br>\n2 <br>\n3</p>")
it "handles quotes properly", ->
cooked = cook("1[quote=\"bob, post:1\"]my quote[/quote]2", {topicId: 2, lookupAvatar: (name) -> "#{name}"})
expect(cooked).toBe("<p>1</p><aside class='quote' data-post=\"1\" >\n <div class='title'>\n <div class='quote-controls'></div>\n bob\n bob\n said:\n </div>\n <blockquote>my quote</blockquote>\n</aside>\n<p>2</p>")
it "includes no avatar if none is found", ->
cooked = cook("1[quote=\"bob, post:1\"]my quote[/quote]2", {topicId: 2, lookupAvatar: (name) -> null})
expect(cooked).toBe("<p>1</p><aside class='quote' data-post=\"1\" >\n <div class='title'>\n <div class='quote-controls'></div>\n \n bob\n said:\n </div>\n <blockquote>my quote</blockquote>\n</aside>\n<p>2</p>")
describe "Links", ->
it "allows links to contain query params", ->
expect(cook("Youtube: http://www.youtube.com/watch?v=1MrpeBRkM5A")).toBe('<p>Youtube: <a href="http://www.youtube.com/watch?v=1MrpeBRkM5A">http://www.youtube.com/watch?v=1MrpeBRkM5A</a></p>')
it "escapes double underscores in URLs", ->
expect(cook("Derpy: http://derp.com?__test=1")).toBe('<p>Derpy: <a href="http://derp.com?%5F%5Ftest=1">http://derp.com?__test=1</a></p>')
it "autolinks something that begins with www", ->
expect(cook("Atwood: www.codinghorror.com")).toBe('<p>Atwood: <a href="http://www.codinghorror.com">www.codinghorror.com</a></p>')
it "autolinks a URL with http://www", ->
expect(cook("Atwood: http://www.codinghorror.com")).toBe('<p>Atwood: <a href="http://www.codinghorror.com">http://www.codinghorror.com</a></p>')
it "autolinks a URL", ->
expect(cook("EvilTrout: http://eviltrout.com")).toBe('<p>EvilTrout: <a href="http://eviltrout.com">http://eviltrout.com</a></p>')
it "supports markdown style links", ->
expect(cook("here is [an example](http://twitter.com)")).toBe('<p>here is <a href="http://twitter.com">an example</a></p>')
it "autolinks a URL with parentheses (like Wikipedia)", ->
expect(cook("Batman: http://en.wikipedia.org/wiki/The_Dark_Knight_(film)")).toBe('<p>Batman: <a href="http://en.wikipedia.org/wiki/The_Dark_Knight_(film)">http://en.wikipedia.org/wiki/The_Dark_Knight_(film)</a></p>')
describe "Mentioning", ->
it "translates mentions to links", ->
expect(cook("Hello @sam", {mentionLookup: (->true)})).toBe("<p>Hello <a href='/users/sam' class='mention'>@sam</a></p>")
it "adds a mention class", ->
expect(cook("Hello @EvilTrout")).toBe("<p>Hello <span class='mention'>@EvilTrout</span></p>")
it "won't add mention class to an email address", ->
expect(cook("robin@email.host")).toBe("<p>robin@email.host</p>")
it "won't be affected by email addresses that have a number before the @ symbol", ->
expect(cook("hanzo55@yahoo.com")).toBe("<p>hanzo55@yahoo.com</p>")
it "supports a @mention at the beginning of a post", ->
expect(cook("@EvilTrout yo")).toBe("<p><span class='mention'>@EvilTrout</span> yo</p>")
# Oneboxing functionality
describe "Oneboxing", ->
it "doesn't onebox a link within a list", ->
expect(cook("- http://www.textfiles.com/bbs/MINDVOX/FORUMS/ethics\n\n- http://drupal.org")).not.toMatch(/onebox/)
it "adds a onebox class to a link on its own line", ->
expect(cook("http://test.com")).toMatch(/onebox/)
it "supports multiple links", ->
expect(cook("http://test.com\nhttp://test2.com")).toMatch(/onebox[\s\S]+onebox/m)
it "doesn't onebox links that have trailing text", ->
expect(cook("http://test.com bob")).not.toMatch(/onebox/)
it "works with links that have underscores in them", ->
expect(cook("http://en.wikipedia.org/wiki/Homicide:_Life_on_the_Street")).toBe("<p><a href=\"http://en.wikipedia.org/wiki/Homicide:_Life_on_the_Street\" class=\"onebox\" target=\"_blank\">http://en.wikipedia.org/wiki/Homicide:_Life_on_the_Street</a></p>")
describe "emailValid", ->
it "allows upper case in first part of emails", ->
expect(Discourse.Utilities.emailValid('Bob@example.com')).toBe(true)
it "allows upper case in domain of emails", ->
expect(Discourse.Utilities.emailValid('bob@EXAMPLE.com')).toBe(true)