Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  1. $.ajaxSetup({
  2.         headers: {
  3.             'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
  4.         }
  5.     });
  6.  
  7.     $( document ).on( 'click', '.loadmore', function () {
  8.         $(this).text('Učitavam...');
  9.         var btn = $(this);
  10.         $.ajax({
  11.             url: '/komentari',
  12.             type: 'POST',
  13.             data: {
  14.                 url: btn.data('url')
  15.             },
  16.             success: function(response){
  17.                 if(response){
  18.                     //console.log(response);
  19.                     btn.hide();
  20.                     $(".comments_display").append(response);
  21.                 } else {
  22.                     alert("error");
  23.                 }
  24.             }
  25.         });
  26.     });
  27.  
  28.     $( document ).on( 'click', '.loadmoreodgovori', function () {
  29.         $(this).hide();
  30.         $(this).siblings('.odgovorkom').show();
  31.  
  32.     });
  33.  
  34.     function IsJsonString(str) {
  35.         try {
  36.             JSON.parse(str);
  37.         } catch (e) {
  38.             return false;
  39.         }
  40.         return true;
  41.     }
  42.  
  43.     var request;
  44.  
  45.     function komentiraj($form) {
  46.  
  47.         if (request) {
  48.             request.abort();
  49.         }
  50.  
  51.         var $inputs = $form.find("input, select, button, textarea");
  52.         var serializedData = $form.serialize();
  53.         $inputs.prop("disabled", true);
  54.         request = $.ajax({
  55.             url: '/komentari/230518180',
  56.             type: "post",
  57.             data: serializedData
  58.         });
  59.  
  60.         $($form).animate({ opacity: .4 });
  61.  
  62.         request.done(function (response, textStatus, jqXHR, dataType){
  63.             //console.log(response);
  64.             var data = response;
  65.  
  66.             if (IsJsonString(data)) data = JSON.parse( response );
  67.  
  68.             if (data["error"]) {
  69.                 alert(data["error"]);
  70.                 $($form).animate({ opacity: 1 });
  71.             } else {
  72.  
  73.                 $($form).each(function(){
  74.                     $(this).find('textarea').val("");
  75.                 });
  76.  
  77.                 if($inputs.length==4) {
  78.                     $($form).before(response);
  79.                     $($form).hide();
  80.                 }
  81.                 else {
  82.                     $($form).animate({ opacity: 1 });
  83.                     $(".comments_display").prepend(response);
  84.                     $(".comments_display").fadeIn();
  85.                 }
  86.  
  87.             }
  88.         });
  89.  
  90.         request.fail(function (jqXHR, textStatus, errorThrown){
  91.             console.error(
  92.                 "The following error occurred: "+
  93.                 textStatus, errorThrown
  94.             );
  95.         });
  96.  
  97.         request.always(function () {
  98.             $inputs.prop("disabled", false);
  99.         });
  100.  
  101.         return false;
  102.     }
  103.  
  104.  
  105.     /* Funkcije za komentare */
  106.     function vote(id, type) {
  107.  
  108.         var params = {sifra: '230518180', type: type};
  109.  
  110.         if (!$(".vote_"+id+"_"+type).hasClass("opacity-40")) {
  111.  
  112.             $(".vote_"+id+"_"+type).addClass("opacity-40");
  113.             var br = parseInt($(".vote_"+id+"_"+type+" span").html());
  114.             $(".vote_"+id+"_"+type+" span").html(br+1);
  115.  
  116.             $.post("https://api.klix.ba/v1/rate/"+id, params, function(response){
  117.                 console.log(response);
  118.             });
  119.         }
  120.  
  121.     }
  122.  
  123.  
  124.  
  125.     function openReplyBox(id) {
  126.         $(".replybox").hide();
  127.         $(".replybox.reply-"+id).show();
  128.     }
  129.  
  130.  
  131.     function showReplies(id) {
  132.         $(".komentarOdgovori[data-id="+id+"] .komentar.hidden").removeClass("hidden");
  133.         $(".komentarOdgovori[data-id="+id+"] .prikaziOstale").remove();
  134.     }
  135.  
  136.     function showComment(id) {
  137.         $(".komentar[data-id="+id+"] .sakriven").remove();
  138.         $(".komentar[data-id="+id+"] .komMain, .komentar[data-id="+id+"] .komentarFooter").removeClass("hidden");
  139.     }
  140.  
  141.  
  142.     var reportID;
  143.  
  144.     function report(id) {
  145.         //alert("id: " + id);
  146.         reportID = id;
  147.         modal.style.display = "block";
  148.     }
  149.  
  150.     function submitreport($form) {
  151.  
  152.         var razlog = $('input[name=razlog]:checked', $form).val();
  153.         if(razlog==undefined) alert("Molimo, odaberite razlog prijave.");
  154.         else {
  155.             $.post('/report', $.param({ komentar: reportID, razlog: razlog }), function(response){
  156.                 console.log("response" + response);
  157.                 var response = JSON.parse( response );
  158.                 if(response["success"]) {
  159.                     modal.style.display = "none";
  160.                     $('input[name=razlog]:checked', $form).prop('checked', false);
  161.                     alert("Uspješno ste prijavili komentar. Hvala vam!");
  162.                 }
  163.             });
  164.         }
  165.  
  166.         return false;
  167.     }
  168.  
  169.     var modal = document.getElementById('myModal');
  170.     var btn = document.getElementsByClassName("prijavi");
  171.     var span = document.getElementsByClassName("close")[0];
  172.     btn.onclick = function() {
  173.         modal.style.display = "block";
  174.     }
  175.     span.onclick = function() {
  176.         modal.style.display = "none";
  177.     }
  178.     window.onclick = function(event) {
  179.         if (event.target == modal) {
  180.             modal.style.display = "none";
  181.             reportID = null;
  182.         }
  183.     }
  184.