Click a star... but you'll first need to play a track!

 

Output goes here

 

  1. <script>
  2.  
  3. // NOTE: These areguments are the stadard set returned when using addMEL
  4. // obj - The button that was clicked
  5. // po - An object containing x/y position information for mouse and object.
  6. // args - Any argument that was established when setting up the addMEL.
  7. function setRating (obj, pos, args){
  8. // Get the current track info
  9. var trackData = player.getTrackDataset();
  10. var file = trackData.file;
  11. // Set up a variable to display what happened.
  12. var displayInfo;
  13. // If no file, then the user hasn't launch a track yet, so don't do rating.
  14. if(file){
  15. // Loop through our "stars" array and turn items on or off
  16. // based on the index sent in via the "args" argument.
  17. for(var i=0; i<5; i++){
  18. var elem = stars[i];
  19. if(i <= args){
  20. elem.setState(1);
  21. } else {
  22. elem.setState(0);
  23. }
  24. }
  25. // Note: "args" is a zero-based reference, so:
  26. // 0 = 1 star
  27. // 1 = 2 stars
  28. // 2 = 3 stars... etc.
  29. displayInfo = "User rated " + file + " with " + (args+1) + " stars.";
  30. } else {
  31. displayInfo = "No file has been played.";
  32. alert("You must play a track before you can rate!");
  33. }
  34. // This function is located in "_test_stuff.js" and prints stuff into page.
  35. showObject(displayInfo, "output", true, "Star Clicked");
  36. //alert(displayInfo);
  37.  
  38. }
  39.  
  40. function setRating2(id){
  41. alert(id);
  42. }
  43.  
  44. var stars = [];
  45. function getStars(){
  46.  
  47. for(var i=0; i<5; i++){
  48. // Get a handle to our star objects in the skin.
  49. var elem = player.getSkinElement("rate" + i);
  50. // Put the element into an array.
  51. stars.push(elem);
  52. // Skin elements have a built-in "addMEL" function,
  53. // (MEL stands for "Mouse Event Listener").
  54. //
  55. // The addMEL is set up with 5 arguments:
  56. //
  57. // addMEL(evt, func, scope, bubbles, arg)
  58. //
  59. // "evt" The event name and can be any of the following:
  60. // mouseDown
  61. // mouseUp
  62. // mouseClick
  63. // mouseOver
  64. // mouseMove mouse hovering over with movement
  65. // mouseDrag click down and dragging
  66. // mouseOut
  67. // "func" The function to call when triggered.
  68. // "scope" The scope that the "func" resides within.
  69. // "bubbles" A boolean that indicates if the mouse click should "fall through" to elements underneath it.
  70. // "arg" Available to incorporate custom data to include during an event trigger.
  71. //
  72. // Here we're setting up the MEL to ping the "setRating" function
  73. // we've defined above, and set the "arg" to the "i" index.
  74. elem.addMEL(
  75. "mouseDown", // The event to listen for.
  76. this.setRating, // The function we want to ping
  77. this, // the "setRating" is in the "window" scope, or "this" for short.
  78. false, // Don't bubble (not that important)
  79. i // the index of the element in our "stars" array.
  80. );
  81. // FYI:
  82. // You can also use traditional methods to apply mouse events.
  83. // To do so, you'll need to target the "element" property of the skin object.
  84. // However, it gets a little tricky doing it this way because you have to
  85. // store the "i" value somehow.
  86. //
  87. // Example:
  88. // elem.element.onclick = function(arg) {
  89. // setRating();
  90. // };
  91. }
  92. }
  93.  
  94. // Create a new player
  95. var player = new wimpyPlayer({
  96. skin : "../wimpy.skins/045_ratings.tsv",
  97. media : "../song1.mp3|../song2.mp3|../song3.mp3",
  98. onReady : getStars
  99. });
  100.  
  101.  
  102.  
  103.  
  104.  
  105. </script>
  106.  
  107.  
  108. Click a star... but you'll first need to play a track!
  109.  
  110.  
  111. <pre id="output">Output goes here<p></p>
  112.  
  113.  
  114.  
  115.  
  116.  
  117.  
  118.  
  119. </pre>
giItT1WQy@!-/#