merged reposts

This commit is contained in:
Jeena Paradies 2013-01-11 22:39:06 +01:00
parent 919ba97744
commit b676a33c7b
2 changed files with 171 additions and 57 deletions

View file

@ -38,23 +38,23 @@ ol li, .error, header.profile {
color: red;
}
ol li:first-child {
body > ol > li:first-child {
border-top: 0;
}
ol li:nth-child(odd), .error, header.profile {
body > ol > li:nth-child(odd), .error, header.profile {
background: url(../img/odd-bg.png) repeat-x bottom #fafafa;
}
ol li:nth-child(even) {
body > ol > li:nth-child(even) {
background: url(../img/even-bg.png) repeat-x bottom #f2f2f2;
}
ol li:hover {
body > ol > li:hover {
background: #dedede;
}
ol li:after, header.profile:after {
body > ol > li:after, header.profile:after {
content: ".";
display: block;
clear: both;
@ -249,6 +249,70 @@ li.mentioned {
margin-right: 5px;
}
.reposted_by {
position: relative;
color: #00317a;
}
.reposted_by ul {
display: none;
position: absolute;
list-style-type: none;
margin: 0;
padding: 3px 6px;
background: black;
border-radius: 3px;
box-shadow: 0 0 5px rgba(0,0,0,0.7);
z-index: 2;
}
.reposted_by:hover ul {
display: block;
}
.reposted_by:hover ul:empty {
display: none;
}
.reposted_by li {
margin: 0;
padding: 0;
background: black;
text-align: center;
border: 0;
}
.reposted_by li:hover {
background: black;
}
.reposted_by li a {
color: white;
background: black;
font-weight: normal;
text-decoration: none;
border: none;
white-space: nowrap;
}
.reposted_by ul:after {
bottom: 100%;
border: solid transparent;
content: " ";
height: 0;
width: 0;
position: absolute;
pointer-events: none;
}
.reposted_by ul:after {
border-color: rgba(0, 0, 0, 0);
border-bottom-color: #000000;
border-width: 5px;
left: 50%;
margin-left: -5px;
}
header.profile button {
background: #09F;
float: right;

View file

@ -88,9 +88,17 @@ function(jQuery, Paths, URI, HostApp, Cache) {
head.appendChild(space.cloneNode());
var reposted_by = a.cloneNode();
var reposted_by = document.createElement("span");
reposted_by.className = "reposted_by";
reposted_by.style.display = "none";
var reposted_count = document.createElement("span");
reposted_count.innerText = "by 0 people";
reposted_by.appendChild(reposted_count)
var reposted_list = document.createElement("ul");
reposted_by.appendChild(reposted_list);
head.appendChild(reposted_by)
@ -132,7 +140,7 @@ function(jQuery, Paths, URI, HostApp, Cache) {
remove: remove
}
return jQuery.extend(true, {}, this.template);
return jQuery.extend(true, {}, this.template);;
}
Core.prototype.getStatusDOMElement = function(status) {
@ -233,43 +241,35 @@ function(jQuery, Paths, URI, HostApp, Cache) {
if (typeof status.__repost != "undefined") {
template.reposted_by.href = status.__repost.entity;
template.reposted_by.innerText = status.__repost.entity;
template.reposted_by.title = status.__repost.entity;
template.reposted_by.style.display = '';
template.reposted_by.onclick = function(e) {
$(template.reposted_by).show();
var a = $("<a/>");
$(template.reposted_by).find("span").html(a)
a.attr("href", status.__repost.entity)
a.html(status.__repost.entity);
a.attr("title", status.__repost.entity);
a.click(function(e) {
HostApp.showProfileForEntity(status.__repost.entity);
return false;
}
});
var repost_profile = this.cache.profiles.getItem(status.__repost.entity)
if (repost_profile) {
var basic = repost_profile["https://tent.io/types/info/basic/v0.1.0"];
if (basic) {
template.reposted_by.innerText = basic.name;
}
} else {
Paths.findProfileURL(status.__repost.entity, function(profile_url) {
if (profile_url) {
Paths.getURL(profile_url, "GET", function(resp) {
if (resp.status >= 200 && resp.status < 400) {
var _p = JSON.parse(resp.responseText);
_this.cache.profiles.setItem(status.__repost.entity, _p);
var basic = _p["https://tent.io/types/info/basic/v0.1.0"];
if (basic && basic.name) {
template.reposted_by.innerText = basic.name;
}
Paths.findProfileURL(status.__repost.entity, function(profile_url) {
if (profile_url) {
Paths.getURL(profile_url, "GET", function(resp) {
if (resp.status >= 200 && resp.status < 400) {
var _p = JSON.parse(resp.responseText);
_this.cache.profiles.setItem(status.__repost.entity, _p);
var basic = _p["https://tent.io/types/info/basic/v0.1.0"];
if (basic && basic.name) {
a.html("by " + basic.name);
}
}, null, false); // do not send auth-headers
}
});
}
}
}, null, false); // do not send auth-headers
}
});
}
if (status && status.permissions && !status.permissions.public) {
@ -371,33 +371,83 @@ function(jQuery, Paths, URI, HostApp, Cache) {
Core.prototype.getRepost = function(repost, before_node) {
var _this = this;
var callback = function(resp) {
if (resp.status >= 200 && resp.status < 300 && before_node) {
var status = JSON.parse(resp.responseText);
status.__repost = repost;
var li = _this.getStatusDOMElement(status);
before_node.parentNode.insertBefore(li, before_node);
}
}
var post = document.getElementById("post-" + repost.content.id);
if (post) {
var reposted_count = $(post).find(".reposted_by ul li").length + 1;
if (reposted_count == 1) {
$(post).find(".reposted_by").show();
var a = $("<a/>");
a.attr("href", repost.entity);
a.attr("title", repost.entity);
a.html(repost.entity);
$(post).find(".reposted_by span").html(a);
} else {
var people_person = reposted_count == 1 ? "person" : "people";
$(post).find(".reposted_by span").html("by " + reposted_count + " " + people_person);
$(post).find(".reposted_by").show();
var li = $("<li/>");
var a = $("<a/>");
a.attr("href", repost.entity);
a.attr("title", repost.entity);
a.html(repost.entity);
li.append(a);
$(post).find(".reposted_by ul").append(li);
}
a.click(function(e) {
HostApp.showProfileForEntity(repost.entity);
return false;
});
var _this = this;
Paths.findProfileURL(repost.entity, function(profile_url) {
if (profile_url) {
Paths.getURL(profile_url, "GET", function(resp) {
if (resp.status >= 200 && resp.status < 400) {
var _p = JSON.parse(resp.responseText);
_this.cache.profiles.setItem(repost.entity, _p);
var basic = _p["https://tent.io/types/info/basic/v0.1.0"];
if (basic && basic.name) {
a.html(basic.name);
}
}
}, null, false); // do not send auth-headers
}
});
var profile = this.cache.profiles.getItem(repost.content.entity);
if (profile && profile != "null") {
var server = profile["https://tent.io/types/info/core/v0.1.0"].servers[0];
Paths.getURL(URI(server + "/posts/" + repost.content.id).toString(), "GET", callback, null, false);
} else {
var _this = this;
var callback = function(resp) {
if (resp.status >= 200 && resp.status < 300 && before_node) {
var status = JSON.parse(resp.responseText);
status.__repost = repost;
var li = _this.getStatusDOMElement(status);
before_node.parentNode.insertBefore(li, before_node);
}
}
Paths.findProfileURL(repost.content.entity, function(profile_url) {
if (profile_url) {
Paths.getURL(profile_url, "GET", function(resp) {
Paths.getURL(profile_url, "GET", function(resp) {
var profile = JSON.parse(resp.responseText);
var server = profile["https://tent.io/types/info/core/v0.1.0"].servers[0];
Paths.getURL(URI(server + "/posts/" + repost.content.id).toString(), "GET", callback, null, false);
var profile = JSON.parse(resp.responseText);
var server = profile["https://tent.io/types/info/core/v0.1.0"].servers[0];
Paths.getURL(URI(server + "/posts/" + repost.content.id).toString(), "GET", callback, null, false);
}, null, false); // do not send auth-headers
}, null, false); // do not send auth-headers
}
})
});
}
}