[Customisation Database Commits] r347 - in /trunk/titania: includes/objects/rating.php js/common.js js/ratings.js styles/default/template/misc/rate.html styles/default/template/overall_header.html styles/default/theme/common.css
Nathan Guse
exreaction at phpbb.com
Fri Sep 4 17:51:13 BST 2009
Author: exreaction
Date: Fri Sep 4 17:51:12 2009
New Revision: 347
Log:
Some more work on the ratings, still not working properly yet :/
Added:
trunk/titania/js/common.js (with props)
Removed:
trunk/titania/js/ratings.js
Modified:
trunk/titania/includes/objects/rating.php
trunk/titania/styles/default/template/misc/rate.html
trunk/titania/styles/default/template/overall_header.html
trunk/titania/styles/default/theme/common.css
Modified: trunk/titania/includes/objects/rating.php
==============================================================================
*** trunk/titania/includes/objects/rating.php (original)
--- trunk/titania/includes/objects/rating.php Fri Sep 4 17:51:12 2009
***************
*** 220,225 ****
--- 220,228 ----
'UA_MAX_RATING' => titania::$config->max_rating,
));
+ // reset the stars block
+ phpbb::$template->destroy_block_vars('stars');
+
for ($i = 1; $i <= titania::$config->max_rating; $i++)
{
phpbb::$template->assign_block_vars('stars', array(
***************
*** 244,250 ****
return false;
}
! if ($rating < 0 || $rating > titania::$config->max_rating)
{
return false;
}
--- 247,253 ----
return false;
}
! if ($rating < 0 || $rating > titania::$config->max_rating || $this->rating_id)
{
return false;
}
***************
*** 275,286 ****
parent::delete();
! // This is accurate enough as long as we have at least 2 decimal places
! $sql = "UPDATE {$this->cache_table} SET
! {$this->cache_rating} = ({$this->cache_rating} * {$this->rating_count} - {$this->rating_value}) / ({$this->rating_count} - 1),
! {$this->cache_rating_count} = {$this->cache_rating_count} - 1
! WHERE {$this->object_column} = {$this->rating_object_id}";
! phpbb::$db->sql_query($sql);
return true;
}
--- 278,303 ----
parent::delete();
! if ($this->rating_count == 1)
! {
! $sql_ary = array(
! $this->cache_rating => 0,
! $this->cache_rating_count => 0,
! );
!
! $sql = 'UPDATE ' . $this->cache_table . ' SET ' . phpbb::$db->sql_build_array('UPDATE', $sql_ary) . '
! WHERE ' . $this->object_column . ' = ' . $this->rating_object_id;
! phpbb::$db->sql_query($sql);
! }
! else
! {
! // This is accurate enough as long as we have at least 2 decimal places
! $sql = "UPDATE {$this->cache_table} SET
! {$this->cache_rating} = ({$this->cache_rating} * {$this->rating_count} - {$this->rating_value}) / ({$this->rating_count} - 1),
! {$this->cache_rating_count} = {$this->cache_rating_count} - 1
! WHERE {$this->object_column} = {$this->rating_object_id}";
! phpbb::$db->sql_query($sql);
! }
return true;
}
Added: trunk/titania/js/common.js
==============================================================================
*** trunk/titania/js/common.js (added)
--- trunk/titania/js/common.js Fri Sep 4 17:51:12 2009
***************
*** 0 ****
--- 1,87 ----
+ $(document).ready(function(){
+
+ // AJAX Rate
+ $("ul.rating li a, ul.rated li a").click(function(event){
+ event.preventDefault();
+
+ // Get the child img id which holds some info we need.
+ var child = $(this).children().attr('id');
+
+ // Child contains the object_id and the star number.
+ var object = child.split('_');
+
+ // Set the red stars that we neeed to.
+ for (i = 1; i <= max_rating; i++)
+ {
+ if (i <= object[1])
+ {
+ $('#' + object[0] + '_' + i).attr({src: green_star.src});
+ }
+ else
+ {
+ $('#' + object[0] + '_' + i).attr({src: grey_star.src});
+ }
+ }
+
+ if ($("#rating_" + object[0]).hasClass("rating"))
+ {
+ $("#rating_" + object[0]).removeClass("rating");
+ $("#rating_" + object[0]).addClass("rated");
+ $(this).unbind("hover");
+ $("#" + object[0] + "_remove").parent().parent().removeClass("hidden");
+ }
+ else
+ {
+ $("#rating_" + object[0]).removeClass("rated");
+ $("#rating_" + object[0]).addClass("rating");
+ $("#" + object[0] + "_remove").parent().parent().addClass("hidden");
+ }
+
+ return;
+
+ $.ajax({
+ type: "POST",
+ url: $(this).attr('href'),
+ success: function() {
+ }
+ });
+ });
+
+ // Rating hover functions
+ $("ul.rating li a").hover(
+ function(){
+ // Over function. This will change the stars up to the point that was hovered on to red
+
+ // Get the child img id which holds some info we need.
+ var child = $(this).children().attr('id');
+
+ // Child contains the object_id and the star number.
+ var object = child.split('_');
+
+ $('#rating' + object[0] + " li a img").each(function() {
+ $(this).attr({src: grey_star.src});
+ });
+
+ // Set the red stars that we neeed to.
+ for (i = 1; i <= object[1]; i++)
+ {
+ $('#' + object[0] + '_' + i).attr({src: red_star.src});
+ }
+ },
+ function(){
+ // Out function. Reset to default stars
+ $("ul.rating li a img.green").each(function() {
+ $(this).attr({src: green_star.src});
+ });
+
+ $("ul.rating li a img.orange").each(function() {
+ $(this).attr({src: orange_star.src});
+ });
+
+ $("ul.rating li a img.grey").each(function() {
+ $(this).attr({src: grey_star.src});
+ });
+ }
+ );
+
+ });
\ No newline at end of file
Propchange: trunk/titania/js/common.js
------------------------------------------------------------------------------
svn:keywords = "Author Date Id Revision"
Removed: trunk/titania/js/ratings.js
==============================================================================
*** trunk/titania/js/ratings.js (original)
--- trunk/titania/js/ratings.js (removed)
***************
*** 1,50 ****
- function ratingHover(cnt, name)
- {
- for (var i = 1; i <= max_rating; i++)
- {
- star = document.getElementById(name + '_' + i);
-
- if (i <= cnt)
- {
- star.src = red_star.src;
- }
- else
- {
- star.src = grey_star.src;
- }
- }
- }
-
- function ratingUnHover(cnt, name)
- {
- for (var i = 1; i <= max_rating; i++)
- {
- star = document.getElementById(name + '_' + i);
-
- if (i <= Math.round(cnt))
- {
- star.src = orange_star.src;
- }
- else
- {
- star.src = grey_star.src;
- }
- }
- }
-
- function ratingDown(id, name)
- {
- for (var i = 1; i <= max_rating; i++)
- {
- star = document.getElementById(name + '_' + i);
-
- if (i <= cnt)
- {
- star.src = green_star.src;
- }
- else
- {
- star.src = grey_star.src;
- }
- }
- }
\ No newline at end of file
--- 0 ----
Modified: trunk/titania/styles/default/template/misc/rate.html
==============================================================================
*** trunk/titania/styles/default/template/misc/rate.html (original)
--- trunk/titania/styles/default/template/misc/rate.html Fri Sep 4 17:51:12 2009
***************
*** 1,4 ****
! <ul class="rating" id="rating_{OBJECT_ID}">
<!-- BEGIN stars -->
<li><a href="{stars.RATE_URL}"><img id="{OBJECT_ID}_{stars.ID}" alt="{stars.ALT}" title="{stars.ALT}"
<!-- IF S_HAS_RATED && stars.ID <= OBJECT_RATING -->
--- 1,4 ----
! <ul class="<!-- IF S_HAS_RATED -->rated<!-- ELSE -->rating<!-- ENDIF -->" id="rating_{OBJECT_ID}">
<!-- BEGIN stars -->
<li><a href="{stars.RATE_URL}"><img id="{OBJECT_ID}_{stars.ID}" alt="{stars.ALT}" title="{stars.ALT}"
<!-- IF S_HAS_RATED && stars.ID <= OBJECT_RATING -->
***************
*** 10,16 ****
<!-- ENDIF -->
/></a></li>
<!-- END stars -->
! <li><a href="{RATE_URL}">
! <img id="{OBJECT_ID}_remove" class="remove" src="{UA_REMOVE_STAR_SRC}" alt="{L_REMOVE_RATING}" title="{L_REMOVE_RATING}">
</a></li>
</ul>
\ No newline at end of file
--- 10,16 ----
<!-- ENDIF -->
/></a></li>
<!-- END stars -->
! <li<!-- IF not S_HAS_RATED --> class="hidden"<!-- ENDIF -->><a href="{RATE_URL}">
! <img id="{OBJECT_ID}_remove" class="remove" src="{UA_REMOVE_STAR_SRC}" alt="{L_REMOVE_RATING}" title="{L_REMOVE_RATING}" />
</a></li>
</ul>
\ No newline at end of file
Modified: trunk/titania/styles/default/template/overall_header.html
==============================================================================
*** trunk/titania/styles/default/template/overall_header.html (original)
--- trunk/titania/styles/default/template/overall_header.html Fri Sep 4 17:51:12 2009
***************
*** 27,32 ****
--- 27,33 ----
<script type="text/javascript" src="{TITANIA_ROOT_PATH}js/jquery-1.3.2.min.js"></script>
<script type="text/javascript" src="{TITANIA_ROOT_PATH}js/jquery-ui-1.7.2.custom.min.js"></script>
+ <script type="text/javascript" src="{TITANIA_ROOT_PATH}js/common.js"></script>
<script type="text/javascript">
// <![CDATA[
***************
*** 49,93 ****
var orange_star= new Image(16,16);
orange_star.src = "{UA_ORANGE_STAR_SRC}";
var max_rating = "{UA_MAX_RATING}";
-
- $(document).ready(function(){
- // Rating stuff
- $("ul.rating li a").click(function(event){
- event.preventDefault();
- });
- $("ul.rating li a").hover(
- function(){
- // Over function. This will change the stars up to the point that was hovered on to red
-
- // Get the child img id which holds some info we need.
- var child = $(this).children().attr('id');
-
- // Child contains the object_id and the star number.
- var object = child.split('_');
-
- // Set the red stars that we neeed to.
- for (i = 1; i <= object[1]; i++)
- {
- $('#' + object[0] + '_' + i).attr({src: red_star.src});
- }
- },
- function(){
- // Out function. Reset to default stars
- $("ul.rating li a img.green").each(function() {
- $(this).attr({src: green_star.src});
- });
-
- $("ul.rating li a img.orange").each(function() {
- $(this).attr({src: orange_star.src});
- });
-
- $("ul.rating li a img.grey").each(function() {
- $(this).attr({src: grey_star.src});
- });
- }
- );
- });
-
// ]]>
</script>
--- 50,55 ----
Modified: trunk/titania/styles/default/theme/common.css
==============================================================================
*** trunk/titania/styles/default/theme/common.css (original)
--- trunk/titania/styles/default/theme/common.css Fri Sep 4 17:51:12 2009
***************
*** 3,8 ****
--- 3,12 ----
* common.css
*/
+ .hidden {
+ display: none !important;
+ }
+
.successbox, .errorbox {
padding: 0 10px;
margin: 10px 0;
***************
*** 126,137 ****
.contrib-content {
background-color: #FFFFFF;
padding: 0 5px;
! }
h2.section-title {
! color: #425667;
! margin-top: .5em;
! text-align: center;
position: relative;
}
--- 130,141 ----
.contrib-content {
background-color: #FFFFFF;
padding: 0 5px;
! }
h2.section-title {
! color: #425667;
! margin-top: .5em;
! text-align: center;
position: relative;
}
***************
*** 163,169 ****
.advanced-search label {
display: block;
!
}
label#main {
--- 167,173 ----
.advanced-search label {
display: block;
!
}
label#main {
***************
*** 209,215 ****
#tabs .activetab a {
background-image: url("./images/tab_bg.gif");
! color: #FFFFFF;
border-color: #027BB8;
}
--- 213,219 ----
#tabs .activetab a {
background-image: url("./images/tab_bg.gif");
! color: #FFFFFF;
border-color: #027BB8;
}
***************
*** 241,247 ****
.half h3 {
margin: 0;
! color: #BC2A4D;
}
#left dl.details dt {
--- 245,251 ----
.half h3 {
margin: 0;
! color: #BC2A4D;
}
#left dl.details dt {
***************
*** 289,300 ****
.faq-list {
float: left;
background-color: #E4EDF1;
! border: 1px solid #B8CFDB;
margin-bottom: 5px;
padding: 0 5px;
font-size: 1.1em;
margin-top: 5px;
! display: block;
width: 98.25%; /* Need to look over this again - IE doesn't want to play nice */
}
--- 293,304 ----
.faq-list {
float: left;
background-color: #E4EDF1;
! border: 1px solid #B8CFDB;
margin-bottom: 5px;
padding: 0 5px;
font-size: 1.1em;
margin-top: 5px;
! display: block;
width: 98.25%; /* Need to look over this again - IE doesn't want to play nice */
}
***************
*** 335,341 ****
}
div#top {
! clear: both;
margin-top: 15px;
}
--- 339,345 ----
}
div#top {
! clear: both;
margin-top: 15px;
}
***************
*** 431,440 ****
}
/* Rating Code */
! ul.rating {
list-style-type: none;
display: inline;
}
! ul.rating li {
display: inline;
}
\ No newline at end of file
--- 435,444 ----
}
/* Rating Code */
! ul.rating, ul.rated {
list-style-type: none;
display: inline;
}
! ul.rating li, ul.rated li {
display: inline;
}
\ No newline at end of file
More information about the customisationdb-commits
mailing list