only1wizard
asked on
5 star resize and animated processing resize
hello im trying to resize this 5 star image to:
width pixels = 13
height pixels = 39
the application works i just want to resize the stars and cannot get it to resize properly.
thanks in advance for your help!
here is the code for the application:
rating.css
default.css
rating.js
behavior.js
_drawrating.php
test.php
_config-rating.php
database table
can you also rezize the animated working.gif or re make it and provide me with the original photoshop/flash file?
working.gif
width pixels = 13
height pixels = 39
the application works i just want to resize the stars and cannot get it to resize properly.
thanks in advance for your help!
here is the code for the application:
rating.css
.ratingblock {
display:block;
border-bottom:1px solid #999;
padding-bottom:8px;
margin-bottom:8px;
}
.loading {
height: 30px;
background: url('../images/working.gif') 50% 50% no-repeat;
}
.unit-rating { /* the UL */
list-style:none;
margin: 0px;
padding:0px;
height: 30px;
position: relative;
background: url('../images/starrating.gif') top left repeat-x;
}
.unit-rating li{
text-indent: -90000px;
padding:0px;
margin:0px;
/*\*/
float: left;
/* */
}
.unit-rating li a {
outline: none;
display:block;
width:30px;
height: 30px;
text-decoration: none;
text-indent: -9000px;
z-index: 20;
position: absolute;
padding: 0px;
}
.unit-rating li a:hover{
background: url('../images/starrating.gif') left center;
z-index: 2;
left: 0px;
}
.unit-rating a.r1-unit{left: 0px;}
.unit-rating a.r1-unit:hover{width:30px;}
.unit-rating a.r2-unit{left:30px;}
.unit-rating a.r2-unit:hover{width: 60px;}
.unit-rating a.r3-unit{left: 60px;}
.unit-rating a.r3-unit:hover{width: 90px;}
.unit-rating a.r4-unit{left: 90px;}
.unit-rating a.r4-unit:hover{width: 120px;}
.unit-rating a.r5-unit{left: 120px;}
.unit-rating a.r5-unit:hover{width: 150px;}
.unit-rating a.r6-unit{left: 150px;}
.unit-rating a.r6-unit:hover{width: 180px;}
.unit-rating a.r7-unit{left: 180px;}
.unit-rating a.r7-unit:hover{width: 210px;}
.unit-rating a.r8-unit{left: 210px;}
.unit-rating a.r8-unit:hover{width: 240px;}
.unit-rating a.r9-unit{left: 240px;}
.unit-rating a.r9-unit:hover{width: 270px;}
.unit-rating a.r10-unit{left: 270px;}
.unit-rating a.r10-unit:hover{width: 300px;}
.unit-rating li.current-rating {
background: url('../images/starrating.gif') left bottom;
position: absolute;
height: 30px;
display: block;
text-indent: -9000px;
z-index: 1;
}
.voted {color:#999;}
.thanks {color:#36AA3D;}
.static {color:#5D3126;}
default.css
body {
background-color: #fff;
font-family: Verdana, Arial, Helvetica, sans-serif;
font-size:11px;
margin: 0;
padding: 20px 0 20px 40px;
color: #000;
}
#container {
width: 50%;
border: 1px solid #ccc;
padding: 20px;
}
h1 {
font-size: 21px;
font-family: Arial, sans-serif;
margin:0 0 5px 0;
padding:0;
}
h2 {
font-size: 16px;
color: #333;
font-family: Arial, sans-serif;
margin:0 0 10px 0;
padding:0;
}
p {
margin:3px;
padding:0;
}
rating.js
var xmlhttp
/*@cc_on @*/
/*@if (@_jscript_version >= 5)
try {
xmlhttp=new ActiveXObject("Msxml2.XMLHTTP")
} catch (e) {
try {
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP")
} catch (E) {
xmlhttp=false
}
}
@else
xmlhttp=false
@end @*/
if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
try {
xmlhttp = new XMLHttpRequest();
} catch (e) {
xmlhttp=false
}
}
function myXMLHttpRequest() {
var xmlhttplocal;
try {
xmlhttplocal= new ActiveXObject("Msxml2.XMLHTTP")
} catch (e) {
try {
xmlhttplocal= new ActiveXObject("Microsoft.XMLHTTP")
} catch (E) {
xmlhttplocal=false;
}
}
if (!xmlhttplocal && typeof XMLHttpRequest!='undefined') {
try {
var xmlhttplocal = new XMLHttpRequest();
} catch (e) {
var xmlhttplocal=false;
alert('couldn\'t create xmlhttp object');
}
}
return(xmlhttplocal);
}
function sndReq(vote,id_num,ip_num,units) {
var theUL = document.getElementById('unit_ul'+id_num); // the UL
// switch UL with a loading div
theUL.innerHTML = '<div class="loading"></div>';
xmlhttp.open('get', 'rpc.php?j='+vote+'&q='+id_num+'&t='+ip_num+'&c='+units);
xmlhttp.onreadystatechange = handleResponse;
xmlhttp.send(null);
}
function handleResponse() {
if(xmlhttp.readyState == 4){
if (xmlhttp.status == 200){
var response = xmlhttp.responseText;
var update = new Array();
if(response.indexOf('|') != -1) {
update = response.split('|');
changeText(update[0], update[1]);
}
}
}
}
function changeText( div2show, text ) {
// Detect Browser
var IE = (document.all) ? 1 : 0;
var DOM = 0;
if (parseInt(navigator.appVersion) >=5) {DOM=1};
// Grab the content from the requested "div" and show it in the "container"
if (DOM) {
var viewer = document.getElementById(div2show);
viewer.innerHTML = text;
} else if(IE) {
document.all[div2show].innerHTML = text;
}
}
/* =============================================================== */
var ratingAction = {
'a.rater' : function(element){
element.onclick = function(){
var parameterString = this.href.replace(/.*\?(.*)/, "$1"); // onclick="sndReq('j=1&q=2&t=127.0.0.1&c=5');
var parameterTokens = parameterString.split("&"); // onclick="sndReq('j=1,q=2,t=127.0.0.1,c=5');
var parameterList = new Array();
for (j = 0; j < parameterTokens.length; j++) {
var parameterName = parameterTokens[j].replace(/(.*)=.*/, "$1"); // j
var parameterValue = parameterTokens[j].replace(/.*=(.*)/, "$1"); // 1
parameterList[parameterName] = parameterValue;
}
var theratingID = parameterList['q'];
var theVote = parameterList['j'];
var theuserIP = parameterList['t'];
var theunits = parameterList['c'];
//for testing alert('sndReq('+theVote+','+theratingID+','+theuserIP+','+theunits+')'); return false;
sndReq(theVote,theratingID,theuserIP,theunits); return false;
}
}
};
Behaviour.register(ratingAction);
behavior.js
/*
Description:
Uses css selectors to apply javascript behaviours to enable
unobtrusive javascript in html documents.
Usage:
var myrules = {
'b.someclass' : function(element){
element.onclick = function(){
alert(this.innerHTML);
}
},
'#someid u' : function(element){
element.onmouseover = function(){
this.innerHTML = "BLAH!";
}
}
};
Behaviour.register(myrules);
// Call Behaviour.apply() to re-apply the rules (if you
// update the dom, etc).
*/
var Behaviour = {
list : new Array,
register : function(sheet){
Behaviour.list.push(sheet);
},
start : function(){
Behaviour.addLoadEvent(function(){
Behaviour.apply();
});
},
apply : function(){
for (h=0;sheet=Behaviour.list[h];h++){
for (selector in sheet){
list = document.getElementsBySelector(selector);
if (!list){
continue;
}
for (i=0;element=list[i];i++){
sheet[selector](element);
}
}
}
},
addLoadEvent : function(func){
var oldonload = window.onload;
if (typeof window.onload != 'function') {
window.onload = func;
} else {
window.onload = function() {
oldonload();
func();
}
}
}
}
Behaviour.start();
/*
document.getElementsBySelector(selector)
- returns an array of element objects from the current document
matching the CSS selector. Selectors can contain element names,
class names and ids and can be nested. For example:
elements = document.getElementsBySelect('div#main p a.external')
Will return an array of all 'a' elements with 'external' in their
class attribute that are contained inside 'p' elements that are
contained inside the 'div' element which has id="main"
See http://www.w3.org/TR/css3-selectors/#attribute-selectors
*/
function getAllChildren(e) {
// Returns all children of element. Workaround required for IE5/Windows. Ugh.
return e.all ? e.all : e.getElementsByTagName('*');
}
document.getElementsBySelector = function(selector) {
// Attempt to fail gracefully in lesser browsers
if (!document.getElementsByTagName) {
return new Array();
}
// Split selector in to tokens
var tokens = selector.split(' ');
var currentContext = new Array(document);
for (var i = 0; i < tokens.length; i++) {
token = tokens[i].replace(/^\s+/,'').replace(/\s+$/,'');;
if (token.indexOf('#') > -1) {
// Token is an ID selector
var bits = token.split('#');
var tagName = bits[0];
var id = bits[1];
var element = document.getElementById(id);
if (tagName && element.nodeName.toLowerCase() != tagName) {
// tag with that ID not found, return false
return new Array();
}
// Set currentContext to contain just this element
currentContext = new Array(element);
continue; // Skip to next token
}
if (token.indexOf('.') > -1) {
// Token contains a class selector
var bits = token.split('.');
var tagName = bits[0];
var className = bits[1];
if (!tagName) {
tagName = '*';
}
// Get elements matching tag, filter them for class selector
var found = new Array;
var foundCount = 0;
for (var h = 0; h < currentContext.length; h++) {
var elements;
if (tagName == '*') {
elements = getAllChildren(currentContext[h]);
} else {
elements = currentContext[h].getElementsByTagName(tagName);
}
for (var j = 0; j < elements.length; j++) {
found[foundCount++] = elements[j];
}
}
currentContext = new Array;
var currentContextIndex = 0;
for (var k = 0; k < found.length; k++) {
if (found[k].className && found[k].className.match(new RegExp('\\b'+className+'\\b'))) {
currentContext[currentContextIndex++] = found[k];
}
}
continue; // Skip to next token
}
// Code to deal with attribute selectors
if (token.match(/^(\w*)\[(\w+)([=~\|\^\$\*]?)=?"?([^\]"]*)"?\]$/)) {
var tagName = RegExp.$1;
var attrName = RegExp.$2;
var attrOperator = RegExp.$3;
var attrValue = RegExp.$4;
if (!tagName) {
tagName = '*';
}
// Grab all of the tagName elements within current context
var found = new Array;
var foundCount = 0;
for (var h = 0; h < currentContext.length; h++) {
var elements;
if (tagName == '*') {
elements = getAllChildren(currentContext[h]);
} else {
elements = currentContext[h].getElementsByTagName(tagName);
}
for (var j = 0; j < elements.length; j++) {
found[foundCount++] = elements[j];
}
}
currentContext = new Array;
var currentContextIndex = 0;
var checkFunction; // This function will be used to filter the elements
switch (attrOperator) {
case '=': // Equality
checkFunction = function(e) { return (e.getAttribute(attrName) == attrValue); };
break;
case '~': // Match one of space seperated words
checkFunction = function(e) { return (e.getAttribute(attrName).match(new RegExp('\\b'+attrValue+'\\b'))); };
break;
case '|': // Match start with value followed by optional hyphen
checkFunction = function(e) { return (e.getAttribute(attrName).match(new RegExp('^'+attrValue+'-?'))); };
break;
case '^': // Match starts with value
checkFunction = function(e) { return (e.getAttribute(attrName).indexOf(attrValue) == 0); };
break;
case '$': // Match ends with value - fails with "Warning" in Opera 7
checkFunction = function(e) { return (e.getAttribute(attrName).lastIndexOf(attrValue) == e.getAttribute(attrName).length - attrValue.length); };
break;
case '*': // Match ends with value
checkFunction = function(e) { return (e.getAttribute(attrName).indexOf(attrValue) > -1); };
break;
default :
// Just test for existence of attribute
checkFunction = function(e) { return e.getAttribute(attrName); };
}
currentContext = new Array;
var currentContextIndex = 0;
for (var k = 0; k < found.length; k++) {
if (checkFunction(found[k])) {
currentContext[currentContextIndex++] = found[k];
}
}
// alert('Attribute Selector: '+tagName+' '+attrName+' '+attrOperator+' '+attrValue);
continue; // Skip to next token
}
if (!currentContext[0]){
return;
}
// If we get here, token is JUST an element (not a class or ID selector)
tagName = token;
var found = new Array;
var foundCount = 0;
for (var h = 0; h < currentContext.length; h++) {
var elements = currentContext[h].getElementsByTagName(tagName);
for (var j = 0; j < elements.length; j++) {
found[foundCount++] = elements[j];
}
}
currentContext = found;
}
return currentContext;
}
/* That revolting regular expression explained
/^(\w+)\[(\w+)([=~\|\^\$\*]?)=?"?([^\]"]*)"?\]$/
\---/ \---/\-------------/ \-------/
| | | |
| | | The value
| | ~,|,^,$,* or =
| Attribute
Tag
*/
_drawrating.php
<?php
function rating_bar($id,$units='',$static='') {
require('_config-rating.php'); // get the db connection info
//set some variables
$ip = $_SERVER['REMOTE_ADDR'];
if (!$units) {$units = 10;}
if (!$static) {$static = FALSE;}
// get votes, values, ips for the current rating bar
$query=mysql_query("SELECT total_votes, total_value, used_ips FROM $rating_dbname.$rating_tableName WHERE id='$id' ")or die(" Error: ".mysql_error());
// insert the id in the DB if it doesn't exist already
if (mysql_num_rows($query) == 0) {
$sql = "INSERT INTO $rating_dbname.$rating_tableName (`id`,`total_votes`, `total_value`, `used_ips`) VALUES ('$id', '0', '0', '')";
$result = mysql_query($sql);
}
$numbers=mysql_fetch_assoc($query);
if ($numbers['total_votes'] < 1) {
$count = 0;
} else {
$count=$numbers['total_votes']; //how many votes total
}
$current_rating=$numbers['total_value']; //total number of rating added together and stored
$tense=($count==1) ? "vote" : "votes"; //plural form votes/vote
// determine whether the user has voted, so we know how to draw the ul/li
$voted=mysql_num_rows(mysql_query("SELECT used_ips FROM $rating_dbname.$rating_tableName WHERE used_ips LIKE '%".$ip."%' AND id='".$id."' "));
// now draw the rating bar
$rating_width = @number_format($current_rating/$count,2)*$rating_unitwidth;
$rating1 = @number_format($current_rating/$count,1);
$rating2 = @number_format($current_rating/$count,2);
if ($static == 'static') {
$static_rater = array();
$static_rater[] .= "\n".'<div class="ratingblock">';
$static_rater[] .= '<div id="unit_long'.$id.'">';
$static_rater[] .= '<ul id="unit_ul'.$id.'" class="unit-rating" style="width:'.$rating_unitwidth*$units.'px;">';
$static_rater[] .= '<li class="current-rating" style="width:'.$rating_width.'px;">Currently '.$rating2.'/'.$units.'</li>';
$static_rater[] .= '</ul>';
$static_rater[] .= '<p class="static">'.$id.'. Rating: <strong> '.$rating1.'</strong>/'.$units.' ('.$count.' '.$tense.' cast) <em>This is \'static\'.</em></p>';
$static_rater[] .= '</div>';
$static_rater[] .= '</div>'."\n\n";
return join("\n", $static_rater);
} else {
$rater ='';
$rater.='<div class="ratingblock">';
$rater.='<div id="unit_long'.$id.'">';
$rater.=' <ul id="unit_ul'.$id.'" class="unit-rating" style="width:'.$rating_unitwidth*$units.'px;">';
$rater.=' <li class="current-rating" style="width:'.$rating_width.'px;">Currently '.$rating2.'/'.$units.'</li>';
for ($ncount = 1; $ncount <= $units; $ncount++) { // loop from 1 to the number of units
if(!$voted) { // if the user hasn't yet voted, draw the voting stars
$rater.='<li><a href="db.php?j='.$ncount.'&q='.$id.'&t='.$ip.'&c='.$units.'" title="'.$ncount.' out of '.$units.'" class="r'.$ncount.'-unit rater" rel="nofollow">'.$ncount.'</a></li>';
}
}
$ncount=0; // resets the count
$rater.=' </ul>';
$rater.=' <p';
if($voted){ $rater.=' class="voted"'; }
$rater.='>'.$id.' Rating: <strong> '.$rating1.'</strong>/'.$units.' ('.$count.' '.$tense.' cast)';
$rater.=' </p>';
$rater.='</div>';
$rater.='</div>';
return $rater;
}
}
?>
test.php
<?php require('_drawrating.php'); ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html lang="en" xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8">
<title>Ajax Star Rating</title>
<script type="text/javascript" language="javascript" src="js/behavior.js"></script>
<script type="text/javascript" language="javascript" src="js/rating.js"></script>
<link rel="stylesheet" type="text/css" href="css/default.css" />
<link rel="stylesheet" type="text/css" href="css/rating.css" />
</head>
<body>
<center>
<?php echo rating_bar('new','5'); ?>
<?php echo rating_bar('new2','10'); ?>
</center>
</body>
</html>
_config-rating.php
<?php
//Connect to your rating database
$rating_dbhost = 'localhost';
$rating_dbuser = 'root';
$rating_dbpass = '';
$rating_dbname = 'rate';
$rating_tableName = 'ratings';
$rating_path_db = ''; // the path to your db.php file (not used yet!)
$rating_path_rpc = ''; // the path to your rpc.php file (not used yet!)
$rating_unitwidth = 30; // the width (in pixels) of each rating unit (star, etc.)
// if you changed your graphic to be 50 pixels wide, you should change the value above
$rating_conn = mysql_connect($rating_dbhost, $rating_dbuser, $rating_dbpass) or die ('Error connecting to mysql');
//mysql_select_db($rating_dbname);
?>
database table
Field Type
id varchar(11)
total_votes int(11)
total_value int(11)
used_ips longtext
can you also rezize the animated working.gif or re make it and provide me with the original photoshop/flash file?
working.gif
ASKER
ive tried that the height is not the same for the image the way i have the image designed is opposite of the height and width of the css so im trying to configure the css to accomidate the changes so i have some tunning to do.
ASKER
and need help tunning it!
ASKER
and i have resized the image 5 star rating.gif to 13h * 50w
how ever the application is not working now!
how ever the application is not working now!
I'm not sure I understand the question, but I can give you a resized star image.
3stars.png
3stars.png
ASKER
ok what im trying to do is this. take image from 30 pixels width and 90 pixels height and converting it to 13 width and 50 height.
i will put a working copy of the original and the change so you can see what im talking about please give me a couple minutes. i will post the url links once completed.
thanks in advance for your help!
i will put a working copy of the original and the change so you can see what im talking about please give me a couple minutes. i will post the url links once completed.
thanks in advance for your help!
ASKER
here is the link to the original star rating system.
http://Only1Wizard.com/starrating/test.php
and here is the size i want to get it to:
http://only1Wizard.com/starrating/test0.php
and i can not get the code to work and it will not highlight all 5 stars as it does in the original test.php
thanks in advance for your help!
http://Only1Wizard.com/starrating/test.php
and here is the size i want to get it to:
http://only1Wizard.com/starrating/test0.php
and i can not get the code to work and it will not highlight all 5 stars as it does in the original test.php
thanks in advance for your help!
ASKER
ok resize let me elaborate on this:
1. resize the image to a small size from
original image http://Only1Wizard.com/starrating/test.php
to
new image http://Only1Wizard.com/starrating/test0.php
2. edit code to reflect the new image size
I dont know where to start besides css and when i have tried to edit it it just doesnt cover the complete image any more like the original image.
@ray its more to it then just resizing the picture, sorry should of explained it better.
1. resize the image to a small size from
original image http://Only1Wizard.com/starrating/test.php
to
new image http://Only1Wizard.com/starrating/test0.php
2. edit code to reflect the new image size
I dont know where to start besides css and when i have tried to edit it it just doesnt cover the complete image any more like the original image.
@ray its more to it then just resizing the picture, sorry should of explained it better.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
ive tried this but its just looping through the loading image, any suggestions? thanks in advance for your help the 5 star was highlighted now just need to get it to work.
Thanks in advance for your help!
Thanks in advance for your help!
ASKER
ok testing results if you look at the image attached youll see that it outputs more then needed after it updates the dataset with the voting count.
thanks again in advance for your help!
Screen-shot-2011-12-30-at-5.12.0.png
thanks again in advance for your help!
Screen-shot-2011-12-30-at-5.12.0.png
Might be related to this:
<ul class="unit-rating" style="width:150px;">
I think the width you want is probably 65px
<ul class="unit-rating" style="width:150px;">
I think the width you want is probably 65px
ASKER
where did you get that code from because im not seeing 150px anywhere in code?
ASKER
also how can i query this to show the default count with in the stars image layout?
thanks in advance for your help!
thanks in advance for your help!
I found the width attribute via "view source" on http://only1wizard.com/starrating/test0.php
The other part sounds like a completely different question so I will sign off on this part for now. Happiest of New Years, ~Ray
The other part sounds like a completely different question so I will sign off on this part for now. Happiest of New Years, ~Ray
ASKER
@ray thank you for your help will close this question and open another question like it in regards to new question. Happy New Years!
ASKER
thank you
And then in the css files where the starrating image is used set height to 39px.