Load unauthed button requests via JSONP from buttons.reddit.com.

This commit is contained in:
Max Goodman
2011-05-05 13:32:49 -07:00
parent d1ae1650bf
commit 8c56f89663
2 changed files with 44 additions and 33 deletions

View File

@@ -23,6 +23,17 @@ $(function() {
$(".entry").removeClass("dislikes").removeClass("likes");
}
}
function submit_url(url, sr, title) {
var submit = "http:///www.reddit.com";
if (sr) {
submit += "/r/" + sr;
}
submit += "/submit?url=" + encodeURIComponent(url);
if (title) {
submit += "&title=" + encodeURIComponent(title);
}
return submit;
}
$(".arrow.up").click(function() {
state = $(this).hasClass("up") ? 1: 0;
set_score_class();
@@ -46,14 +57,7 @@ $(function() {
b = lst[1];
querydict[a] = b;
});
var submit = "/submit?url=" + encodeURIComponent(querydict.url);
if (querydict.sr) {
submit = "/r/" + querydict.sr + submit;
}
if (querydict.title) {
submit += "&title=" + encodeURIComponent(querydict.title);
}
$("a").attr("href", submit);
$("a").attr("href", submit_url(querydict.url, querydict.sr, querydict.title));
if(querydict.bgcolor) {
$("body").css("background-color", color(querydict.bgcolor));
}
@@ -86,7 +90,7 @@ $(function() {
};
/* add the thing's id */
$(".thing").addClass("id-" + data.name);
$(".bling a, a.bling").attr("href", data.permalink);
$(".bling a, a.bling").attr("href", "http://www.reddit.com"+data.permalink);
if(data.likes) {
real_state = 1;
transition_score(function() {
@@ -129,13 +133,7 @@ $(function() {
};
var make_submit = function() {
var submit = "/submit?url=" + encodeURIComponent(querydict.url);
if (querydict.sr) {
submit = "/r/" + querydict.sr + submit;
}
if (querydict.title) {
submit += "&title=" + encodeURIComponent(querydict.title);
}
var submit = submit_url(querydict.url, querydict.sr, querydict.title);
$(".score:visible").fadeOut(function() {
$(".score").html('<a class="submit" target="' +
target + '" href="' +
@@ -153,23 +151,36 @@ $(function() {
});
}
var url = "/button_info.json";
var options = {
type: "GET", url: null,
data: {},
success : update_button,
error: make_submit
};
var target = "/button_info.json";
if (querydict.sr) {
url = "/r/" + querydict.sr + url;
}
params = {};
if ($.defined(querydict.url)) {
params["url"] = querydict.url;
}
if ($.defined(querydict.id)) {
params["id"] = querydict.id;
target = "/r/" + querydict.sr + target;
}
$.ajax({ type: "GET", url: url,
data: params,
success : update_button,
error: make_submit,
dataType: "json"});
if ($.cookie_read("session", "reddit_").data) {
options.url = target;
options.dataType = "json";
} else {
options.url = "http://buttons.reddit.com" + target;
options.dataType = options.jsonp = "jsonp";
options.jsonpCallback = "buttonInfoCb";
options.cache = true;
}
if ($.defined(querydict.url)) {
options.data["url"] = querydict.url;
}
if ($.defined(querydict.id)) {
options.data["id"] = querydict.id;
}
$.ajax(options);
}
);
@@ -183,4 +194,4 @@ function set_score() {
function finalize_thing(data) {
/* to be overridden for anything in the non-general case */
}
}

View File

@@ -763,8 +763,8 @@ $.cookie_write = function(c) {
}
};
$.cookie_read = function(name) {
var nameEQ = cookie_name_prefix + name + '=';
$.cookie_read = function(name, prefix) {
var nameEQ = (prefix || cookie_name_prefix) + name + '=';
var ca=document.cookie.split(';');
/* walk the list backwards so we always get the last cookie in the
list */