not really known
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

72 lines
1.6 KiB

  1. // Card component with image, text and sound
  2. enyo.kind({
  3. name: "FoodChain.Card",
  4. kind: enyo.Control,
  5. published: { cardname: "", x: 0, y: 0, z: 0 },
  6. classes: "card",
  7. components: [
  8. { name: "itemImage", classes: "cardImage", kind: "Image" },
  9. { kind: "Image", src: "images/sound_icon.png", classes: "cardSoundIcon" },
  10. { name: "itemText", classes: "cardText" }
  11. ],
  12. // Constructor
  13. create: function() {
  14. this.inherited(arguments);
  15. this.cardnameChanged();
  16. this.xChanged();
  17. this.yChanged();
  18. this.zChanged();
  19. },
  20. // Rendering
  21. rendered: function() {
  22. this.inherited(arguments);
  23. },
  24. // Localization changed, update card
  25. setLocale: function() {
  26. this.cardnameChanged();
  27. this.render();
  28. },
  29. // Card setup
  30. cardnameChanged: function() {
  31. var image = FoodChain.context.home.getDatabase()+"images/cards/"+this.cardname+".png";
  32. var text = __$FC(this.cardname);
  33. this.sound = FoodChain.context.home.getDatabase()+"audio/"+__$FC("sounddir")+"/cards/"+this.cardname;
  34. this.$.itemImage.setAttribute("src", image);
  35. this.$.itemText.setContent(text);
  36. },
  37. // Coordinate setup
  38. xChanged: function() {
  39. if (this.x.toString().indexOf("%") != -1)
  40. this.applyStyle("margin-left", this.x);
  41. else
  42. this.applyStyle("margin-left", this.x+"px");
  43. },
  44. // Coordinate setup
  45. yChanged: function() {
  46. this.applyStyle("margin-top", this.y+"px");
  47. },
  48. // Coordinate setup
  49. zChanged: function() {
  50. this.applyStyle("z-index", this.z);
  51. },
  52. // Play sound using the media
  53. play: function(media) {
  54. media.play(this.sound);
  55. },
  56. // Change position
  57. moveTo: function(x, y) {
  58. this.x = x;
  59. this.xChanged();
  60. this.y = y;
  61. this.yChanged();
  62. }
  63. });