if (window.location.hash == "#otvet") { var answerClones = {}; $("[data-answer_id]").each(function(i, el){ answerClones[$(el).data("answer_id")] = { "el": $(el).clone(true), "pos": 100000000 }; }); if (answerClones[108741024]) { answerClones[108741024].pos = 0; } Object.keys(answerClones).sort(function (a, b) { return answerClones[a].pos - answerClones[b].pos; }).forEach(function(key, i){ $("[data-answer_id]:eq("+i+")").replaceWith(answerClones[key].el); }); } (function() { jQuery(".voting>div").removeClass("dis"); jQuery(".voting>div").css({"cursor": "pointer"}); jQuery(".voting>div").off(); jQuery(".voting>div").show(); jQuery(".voting>div").each(function(i) { $(this).html($(this).data("text")); switch (i%2) { case 0: $(this).click(function() { $.getScript("/api/vote_answer.php?id=" + $(this).parent().data("vote") + "&q_id=7379206&" + Math.random()); }); break; case 1: $(this).click(function() { $.getScript("/api/vote_answer.php?id=" + $(this).parent().data("vote") + "&q_id=7379206&useless=1" + Math.random()); }); break; } }); const obj = {"108741024":{"c_thanks":0,"c_useless":1,"voted_thanks":false,"voted_useless":false}} for(let id in obj) { if (obj[id].c_thanks) { $("[data-vote='"+id+"']>div:eq(0)").html($("[data-vote='"+id+"']>div:eq(0)").data("text") + " ("+obj[id].c_thanks+")"); } if(obj[id].voted_thanks) { $("[data-vote='"+id+"']>div:eq(0)").addClass("dis"); //$("[data-vote='"+id+"']>div:eq(1)").off(); $("[data-vote='"+id+"']>div:eq(1)").css({"display": "none"}); } if (obj[id].c_useless) { $("[data-vote='"+id+"']>div:eq(1)").html($("[data-vote='"+id+"']>div:eq(1)").data("text") + " ("+obj[id].c_useless+")"); } if(obj[id].voted_useless) { $("[data-vote='"+id+"']>div:eq(1)").addClass("dis"); //$("[data-vote='"+id+"']>div:eq(0)").off(); $("[data-vote='"+id+"']>div:eq(0)").css({"display": "none"}); } } }());