Advertisement
Guest User

teste

a guest
Oct 17th, 2017
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  /*
  2.     * Show more questions
  3.     * */
  4.     var cruzadinha = {
  5.         perguntas: [
  6.             {
  7.                 "id": "0",
  8.                 "Pergunta": "Como é seu nome?",
  9.                 "Categoria": "Pessoal",
  10.                 "status" : "none"
  11.             },
  12.             {
  13.                 "id": "1",
  14.                 "Pergunta": "Em que ano você nasceu?",
  15.                 "Categoria": "Pessoal",
  16.                 "status" : "none"
  17.             },
  18.             {
  19.                 "id": "2",
  20.                 "Pergunta": "Quantos anos você tem?",
  21.                 "Categoria": "Facil",
  22.                 "status" : "none"
  23.             },
  24.             {
  25.                 "id": "3",
  26.                 "Pergunta": "Como é seu primeiro nome?",
  27.                 "Categoria": "Facil",
  28.                 "status" : "none"
  29.             },
  30.             {
  31.                 "id": "4",
  32.                 "Pergunta": "O nome de sua filha do meio?",
  33.                 "Categoria": "Facil",
  34.                 "status" : "none"
  35.             },
  36.             {
  37.                 "id": "5",
  38.                 "Pergunta": "O nome do seu primeiro cachorro?",
  39.                 "Categoria": "Facil",
  40.                 "status" : "none"
  41.             },
  42.             {
  43.                 "id": "6",
  44.                 "Pergunta": "Quantos anos vc trabalhou pela primeira vez?",
  45.                 "Categoria": "Facil",
  46.                 "status" : "none"
  47.             },
  48.             {
  49.                 "id": "7",
  50.                 "Pergunta": "Seu esporte favorito?",
  51.                 "Categoria": "Facil",
  52.                 "status" : "none"
  53.             },
  54.             {
  55.                 "id": "8",
  56.                 "Pergunta": "Com qual idade voce andou de bicicleta?",
  57.                 "Categoria": "Facil",
  58.                 "status" : "none"
  59.             },
  60.             {
  61.                 "id": "9",
  62.                 "Pergunta": "Como é seu nome?",
  63.                 "Categoria": "Facil",
  64.                 "status" : "none"
  65.             },
  66.             {
  67.                 "id": "10",
  68.                 "Pergunta": "Como é seu dasd nome?",
  69.                 "Categoria": "Facil",
  70.                 "status" : "none"
  71.             },
  72.             {
  73.                 "id": "11",
  74.                 "Pergunta": "Como é seu asdas nome?",
  75.                 "Categoria": "Facil",
  76.                 "status" : "none"
  77.             },
  78.             {
  79.                 "id": "12",
  80.                 "Pergunta": "Como é seuasdads nome?",
  81.                 "Categoria": "Facil",
  82.                 "status" : "none"
  83.             },
  84.             {
  85.                 "id": "13",
  86.                 "Pergunta": "Comoadsdasdas é seu nome?",
  87.                 "Categoria": "Facil",
  88.                 "status" : "none"
  89.             },
  90.             {
  91.                 "id": "14",
  92.                 "Pergunta": "Comoasddaddsa é seu nome?",
  93.                 "Categoria": "Facil",
  94.                 "status" : "none"
  95.             },
  96.             {
  97.                 "id": "9",
  98.                 "Pergunta": "Como é seu nome?",
  99.                 "Categoria": "Facil",
  100.                 "status" : "none"
  101.             },
  102.             {
  103.                 "id": "10",
  104.                 "Pergunta": "Como é seu dasd nome?",
  105.                 "Categoria": "Facil",
  106.                 "status" : "none"
  107.             },
  108.             {
  109.                 "id": "11",
  110.                 "Pergunta": "Como é seu asdas nome?",
  111.                 "Categoria": "Facil",
  112.                 "status" : "none"
  113.             },
  114.             {
  115.                 "id": "12",
  116.                 "Pergunta": "Como é seuasdads nome?",
  117.                 "Categoria": "Facil",
  118.                 "status" : "none"
  119.             },
  120.             {
  121.                 "id": "13",
  122.                 "Pergunta": "Comoadsdasdas é seu nome?",
  123.                 "Categoria": "Facil",
  124.                 "status" : "none"
  125.             },
  126.             {
  127.                 "id": "14",
  128.                 "Pergunta": "Comoasddaddsa é seu nome?",
  129.                 "Categoria": "Facil",
  130.                 "status" : "none"
  131.             },
  132.             {
  133.                 "id": "9",
  134.                 "Pergunta": "Como é seu nome?",
  135.                 "Categoria": "Facil",
  136.                 "status" : "none"
  137.             },
  138.             {
  139.                 "id": "10",
  140.                 "Pergunta": "Como é seu dasd nome?",
  141.                 "Categoria": "Facil",
  142.                 "status" : "none"
  143.             },
  144.             {
  145.                 "id": "11",
  146.                 "Pergunta": "Como é seu asdas nome?",
  147.                 "Categoria": "Facil",
  148.                 "status" : "none"
  149.             },
  150.             {
  151.                 "id": "12",
  152.                 "Pergunta": "Como é seuasdads nome?",
  153.                 "Categoria": "Facil",
  154.                 "status" : "none"
  155.             },
  156.             {
  157.                 "id": "13",
  158.                 "Pergunta": "Comoadsdasdas é seu nome?",
  159.                 "Categoria": "Facil",
  160.                 "status" : "none"
  161.             },
  162.             {
  163.                 "id": "14",
  164.                 "Pergunta": "Comoasddaddsa é seu nome?",
  165.                 "Categoria": "Facil",
  166.                 "status" : "none"
  167.             },
  168.             {
  169.                 "id": "9",
  170.                 "Pergunta": "Como é seu nome?",
  171.                 "Categoria": "Facil",
  172.                 "status" : "none"
  173.             },
  174.             {
  175.                 "id": "10",
  176.                 "Pergunta": "Como é seu dasd nome?",
  177.                 "Categoria": "Facil",
  178.                 "status" : "none"
  179.             },
  180.             {
  181.                 "id": "11",
  182.                 "Pergunta": "Como é seu asdas nome?",
  183.                 "Categoria": "Facil",
  184.                 "status" : "none"
  185.             },
  186.             {
  187.                 "id": "12",
  188.                 "Pergunta": "Como é seuasdads nome?",
  189.                 "Categoria": "Facil",
  190.                 "status" : "none"
  191.             },
  192.             {
  193.                 "id": "13",
  194.                 "Pergunta": "Comoadsdasdas é seu nome?",
  195.                 "Categoria": "Facil",
  196.                 "status" : "none"
  197.             },
  198.             {
  199.                 "id": "14",
  200.                 "Pergunta": "Comoasddaddsa é seu nome?",
  201.                 "Categoria": "Facil",
  202.                 "status" : "none"
  203.             },
  204.             {
  205.                 "id": "9",
  206.                 "Pergunta": "Como é seu nome?",
  207.                 "Categoria": "Facil",
  208.                 "status" : "none"
  209.             },
  210.             {
  211.                 "id": "10",
  212.                 "Pergunta": "Como é seu dasd nome?",
  213.                 "Categoria": "Facil",
  214.                 "status" : "none"
  215.             },
  216.             {
  217.                 "id": "11",
  218.                 "Pergunta": "Como é seu asdas nome?",
  219.                 "Categoria": "Facil",
  220.                 "status" : "none"
  221.             },
  222.             {
  223.                 "id": "12",
  224.                 "Pergunta": "Como é seuasdads nome?",
  225.                 "Categoria": "Facil",
  226.                 "status" : "none"
  227.             },
  228.             {
  229.                 "id": "13",
  230.                 "Pergunta": "Comoadsdasdas é seu nome?",
  231.                 "Categoria": "Facil",
  232.                 "status" : "none"
  233.             },
  234.             {
  235.                 "id": "14",
  236.                 "Pergunta": "Comoasddaddsa é seu nome?",
  237.                 "Categoria": "Facil",
  238.                 "status" : "none"
  239.             },
  240.             {
  241.                 "id": "9",
  242.                 "Pergunta": "Como é seu nome?",
  243.                 "Categoria": "Facil",
  244.                 "status" : "none"
  245.             },
  246.             {
  247.                 "id": "10",
  248.                 "Pergunta": "Como é seu dasd nome?",
  249.                 "Categoria": "Facil",
  250.                 "status" : "none"
  251.             },
  252.             {
  253.                 "id": "11",
  254.                 "Pergunta": "Como é seu asdas nome?",
  255.                 "Categoria": "Facil",
  256.                 "status" : "none"
  257.             },
  258.             {
  259.                 "id": "12",
  260.                 "Pergunta": "Como é seuasdads nome?",
  261.                 "Categoria": "Facil",
  262.                 "status" : "none"
  263.             },
  264.             {
  265.                 "id": "13",
  266.                 "Pergunta": "Comoadsdasdas é seu nome?",
  267.                 "Categoria": "Facil",
  268.                 "status" : "none"
  269.             },
  270.             {
  271.                 "id": "14",
  272.                 "Pergunta": "Comoasddaddsa é seu nome?",
  273.                 "Categoria": "Facil",
  274.                 "status" : "none"
  275.             },
  276.             {
  277.                 "id": "9",
  278.                 "Pergunta": "Como é seu nome?",
  279.                 "Categoria": "Facil",
  280.                 "status" : "none"
  281.             },
  282.             {
  283.                 "id": "10",
  284.                 "Pergunta": "Como é seu dasd nome?",
  285.                 "Categoria": "Facil",
  286.                 "status" : "none"
  287.             },
  288.             {
  289.                 "id": "11",
  290.                 "Pergunta": "Como é seu asdas nome?",
  291.                 "Categoria": "Facil",
  292.                 "status" : "none"
  293.             },
  294.             {
  295.                 "id": "12",
  296.                 "Pergunta": "Como é seuasdads nome?",
  297.                 "Categoria": "Facil",
  298.                 "status" : "none"
  299.             },
  300.             {
  301.                 "id": "13",
  302.                 "Pergunta": "Comoadsdasdas é seu nome?",
  303.                 "Categoria": "Facil",
  304.                 "status" : "none"
  305.             },
  306.             {
  307.                 "id": "14",
  308.                 "Pergunta": "Comoasddaddsa é seu nome?",
  309.                 "Categoria": "Facil",
  310.                 "status" : "none"
  311.             },
  312.             {
  313.                 "id": "9",
  314.                 "Pergunta": "Como é seu nome?",
  315.                 "Categoria": "Facil",
  316.                 "status" : "none"
  317.             },
  318.             {
  319.                 "id": "10",
  320.                 "Pergunta": "Como é seu dasd nome?",
  321.                 "Categoria": "Facil",
  322.                 "status" : "none"
  323.             },
  324.             {
  325.                 "id": "11",
  326.                 "Pergunta": "Como é seu asdas nome?",
  327.                 "Categoria": "Facil",
  328.                 "status" : "none"
  329.             },
  330.             {
  331.                 "id": "12",
  332.                 "Pergunta": "Como é seuasdads nome?",
  333.                 "Categoria": "Facil",
  334.                 "status" : "none"
  335.             },
  336.             {
  337.                 "id": "13",
  338.                 "Pergunta": "Comoadsdasdas é seu nome?",
  339.                 "Categoria": "Facil",
  340.                 "status" : "none"
  341.             },
  342.             {
  343.                 "id": "14",
  344.                 "Pergunta": "Comoasddaddsa é seu nome?",
  345.                 "Categoria": "Facil",
  346.                 "status" : "none"
  347.             },
  348.             {
  349.                 "id": "9",
  350.                 "Pergunta": "Como é seu nome?",
  351.                 "Categoria": "Facil",
  352.                 "status" : "none"
  353.             },
  354.             {
  355.                 "id": "10",
  356.                 "Pergunta": "Como é seu dasd nome?",
  357.                 "Categoria": "Facil",
  358.                 "status" : "none"
  359.             },
  360.             {
  361.                 "id": "11",
  362.                 "Pergunta": "Como é seu asdas nome?",
  363.                 "Categoria": "Facil",
  364.                 "status" : "none"
  365.             },
  366.             {
  367.                 "id": "12",
  368.                 "Pergunta": "Como é seuasdads nome?",
  369.                 "Categoria": "Facil",
  370.                 "status" : "none"
  371.             },
  372.             {
  373.                 "id": "13",
  374.                 "Pergunta": "Comoadsdasdas é seu nome?",
  375.                 "Categoria": "Facil",
  376.                 "status" : "none"
  377.             },
  378.             {
  379.                 "id": "14",
  380.                 "Pergunta": "Comoasddaddsa é seu nome?",
  381.                 "Categoria": "Facil",
  382.                 "status" : "none"
  383.             }
  384.             ],
  385.         perguntasSelecionadas: [],
  386.  
  387.         init: function(){
  388.  
  389.             this.cacheDom();
  390.             this.populaPergunta();
  391.             this.adicionarPerguntas();
  392.             this.excluirPerguntas();
  393.         },
  394.  
  395.         cacheDom: function (){
  396.             this.$listaPerguntas = $('.lista-perguntas');
  397.         },
  398.  
  399.         populaPergunta: function () {
  400.             for(var x = 0; x < 10; x++) {
  401.                 $('<li>'+this.perguntas[x].Pergunta+'<a class="exclude" data-id="'+this.perguntas[x].id+'">--Excluir</a></li>').prependTo(this.$listaPerguntas).hide().fadeIn();
  402.                 this.perguntas[x].status = 'select';
  403.                 this.perguntasSelecionadas.push(this.perguntas[x]);
  404.             }
  405.         },
  406.        
  407.         adicionarPerguntas: function () {
  408.             var self = this;
  409.             $(document).on('click','.btn-questions', function () {
  410.                 var maxRepetion = 0;
  411.                 if(self.perguntas.length > 10) {
  412.                     for (var x = 0; x < self.perguntas.length; x++) {
  413.                         if (self.perguntas[x].status === 'none') {
  414.                             $('<li>' + self.perguntas[x].Pergunta + '<a class="exclude" data-id="' + self.perguntas[x].id + '">--Excluir</a></li>').appendTo(self.$listaPerguntas).hide().fadeIn();
  415.                             self.perguntas[x].status = 'select';
  416.                             self.perguntasSelecionadas.push(self.perguntas[x]);
  417.                             maxRepetion++;
  418.                             if (maxRepetion > 5) {
  419.                                 return;
  420.                             }
  421.                         }
  422.                     }
  423.                 }else{
  424.                     alert("Acabou as perguntas caraio");
  425.                 }
  426.             })
  427.  
  428.         },
  429.        
  430.         excluirPerguntas: function () {
  431.             var self = this;
  432.  
  433.             function removePergunta(btn){
  434.                 for (var x = 0; x < self.perguntas.length; x++) {
  435.                     if (self.perguntas[x].id === $(btn).attr('data-id')) {
  436.                         $(btn).parent().fadeOut();
  437.                         $(btn).parent().remove();
  438.                         self.perguntas.splice(self.perguntas.indexOf(self.perguntas[x]), 1);
  439.                         self.perguntasSelecionadas.splice(self.perguntasSelecionadas.indexOf(self.perguntas[x]), 1);
  440.                         break;
  441.                     }
  442.                 }
  443.             }
  444.  
  445.             $(document).on('click','.exclude', function () {
  446.                 if(self.perguntas.length > 10){
  447.                     if(self.perguntasSelecionadas.length === 10) {
  448.                         removePergunta($(this));
  449.                         for (var y = 0; y < self.perguntas.length; y++) {
  450.                             if (self.perguntas[y].status === 'none') {
  451.                                 $('<li>' + self.perguntas[y].Pergunta + '<a class="exclude" data-id="' + self.perguntas[y].id + '">--Excluir</a></li>').appendTo(self.$listaPerguntas).hide().fadeIn();
  452.                                 self.perguntas[y].status = 'select';
  453.                                 self.perguntasSelecionadas.push(self.perguntas[y]);
  454.                                 return;
  455.                             }
  456.                         }
  457.                     }else if(self.perguntasSelecionadas.length > 10){
  458.                         removePergunta(this);
  459.                     } else{
  460.                         alert("Minimo 10 perguntas viado");
  461.                     }
  462.                 }else{
  463.                     alert("Acabou as perguntas carai");
  464.                 }
  465.             })
  466.         }
  467.     };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement