Skip to content

Commit

Permalink
[ENHANCEMENT] Better AJAX rating selector (CSS-only!)
Browse files Browse the repository at this point in the history
[NOTE] ratingpic() now take images from themes/images/rating/

ToDo notice:
1. Clean the CSS-mess
2. ??????
3. PROFIT
  • Loading branch information
yunasc committed Jul 21, 2014
1 parent b7891bd commit c0c8daa
Show file tree
Hide file tree
Showing 22 changed files with 105 additions and 7 deletions.
52 changes: 50 additions & 2 deletions details.php
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,7 @@ function hex_esc($matches) {
tr($tracker_lang['seeder'], "{$tracker_lang['seeder_last_seen']} " . mkprettytime($row['lastseed']) . " {$tracker_lang['ago']}");
tr($tracker_lang['size'], mksize($row['size']) . " (" . number_format($row['size']) . " {$tracker_lang['bytes']})");

$s = "";
/*$s = "";
$s .= "<div id=\"ajaxrate\"><table border=\"0\" cellpadding=\"0\" cellspacing=\"0\"><tr><td valign=\"top\" class=\"embedded\">";
if (!isset($row["rating"])) {
if ($minvotes > 1) {
Expand Down Expand Up @@ -398,7 +398,55 @@ function sendrating(){
</script>
<?
tr($tracker_lang['rating'], $s, 1);
tr($tracker_lang['rating'], $s, 1);*/

if ($CURUSER) {
?>
<script>
$(document).ready(function(){
$('span.star').click(function (e) {
e.stopPropagation();
var tid = $('#ratingtid').val();
var rate_value = $(e.target).data('value');
$.ajax({
url: 'takerate.php',
type: 'post',
data: {rating: rate_value, id: tid},
beforeSend: function () {
$('div#rating_selector').html('<img src="pic/loading.gif" />');
},
success: function (result) {
$('div#rating_selector').html(result);
}
});
});
});
</script>
<?

/* Sorry, but heredoc is not possible to indent */
$rating_selector = <<<SELECTOR
<input type="hidden" id="ratingtid" value="{$id}" />
<div id="rating_selector">
<span class="rating star" title="{$tracker_lang['vote_1']}" data-value="1">
<span class="rating star" title="{$tracker_lang['vote_2']}" data-value="2">
<span class="rating star" title="{$tracker_lang['vote_3']}" data-value="3">
<span class="rating star" title="{$tracker_lang['vote_4']}" data-value="4">
<span class="rating star" title="{$tracker_lang['vote_5']}" data-value="5">
</span></span></span></span></span>
</div>
SELECTOR;

$is_voted = mysql_fetch_array(sql_query('SELECT rating FROM ratings WHERE torrent = ' . $id . ' AND user = ' . $CURUSER['id']));
if (mysql_error())
sqlerr();
if ($is_voted) {
$stars .= ratingpic($row['rating']) . "(" . $row["rating"] . " " . $tracker_lang['from'] . " 5 ".$tracker_lang['with'] . " " . $row["numratings"] . " " . getWord($row["numratings"], array($tracker_lang['votes_1'], $tracker_lang['votes_2'], $tracker_lang['votes_3'])).")".' Âàøà îöåíêà <b>' . $is_voted['rating'] . '</b> - <b>' . $tracker_lang['vote_' . $is_voted['rating']] . '</b>';
} else {
$stars .= $rating_selector;
}
tr($tracker_lang['rating'], $stars, 1);
}

tr($tracker_lang['added'], $row["added"]);
tr($tracker_lang['views'], $row["views"]);
Expand Down
6 changes: 3 additions & 3 deletions include/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -912,11 +912,11 @@ function linkcolor($num) {
}

function ratingpic($num) {
global $pic_base_url, $tracker_lang;
$r = round($num * 2) / 2;
global $pic_base_url, $tracker_lang, $ss_uri;
$r = round($num);
if ($r < 1 || $r > 5)
return;
return "<img src=\"$pic_base_url/$r.gif\" border=\"0\" alt=\"".$tracker_lang['rating'].": $num / 5\" />";
return "<img src=\"themes/$ss_uri/images/rating/$r.gif\" border=\"0\" alt=\"".$tracker_lang['rating'].": $num / 5\" />";
}

function writecomment($userid, $comment) {
Expand Down
4 changes: 3 additions & 1 deletion languages/lang_russian/lang_constants.php
Original file line number Diff line number Diff line change
Expand Up @@ -393,7 +393,9 @@
'vote_4' => 'Хорошо',
'vote_5' => 'Отлично!',
'voted' => 'Голос добавлен!',
'votes' => 'Голосов',
'votes_1' => 'голосом',
'votes_2' => 'голосами',
'votes_3' => 'голосами',
'wait' => 'Ожидание',
'welcome_back' => 'Привет, ',
'whos_online' => 'Пользователи',
Expand Down
2 changes: 1 addition & 1 deletion takerate.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ function bark($msg) {

sql_query("UPDATE torrents SET numratings = numratings + 1, ratingsum = ratingsum + $rating WHERE id = $id");

stdmsg($tracker_lang['success'], 'Âû óñïåøíî îöåíèëè òîððåíò. Ñïàñèáî!<br />Îáíîâèòå ñòðàíèöó, ÷òî-áû óâèäåòü ðåéòèíã.');
echo 'Âàøà îöåíêà <b>' . $rating . '</b> - <b>' . $tracker_lang['vote_' . $rating] . '</b>';

//header("Refresh: 0; url=details.php?id=$id&rated=1");

Expand Down
24 changes: 24 additions & 0 deletions themes/Gray/Gray.css
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,30 @@

/* Spoiler hack */

/* AJAX css-only rating stars */
/* rating selector */
span.rating {
width: 16px; /* Must be same width as rating images */
height: 18px; /* Must be same height as rating images */
}

span.star {
display: block;
position: relative;
left: 16px; /* Must be same width as rating images */
cursor: pointer;
background: url(images/rating/off.gif) no-repeat;
}

span.star:hover {
background: url(images/rating/on.gif) no-repeat;
}

div#rating_selector > span:only-child {
left: 0px;
}
/* AJAX css-only rating stars */

body {
font-family: "tahoma";
font-size: 8pt;
Expand Down
Binary file added themes/Gray/images/rating/1.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added themes/Gray/images/rating/1_0.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added themes/Gray/images/rating/2.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added themes/Gray/images/rating/3.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added themes/Gray/images/rating/4.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added themes/Gray/images/rating/5.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added themes/Gray/images/rating/off.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added themes/Gray/images/rating/on.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
24 changes: 24 additions & 0 deletions themes/TBDev/TBDev.css
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,30 @@

/* Spoiler hack */

/* AJAX css-only rating stars */
/* rating selector */
span.rating {
width: 16px; /* Must be same width as rating images */
height: 18px; /* Must be same height as rating images */
}

span.star {
display: block;
position: relative;
left: 16px; /* Must be same width as rating images */
cursor: pointer;
background: url(images/rating/off.gif) no-repeat;
}

span.star:hover {
background: url(images/rating/on.gif) no-repeat;
}

div#rating_selector > span:only-child {
left: 0px;
}
/* AJAX css-only rating stars */

body {
font-family: "tahoma";
font-size: 8pt;
Expand Down
Binary file added themes/TBDev/images/rating/1.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added themes/TBDev/images/rating/1_0.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added themes/TBDev/images/rating/2.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added themes/TBDev/images/rating/3.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added themes/TBDev/images/rating/4.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added themes/TBDev/images/rating/5.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added themes/TBDev/images/rating/off.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added themes/TBDev/images/rating/on.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit c0c8daa

Please sign in to comment.