From ccd0ddba1df405b6560821903bfa820bf4c54d10 Mon Sep 17 00:00:00 2001 From: Scott Ostler Date: Tue, 22 Feb 2011 01:21:00 -0500 Subject: add updating fav counts --- src/utils.clj | 18 ++- static/js/pichat.js | 36 ++++- template/fame.st | 2 +- template/fame_dump.st | 4 +- template/frontpage.st | 256 +++++++++++-------------------- template/frontpage_share_buttons.st | 4 +- template/hall_log_dump.st | 3 +- template/hall_share_buttons.st | 19 +++ template/head.st | 5 +- template/profile.st | 20 ++- template/share_buttons.st | 2 + template/single_message.st | 50 +++--- template/single_message_share_buttons.st | 19 +++ 13 files changed, 213 insertions(+), 225 deletions(-) create mode 100644 template/hall_share_buttons.st create mode 100644 template/single_message_share_buttons.st diff --git a/src/utils.clj b/src/utils.clj index 22a0b5d..a332898 100755 --- a/src/utils.clj +++ b/src/utils.clj @@ -376,14 +376,16 @@ (defn initialize-template [st session] (.setAttribute st "domain" config/*server-url*) - (if (session :nick) - (doto st - (.setAttribute "user_email" (session :email)) - (.setAttribute "user_nick" (session :nick)) - (.setAttribute "user_avatar" (if (non-empty-string? (session :avatar)) - (session :avatar) - nil)) - (.setAttribute "isadmin" (session :is_admin)))) + (doto st + ; user_nick is used in some templates to test if user is logged in, + ; and stringtemplate only recognizes variables set to false, not nil. + (.setAttribute "logged_in" (not (nil? (:nick session)))) + (.setAttribute "user_nick" (or (:nick session) false)) + (.setAttribute "user_email" (:email session)) + (.setAttribute "user_avatar" (if (non-empty-string? (:avatar session)) + (:avatar session) + nil)) + (.setAttribute "isadmin" (:is_admin session))) st) (defn fetch-template [template session] diff --git a/static/js/pichat.js b/static/js/pichat.js index 8d849bf..afddec7 100644 --- a/static/js/pichat.js +++ b/static/js/pichat.js @@ -1160,18 +1160,38 @@ Tag = { "cache": false }); }, - "frontpage_fav": function(button) { + "animated_fav": function(button, scoreClass, bigTextSize, smallTextSize) { + if (!Nick) { return; } Tag.favorite(button); - console.log("frontpage_fav"); - var dump = $(button).parents(".dump"); - var $score = dump.find('.hallscore'); - var inc = dump.hasClass("favorite") ? 1 : -1; + var $dump = $(button).parents(".dump"); + var isAdding = $dump.hasClass('favorite'); + + // Frontpage-favs can be triggered by clicking score number, + // so manually sync heart-thumb visual state. + if ($(button).hasClass('hallscore')) { + $dump.find('.thumb').attr('src', isAdding ? Imgs.logThumb : Imgs.logThumbOff); + } + + if ($dump.attr('nick') == Nick) + return; + + var $score = $dump.find(scoreClass); + var inc = isAdding ? 1 : -1; var oldScore = parseInt($score.text(), 10); - console.log($score, oldScore + inc); $score.text(oldScore + inc); - $score.animate({ 'font-size': '60px' }, 250, function() { - $score.animate({ 'font-size': '40px' }, 250); + $score.stop().animate({ 'font-size': bigTextSize }, 250, function() { + $score.animate({ 'font-size': smallTextSize }, 250); }); + + if (isAdding) { + var link = $('') + .attr('href', Domain + '/' + Nick + '/popular') + .append($('').text(Nick)) + .append(" "); + $dump.find('.faver-list').append(link); + } else { + $dump.find('.faver-list b').filter(function() { return $(this).text() == Nick }).parent().remove(); + } } } diff --git a/template/fame.st b/template/fame.st index df030d3..d773447 100644 --- a/template/fame.st +++ b/template/fame.st @@ -17,7 +17,7 @@ diff --git a/template/frontpage.st b/template/frontpage.st index dfca4e2..857c019 100644 --- a/template/frontpage.st +++ b/template/frontpage.st @@ -8,65 +8,33 @@ frm.src=frm.src; setTimeout("refreshing()",300000); } - dump.fm - - - - + dump.fm + - - - - - - - - - - -$if(!user_nick)$ - - -$endif$ -$if(isadmin)$ - - - - - -$endif$ - - - - - - - @@ -441,7 +393,7 @@ jQuery(window).load(function(){ @@ -449,30 +401,25 @@ jQuery(window).load(function(){ - $if(!user_nick)$ - - $else$ - - - $endif$ + $if(!logged_in)$ + + $else$ + + $endif$ - - $if(user_nick)$ - - - - - - $else$ + $if(user_nick)$ + + + $else$ - Register! - $endif$ - - + Register! + $endif$ - - - + + - $if(user_nick)$ - -
-
- Logout -
-
- - $else$ -
- $form_login()$ -
- - $endif$ - - + $if(logged_in)$ +
+
+ Logout +
+
+ + $else$ +
+ $form_login()$ +
+ $endif$ @@ -521,49 +461,39 @@ jQuery(window).load(function(){
+ $if(user_nick)$ JOIN CHAT!
$else$ - - - Currently hot on dump.fm - -

Join the conversation!

or register! + Currently hot on dump.fm +
+
Join the conversation!

+ + or register! +
$endif$
- - $if(dumps)$ - $dumps: { d | $hall_log_dump(dump=d)$ }$ - $endif$ -
+ $if(dumps)$ + $dumps: { dump | $hall_log_dump()$ }$ + $endif$ +
- - $if(prev)$ - - $else$ - - $endif$ - - $if(next)$ - - $else$ - - $endif$ - + $if(prev)$ + + $endif$ + + $if(next)$ + + + + $endif$
- + $if(!user_nick)$ $endif$ diff --git a/template/profile.st b/template/profile.st index 82c77e6..f37aeba 100644 --- a/template/profile.st +++ b/template/profile.st @@ -34,7 +34,7 @@ jQuery(document).ready(function() { $if(avatar)$
$else$ -
+
$endif$ $banner()$ @@ -46,7 +46,7 @@ jQuery(document).ready(function() { $else$ - + $endif$ @@ -60,18 +60,16 @@ jQuery(document).ready(function() { $if(is_home)$ $endif$
-

- $nick$$if(score_ent)$$score_ent$$endif$

- +

$nick$$if(score_ent)$$score_ent$$endif$


contact info

$if(contact)$
$contact$
$else$ - + $endif$

bio

@@ -90,16 +88,16 @@ jQuery(document).ready(function() {
-
$if(is_home)$ your $else$ $nick$'s$endif$ most recent dumps
+
$if(is_home)$ your $else$ $nick$'s$endif$ most recent dumps
$imgs: { img | }$
diff --git a/template/share_buttons.st b/template/share_buttons.st index 7cb874f..67dd762 100644 --- a/template/share_buttons.st +++ b/template/share_buttons.st @@ -4,6 +4,7 @@ +$if(logged_in)$ $if(dump.favorited)$ $else$ @@ -11,6 +12,7 @@ $else$
$endif$ +$endif$ $if(dump.favcount)$ $dump.favcount$ $endif$ diff --git a/template/single_message.st b/template/single_message.st index 3bf49ac..872ff24 100644 --- a/template/single_message.st +++ b/template/single_message.st @@ -11,39 +11,33 @@ $banner()$



-
- - -
$dump.content$

- $dump.count$ $dump.favers: { nick | $nick$   }$ -
-$share_buttons()$ -
- - -
- $footer()$ -
-
- + $dump.count$ + + $dump.favers: { nick | $nick$  }$ +
+ $single_message_share_buttons()$ + +
+ $footer()$ +
+ + diff --git a/template/single_message_share_buttons.st b/template/single_message_share_buttons.st new file mode 100644 index 0000000..313bcb1 --- /dev/null +++ b/template/single_message_share_buttons.st @@ -0,0 +1,19 @@ + + + + + + +$if(user_nick)$ + $if(dump.favorited)$ + + $else$ +
+ +
+ $endif$ +$endif$ +$if(dump.favcount)$ + $dump.favcount$ +$endif$ +
-- cgit v1.2.3-70-g09d2