From e30b950396b7fb7f0b7e97dd083370fa4263300a Mon Sep 17 00:00:00 2001 From: timb Date: Wed, 17 Mar 2010 13:10:11 -0700 Subject: share to fb,tumblr etc --- src/site.clj | 4 ++-- static/header.css | 3 +++ static/js/pichat.js | 44 +++++++++++++++++++++++++++++++++++++++++++- template/directory.st | 12 +++++------- template/logged_dump.st | 10 ++-------- template/share_buttons.st | 6 ++++++ template/single_message.st | 8 +++----- 7 files changed, 64 insertions(+), 23 deletions(-) create mode 100644 template/share_buttons.st diff --git a/src/site.clj b/src/site.clj index e0a03e4..43e17a8 100755 --- a/src/site.clj +++ b/src/site.clj @@ -211,7 +211,7 @@ (defn fetch-messages-by-nick ([nick image-only] (fetch-messages-by-nick nick image-only 0)) ([nick image-only offset] - (let [query (str "SELECT m.content, m.created_on, u.nick, u.avatar + (let [query (str "SELECT m.content, m.created_on, m.message_id, u.nick, u.avatar FROM messages m, users u, rooms r WHERE m.user_id = u.user_id AND u.nick = ? AND r.room_id = m.room_id AND r.admin_only = false " @@ -412,7 +412,7 @@ (min (count directory) (* (inc offset) *per-directory-page*))) user-ids (apply str (interpose ", " (map #(%1 :user_id) users))) - qry (str "SELECT u.user_id, u.nick, u.avatar, m.content + qry (str "SELECT u.user_id, u.nick, u.avatar, m.content, m.message_id FROM users u, messages m WHERE u.user_id in (" user-ids ") AND m.user_id = u.user_id diff --git a/static/header.css b/static/header.css index e3cb85d..d416dd2 100755 --- a/static/header.css +++ b/static/header.css @@ -41,6 +41,9 @@ background-repeat:repeat-x; left: 0px; } + +.share-buttons img { cursor: pointer; } + #bar7{ top:12px; position:absolute; diff --git a/static/js/pichat.js b/static/js/pichat.js index 3775cfe..330aa86 100755 --- a/static/js/pichat.js +++ b/static/js/pichat.js @@ -5,6 +5,10 @@ var MaxImagePosts = 40 // Utils +// use e.g. "backgroundColor" not "background-color" +function isCSSPropertySupported(prop){ + return prop in document.body.style; +} function escapeHtml(txt) { if (!txt) { return ""; } @@ -470,7 +474,7 @@ function initDirectory() { } //big hand stuff - +// TODO: replace this with simple pointer-events thing. function initBigHand(id){ var cursorId = "#cursor-big" @@ -535,4 +539,42 @@ function initBigHand(id){ $(id).mouseover(imageMouseOver) +} + +Share = { + "getMessage": function(button){ + var message = $(button).parents(".logged-dump") + var id = message.attr("id").substr(8) // cut "message-001" to "001" + var nick = message.find("a").attr("href").substr(3) // cut "/u/timb" to "timb" + var link = "http://dump.fm/p/" + nick + "/" + id + var content = message.find(".linkify") + if (!content.length) content = message.find(".content") + var rawContent = content.html() + var img = content.find("img").attr("src") + var via = "via " + nick + " on dump.fm" + return {"nick": nick, "id": id, "link": encodeURIComponent(link), "content": content, "img": encodeURIComponent(img), "via": encodeURIComponent(via)} + }, + "openLink": function(url){ + window.open(url, "_blank") + }, + "facebook": function(button){ + var message = Share.getMessage(button) + var url = "http://www.facebook.com/share.php?u=" + message.link + "&t=" + message.via + Share.openLink(url) + }, + "tumblr": function(button){ + var message = Share.getMessage(button) + var url = "http://www.tumblr.com/share?v=3&u=" + message.img + "&t=" + message.via + Share.openLink(url) + }, + "twitter": function(button){ + var message = Share.getMessage(button) + var url = "http://twitter.com/home?status=" + message.img + encodeURIComponent(" ") + message.via + Share.openLink(url) + }, + "delicious": function(button){ + var message = Share.getMessage(button) + var url = "http://delicious.com/save?url=" + message.img + "&title=" + message.img + "¬es=" + message.via + Share.openLink(url) + } } \ No newline at end of file diff --git a/template/directory.st b/template/directory.st index 954c717..ef20a29 100644 --- a/template/directory.st +++ b/template/directory.st @@ -17,7 +17,7 @@

-
+

✭ ✭ DUMP STARS ✭ ✭

@@ -27,7 +27,7 @@
$if(users)$ $users:{ u | - +
+ $share_buttons()$ +
}$ $else$ No more users! diff --git a/template/logged_dump.st b/template/logged_dump.st index 6fe4f68..3b8336a 100755 --- a/template/logged_dump.st +++ b/template/logged_dump.st @@ -1,6 +1,5 @@ - -
+
$dump.content$

-
-
- - - + $share_buttons()$
- \ No newline at end of file diff --git a/template/share_buttons.st b/template/share_buttons.st new file mode 100644 index 0000000..eeaae92 --- /dev/null +++ b/template/share_buttons.st @@ -0,0 +1,6 @@ +
+ + + + +
\ No newline at end of file diff --git a/template/single_message.st b/template/single_message.st index e75ddd5..7047cbd 100644 --- a/template/single_message.st +++ b/template/single_message.st @@ -18,7 +18,7 @@

- + $share_buttons()$