Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.
 
 
 
 

65 linhas
1.7 KiB

  1. const $ = require('jquery');
  2. class Survey{
  3. constructor(section) {
  4. this.section = section.addClass('initiated');
  5. this.form = section.find('form');
  6. if (this.form.data('show-result')) {
  7. this.loadResult();
  8. }
  9. else {
  10. this.initOptions();
  11. }
  12. }
  13. initOptions() {
  14. this.form.find('input[type="radio"]').on('change', (e) => {
  15. if (this.form.find('input[type="radio"]:checked').length === this.form.find('fieldset').length) {
  16. this.loadResult();
  17. }
  18. })
  19. }
  20. loadResult() {
  21. const heightDiff = this.section.outerHeight() - this.form.outerHeight();
  22. const parent = this.form.parent();
  23. parent.css({'height': parent.outerHeight() + 'px', 'min-height': parent.outerHeight() + 'px'});
  24. const posting = $.post(this.form.attr('action'), this.form.serialize()).done((result) => {
  25. this.result = $(result).appendTo(parent);
  26. parent.css('height', (this.result.outerHeight() + heightDiff) + 'px');
  27. this.animateResult();
  28. setTimeout(() => {
  29. this.section.addClass('show-result')
  30. },50)
  31. setTimeout(() => {
  32. parent.css({'height': 'auto'});
  33. },800)
  34. })
  35. }
  36. animateResult() {
  37. const items = this.result.find('.sub-result-wrapper');
  38. items.each((i, el) => {
  39. $('<span class="bar" />').prependTo($(el)).css('transition-delay', (i / 10).toString() + 's');
  40. })
  41. setTimeout(() => {
  42. items.each((i, el) => {
  43. const item = $(el);
  44. item.find('.bar').css('width', parseInt(item.find('.value').text()) + '%');
  45. })
  46. },500)
  47. }
  48. }
  49. $('body').on('ihk-init dynamic-component-loaded gfi-dynamic-init', function () {
  50. $('.survey:not(.initiated)').each((i, el) => {
  51. new Survey($(el));
  52. });
  53. })