Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.
 
 
 

55 rader
1.0 KiB

  1. define([
  2. 'html!ui/templates/effects/template',
  3. 'css!ui/templates/effects/styles',
  4. 'html!ui/templates/effects/templateEffect'
  5. ], function (
  6. template,
  7. styles,
  8. templateEffect
  9. ) {
  10. return {
  11. tpl: template,
  12. icons: {},
  13. postRender: function () {
  14. this.onEvent('onGetEffectIcon', this.onGetEffectIcon.bind(this));
  15. this.onEvent('onRemoveEffectIcon', this.onRemoveEffectIcon.bind(this));
  16. },
  17. buildIcon: function (config) {
  18. let { icon, url } = config;
  19. if (!url)
  20. url = '../../../images/statusIcons.png';
  21. let imgX = icon[0] * -32;
  22. let imgY = icon[1] * -32;
  23. let html = templateEffect;
  24. let el = $(html).appendTo(this.el)
  25. .find('.inner')
  26. .css({
  27. background: `url(${url}) ${imgX}px ${imgY}px`
  28. });
  29. return el.parent();
  30. },
  31. onGetEffectIcon: function (config) {
  32. let el = this.buildIcon(config);
  33. this.icons[config.id] = el;
  34. },
  35. onRemoveEffectIcon: function (config) {
  36. let el = this.icons[config.id];
  37. if (!el)
  38. return;
  39. el.remove();
  40. delete this.icons[config.id];
  41. }
  42. };
  43. });