This patch will make it possible to dynamically change the Fivestar label of "Your vote:" to either "Poor", "Okay", "Good", "Pretty Good", "Awesome" depending on which star is rolled over (i.e. 1 stars = "Poor" & 5 stars = "Awesome). These messages can be changed by hardcoding them into the jquery.rating.js file.

A demo screencast can be seen either here or here

This is achieved by adding three lines & changing one in the jquery.rating.js file.
A "node" attribute is added to the innerHTML link to each star in order to uniquely identify which label should get changed.
Two jQuery lines are needed to actually change the label message on the mouseover and mouseout.
And another line is added to declare the info_message array with the status messages.

NOTE Just discovered that this code only works when the "Five Star display style" is set to "Stars and Average." And when the display style is set to "Two sets of stars," then it changes both of the labels of "Your vote:" and "Current rating." Looking into this, but I figured that I would post what I have so far to get some preliminary feedback.

Comments

KentBye’s picture

StatusFileSize
new1.74 KB

I fixed the previous bug in the "Two sets of stars" setting with a ":first" jQuery CSS selector to isolate the first label from the Current rating label. Now it currently works in Firefox.

However, the label completely disappears in Safari as shown in this video.

Not sure if it is because I'm emptying out the label first and then doing a prepend with this line: $('#fivestar-form-node-'+$(this.innerHTML).attr("node")+' label:first').empty().prepend(info_msg[this.textContent/20]);

KentBye’s picture

It turns out that "this.textContent" provides the rating value of the star (i.e. 100, 80, 60, 40 or 20) in Firefox.
But for whatever reason it is undefined in Safari, and therefore returning a NaN value when trying to divide by 20.
FYI: The info_message array contains the rollover message values as well as the default "Your vote:", which is the info_message[0] value. The other values are from 1-5 so that dividing by 20 could calculate the position in the array.

I'm going to try and figure out how to get the vote value to register in Safari now.

KentBye’s picture

Status: Needs work » Needs review
StatusFileSize
new1.76 KB

I fixed the Safari error by replacing "this.textContent" with a less elegant, but working "this.firstChild.firstChild.nodeValue"
I used Firebug's debugger to search through the elements for the actual vote value (i.e. 20, 40, 60, 80 or 100).
This value was located in a number of other places, and I'm not sure if there is a more intuitive path.
I also have no idea why this.textContent worked in Firefox and not Safari, but it works now with this jQuery line:
$('#fivestar-form-node-'+$(this.innerHTML).attr("node")+' label:first').empty().prepend(info_msg[this.firstChild.firstChild.nodeValue/20]);

This hasn't been tested this in IE yet.

KentBye’s picture

Status: Needs review » Needs work

This patch is compatible with fivestar.module version 1.2.2.6, but not when using than five stars in version 1.2.2.7.

Currently working this functionality into a larger patch with the ability to set the status messages on an admin page.

quicksketch’s picture

Yeah sorry I totally broke your implementation by making more (or less) than 5 stars. You'd need to write some clever code that provides several options (like 10) or make it configurable.

quicksketch’s picture

Marked http://drupal.org/node/182174 as duplicate

KentBye’s picture

Version: 5.x-1.4 » 5.x-1.x-dev

Okay, I'm going to take another look at this to see if I can get something together for a 1.9 release.
Last I remember, there was an official 1.5 release made with major changes in the midst of development which deprecated the patch.
Part of the problem as I remember it was creating a dynamic admin form that would have as many fields with default values as there were number of stars.
I'm taking a look at this issue as well.

KentBye’s picture

UPDATE: Either the DRUPAL-5 branch of fivestar is broken or I've incorrectly checked it out.
I'm using: cvs -z6 -d:pserver:anonymous:anonymous@cvs.drupal.org:/cvs/drupal checkout -r DRUPAL-5 -d fivestar contributions/modules/fivestar

Version 1.2.2.35 of fivestar.module won't let me "Enable Fivestar rating" on any content type.

So I'm going back to the 1.8 release.

quicksketch’s picture

Hey Kent, I'd really encourage you to try to develop against the 5.x development branch, as it's seen drastic changes since 1.8 and patches probably won't apply easily. Could you describe the problem of not being able to enable Fivestar for a particular content type?

KentBye’s picture

Sorry, I should have posted that I did decide to defer until I heard back from you.
Yes, I did notice a lot of changes, but I was working on some UI feedback and suggestions for the Direct rating widge here: http://drupal.org/node/192927

So I'm using the CVS command as described above, and then when I try to click the "Enable Fivestar rating" checkbox and save it, then it doesn't save it at all. I had tried this on a site that originally had fivestar 1.7 installed, and so I tried update.php -- and that didn't work.

And then I created a fresh install of Drupal 5.3 and installed the latest dev versions of VotingAPI and Fivestar, but haven't been able to enable it at all.

Will try the latest official VotingAPI release to see if that helps.

KentBye’s picture

Status update...

I got the latest dev of fivestar working after discovering this weird js bug on Firefox.

I've also got the mouseover text working again and am in the process of making changes to the fivestar_form_alter to allow the user to customize the rollover text for each content type. The rollover text options will be passed into the javascript for each node type that has fivestar enabled.

KentBye’s picture

Status: Needs work » Active

Changing the status to back to active until I have an updated patch...

KentBye’s picture

Status: Active » Needs work
StatusFileSize
new12.33 KB

This patch is about 80% the way there, and I just wanted to post my progress on it.
I have mouseover texts working for each content type.
You can now specify the mouseover texts while editing the content form -- Ideally there would be a "Save and Continue" button ala views because the form needs to get rebuild and I added some bolded warnings trying to indicate this.
This will probably be solved with some AHAH magic in the 6.x version.

I also have to loop through all of the content types in fivestar_init() to pass the mouseover texts to javascript -- as well as to determine whether or not the content has mouseover text enabled or not.
One consideration is whether or not to add a global mouseover text flag in this section so that this section of code could be bypassed if need be -- especially on a site with a lot of node types.

I had to add some code to pass the node number and content type so that it would be more available to jQuery.

I'm now going to dive into overridding the "Your Vote:" "Average" or no text since at the moment it incorrectly statically defaults back to "Your Vote:" on mouseout. Going to add some dynamic logic based up on the 'fivestar_style_'. $node->type

KentBye’s picture

I threw together a demo video here on the progress so far:
http://blip.tv/file/get/Kentbye_tech-Fivestar_Mouseover_text_Demo_v1_276...

KentBye’s picture

Just talked w/ Quicksketch in IRC and he had a couple of suggstions:

* i think placing the mouseover text in the description text is more common
* i'd suggest hiding the content rather than replacing it anyway, it'll make things easier for you

One issue with placing the mouseover text in the description is that the star heights maybe too small and the mouse cursor may get it in the way. I will explore it, and may have a way to have both as an option.

KentBye’s picture

Status: Needs work » Needs review
StatusFileSize
new12.19 KB

Finally got a chance to clean this up a bit after the holidays.
Now hides content instead of emptying it.

A couple of unanswered TODOs
One in the fivestar_init():
"Possibly add in a global admin variable determining if MouseOver is enabled or not due to performance considerations when there are a lot of content types"
I'm not sure if there needs to be a global admin option to turn off and on the mouseover texts.
Take a look at the init code and see what you think.

Also, in the fivestar_admin_settings(), the mouseover texts depend on the number of stars.
And so at the moment, I have a lengthy explanation detailing the steps for properly initializing the mouseover text fields.
What would be ideal would be if there was a "Save and Continue" button ala views to be able to regenerate the form, but the explanation will have to do absent that extra button.
But the pending TODO is to a question of "Should there be additional jQuery checks or form validation if the number of stars changes for UI streamlining?"
Not sure the best way to handle that.

Other than that, I think the major functionality of mouseover texts is in the patch.
Although, there is a slight space that is added to the div when mouseover texts are rolled over, which may need to be addressed either with CSS or re-positioning the div.

quicksketch’s picture

Status: Needs review » Needs work

Okay I took a look at this today and this is going to need a bit of work yet.

- On rollover of stars on the content type form, I get javascript errors "ret[ret.length - 1] has no properties". I don't actually see any change in message with or without a custom message set.

- The process for enabling descriptions is much too tedious. We should render all the choices on page load, then hide them with javascript if it's disabled. If enabled we can just hide the appropriate number. They should update as you change number of stars. No help text should be necessary.

- The strings in $default_mouseover_text should all be wrapped in t() functions.

- t() function calls containing dynamic text like this one: t($star_count.'-Star Rating Description') should be t('@count-Star Rating Description', array('@count' => $star_count)). See t() documentation.

- The description text should also be used as the title for the link. I'd love to get rid of the Give it ' + count hard-coded into the titles and use this dynamic value instead. That way we could close requests to make that string translatable also.

- I wouldn't add javascript in fivestar_init(). Rather you should add javascript in the theme function expand_fivestar() and only load the variables necessary for that node type. Make an additional property to the fivestar element for #labels. So you could add messages like this:

  $form['vote'] = array(
    '#type' => 'fivestar',
    '#stars' => 5,
    '#auto_submit' => FALSE,
    '#allow_clear' => TRUE,
    '#labels' => array(t('Bad'), t('Poor'), t('Average'), t('Good'), t('Great')),
  );

fivestar_expand will take those labels and add them to each star. This would be an excellent place to make #labels default to something like t('Give it @star/@count') as the default and remove that hard coded line in the javascript file.

That's probably enough to chew on. Thanks for undertaking this effort, it's no small feature!

KentBye’s picture

Thanks for all of the detailed feedback.
(Too bad that it's throwing that error to not even see it in action.)

I'm on the road at the moment, which is bad timing, but I want to take a look at these suggestions next week and get out another iteration -- hopefully before the official 1.9 release goes out.

And it looks like you've had a spring cleaning of other pending fivestar issues after the Drupal 6 usability sprint.
Thanks.

KentBye’s picture

Thanks for all of the detailed feedback.
(Too bad that it's throwing that error to not even see it in action.)

I'm on the road at the moment, which is bad timing, but I want to take a look at these suggestions next week and get out another iteration -- hopefully before the official 1.9 release goes out.

And it looks like you've had a spring cleaning of other pending fivestar issues after the Drupal 6 usability sprint.
Thanks.

KentBye’s picture

A brief update and one question down below....

I've been traveling around a lot, and just had a bit of time to take a preliminary look at the code and suggested changes.

One thing that I need to figure out is to see if the absolute star number is already available through the DOM.
At the moment, I'm using the vote value (i.e. "25" for 1/4)

And since the vote value was more readily available than the star number, then I had originally indexed the mouseover texts by the star value:
$star_value = ceil((100/$fivestar_star_number) * $star_count);
variable_get('fivestar_mouseover_text_'. $star_value .'_'. $type->type, $default_mouseover_text[$star_value]),

But if it's better to display all of the form values and then hide them, then I'm going to have to use the star number as an index instead.

I had originally got the star value on hover by setting a break point in FireBug and digging around until I found the vote value here:
this.firstChild.firstChild.nodeValue

But I can't figure out how to get the existing node->nid from the hover.
When I do a console.log(this) in Firebug, I get:
<div class="star star-1 star-odd">
-- which has the absolute star number in the second class.

QUESTION: Do you know offhand if there is a jQuery way of grabbing that star number?
As an aside, on a quick inspection of the js and css, I didn't see anything that is actually using this star-1 class.

The node->nid is also passed in through a hidden form value, but it will only grab the first widget value when I do:
$('input#edit-content-id').attr("value")

$('input#edit-content-id') wiil display all of them on the page, but I would need the preceding one relative to whatever is being hovered.

The star number is also available as the text in the radio when the js is disabled, but it'd be nice not to use this and replace it with the mouseover texts as well:
<input type="radio" name="vote" value="25" class="form-radio" /> 1</label>

What I may end up doing is placing an additional attribute for the star number here if there isn't another way to get it now:

<div class="star star-1 star-odd">
   <a title="Give it 1/4" href="#25" style="width: 100%;">25</a>
</div>
KentBye’s picture

Err. nevermind that previous question.
The alternative could be to change the -/a title\- to the array you specified, and it may be accessible from there...
I'll try that first before grabbing the star number...

KentBye’s picture

Status: Needs work » Needs review
StatusFileSize
new6.06 KB

This is a barebones work-in-progress patch for the star description admin form with degradable javascript.
I now that you're in active development, and so I wanted to get this to you for some feedback before the latest changes hit CVS -- specifically some UI feedback on this because there are some things in here that could become the default link titles & radio descriptions.
At the moment the link titles are hard-coded in js, and the radio descriptions are just numbers, but could potentially become these star descriptions as well.

I'm having trouble fully testing this because I can't submit forms with javascript enabled.
But when you change the star number, then it reveals the correct number of textfields, and changes the text value to properly read "Give it 1/3, 2/3, 3/3, etc..."

And because 4/3 doesn't ever make sense, it defaults to "Rate it 4 stars" if javascript is disabled.
If javascript is enabled, then switching to 4 changes it to 1/4, 2/4, 3/4, 4/4, etc.

This patch has these caveats:
It's just the admin so far.
No translation t() changes yet.
The admin.js file is using the constructor from nodePreview -- it probably needs it's own namespaced functions, but I had a bit of trouble and wanted to get a working copy out to you since I'm on the road still.

Give it a look when you have a chance.
Thanks.

quicksketch’s picture

StatusFileSize
new6.96 KB

Hey Kent, I took a look at the last patch here and I think it's the direction we want to be heading. To simplify the entire process of getting the rollover titles, I've switched the HTML version of the widget from radio buttons to a select list. This way it takes up a smaller amount of space before the javascript version is rendered. This is currently in the latest 5.x branch of fivestar.

So I took the patch in #22 and wired it up to use the new system, and the titles on the stars are now actually using the settings from the content type page. Because this text is used for more than just mouseover text, I changed the name from "mouseover_text" in code to "labels". The updating of the description text is not yet in place.

KentBye’s picture

Hey quicksketch.
Thanks for taking a look at this, and sorry I couldn't do more while traveling (and getting a bit sick to boot)

Anyway, I'll take a look at these changes and work with the latest dev from there.
I agree that a more general "labels" would be better than mouseover, and I'll try to clean up other instances

And yes and select list works much better since long descriptions makes it a bit unreadable and unusable with radios.

Taking a look at it now...

quicksketch’s picture

I committed a large chunk of code to 5.x dev that gets us really close to completion on this. The rollovers are now working, as is the admin interface for updating the labels and having the preview reflect it. The one thing that is missing however is actually *turning it off*. The checkbox for enabling this functionality is ignored by the preview. Additional help text needs to be added also that @star and @count are basically tokens that can be used.

quicksketch’s picture

Status: Needs review » Fixed

I finished up this request today. Kent, I'd love if you can try out the latest CVS and we can open new tickets for further enhancements. Thanks!

KentBye’s picture

Great!
Testing it out now.

-Kent.

Anonymous’s picture

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for two weeks with no activity.

asb’s picture

Hi,

the current D5 release of the "Fivestar Star" seems to support Dynamic Descriptions on Mouseover based on this patch; however, I could not find the referenced jquery.rating.js file in the tarball; also I noticed, that the strings for a ten-star-rating seem to be missing in the .po files. Which precedures apply to modify resp. translate those mouseover descriptions?

Thank you, -asb