Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- $.ajaxSetup({
- headers: {
- 'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
- }
- });
- $( document ).on( 'click', '.loadmore', function () {
- $(this).text('Učitavam...');
- var btn = $(this);
- $.ajax({
- url: '/komentari',
- type: 'POST',
- data: {
- url: btn.data('url')
- },
- success: function(response){
- if(response){
- //console.log(response);
- btn.hide();
- $(".comments_display").append(response);
- } else {
- alert("error");
- }
- }
- });
- });
- $( document ).on( 'click', '.loadmoreodgovori', function () {
- $(this).hide();
- $(this).siblings('.odgovorkom').show();
- });
- function IsJsonString(str) {
- try {
- JSON.parse(str);
- } catch (e) {
- return false;
- }
- return true;
- }
- var request;
- function komentiraj($form) {
- if (request) {
- request.abort();
- }
- var $inputs = $form.find("input, select, button, textarea");
- var serializedData = $form.serialize();
- $inputs.prop("disabled", true);
- request = $.ajax({
- url: '/komentari/230518180',
- type: "post",
- data: serializedData
- });
- $($form).animate({ opacity: .4 });
- request.done(function (response, textStatus, jqXHR, dataType){
- //console.log(response);
- var data = response;
- if (IsJsonString(data)) data = JSON.parse( response );
- if (data["error"]) {
- alert(data["error"]);
- $($form).animate({ opacity: 1 });
- } else {
- $($form).each(function(){
- $(this).find('textarea').val("");
- });
- if($inputs.length==4) {
- $($form).before(response);
- $($form).hide();
- }
- else {
- $($form).animate({ opacity: 1 });
- $(".comments_display").prepend(response);
- $(".comments_display").fadeIn();
- }
- }
- });
- request.fail(function (jqXHR, textStatus, errorThrown){
- console.error(
- "The following error occurred: "+
- textStatus, errorThrown
- );
- });
- request.always(function () {
- $inputs.prop("disabled", false);
- });
- return false;
- }
- /* Funkcije za komentare */
- function vote(id, type) {
- var params = {sifra: '230518180', type: type};
- if (!$(".vote_"+id+"_"+type).hasClass("opacity-40")) {
- $(".vote_"+id+"_"+type).addClass("opacity-40");
- var br = parseInt($(".vote_"+id+"_"+type+" span").html());
- $(".vote_"+id+"_"+type+" span").html(br+1);
- $.post("https://api.klix.ba/v1/rate/"+id, params, function(response){
- console.log(response);
- });
- }
- }
- function openReplyBox(id) {
- $(".replybox").hide();
- $(".replybox.reply-"+id).show();
- }
- function showReplies(id) {
- $(".komentarOdgovori[data-id="+id+"] .komentar.hidden").removeClass("hidden");
- $(".komentarOdgovori[data-id="+id+"] .prikaziOstale").remove();
- }
- function showComment(id) {
- $(".komentar[data-id="+id+"] .sakriven").remove();
- $(".komentar[data-id="+id+"] .komMain, .komentar[data-id="+id+"] .komentarFooter").removeClass("hidden");
- }
- var reportID;
- function report(id) {
- //alert("id: " + id);
- reportID = id;
- modal.style.display = "block";
- }
- function submitreport($form) {
- var razlog = $('input[name=razlog]:checked', $form).val();
- if(razlog==undefined) alert("Molimo, odaberite razlog prijave.");
- else {
- $.post('/report', $.param({ komentar: reportID, razlog: razlog }), function(response){
- console.log("response" + response);
- var response = JSON.parse( response );
- if(response["success"]) {
- modal.style.display = "none";
- $('input[name=razlog]:checked', $form).prop('checked', false);
- alert("Uspješno ste prijavili komentar. Hvala vam!");
- }
- });
- }
- return false;
- }
- var modal = document.getElementById('myModal');
- var btn = document.getElementsByClassName("prijavi");
- var span = document.getElementsByClassName("close")[0];
- btn.onclick = function() {
- modal.style.display = "block";
- }
- span.onclick = function() {
- modal.style.display = "none";
- }
- window.onclick = function(event) {
- if (event.target == modal) {
- modal.style.display = "none";
- reportID = null;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement