')); // Cube Competition if ($('div#page_body h2').text() === 'Competition: Win this awesome Cube gaming PC!') $('.articleCopy').html($('.articleCopy').html().replace('***QUESTION GOES HERE***', '')); // NZXT competition ending in July 22nd if ($('div#page_body h2').text() === 'Competition: Win an NZXT H440 EnVyUs case, Hue+ lighting controller or Gridv2 fan controller') $('.articleCopy').html($('.articleCopy').html().replace('**ENTER FORM HERE**', '')); if (screen.width <= 640)$('iframe#cube-competition').attr('scrolling', 'yes'); // Raven competition ending in July 19th if ($('div#page_body h2').text() === 'Competition: Win a load of awesome SilverStone gear!') $('.articleCopy').html($('.articleCopy').html().replace('***QUESTIONNAIRE GOES HERE***', '')); // Tickets competition if ($('div#page_body h2').text() === 'Competition: Win a pair of ROCCAT VIP Insomnia 58 tickets!') $('.articleCopy').html($('.articleCopy').html().replace('***QUESTIONNAIRE GOES HERE***', '')); // SilverStone competition if ($('div#page_body h2').text() === 'Competition: Win one of three SilverStone prizes!') $('.articleCopy').html($('.articleCopy').html().replace('***QUESTIONNAIRE GOES HERE***', '')); // if ($('.award img').attr('alt').indexOf('bittech-') > -1 || $('.award img').attr('alt').indexOf('bitgamer-') > -1) $('.overall').hide(); // $(".overall").each(function(){ if ($(this).css("display") === "none") {$(this).remove();}}); var newScoresClone = $('#newScores').detach(); var lastChild = $('.articleCopy').children().last(); if (lastChild.is('center')) lastChild.before(newScoresClone); else $('div.articleCopy').append(newScoresClone); var get_comments_url = "/api/functions/get_comments/76787/1/"; var template = Ta.compile($("#comments_template").html()); var base_comment_html = function(id, title, user_id, username) { return template({ id: id, title: title, user_id: user_id, username: username, }); }; function regenerate_comments_batch(batch_num){ empty_comments(); $.ajax({ url: get_comments_url.slice(0, -2) + batch_num + '/', type: 'GET', success: function(data){ $('#comments_container').prepend('
'); if (data.result === 'success'){ data.posts.forEach(function(v, i){ if (v.message_state==="visible") { var date = new Date(v.post_date * 1000); var formatted_date = date.toString().substring(0, 21) $('#current_comments').append(base_comment_html(v.post_id, 'Posted by ' + v.username + ' - ' + formatted_date, v.user_id, v.username)); $('#comment_' + v.post_id).find('.comment_text').html(v.message_html); } }); } else if (data.result === 'failed'){ console.log(data.error); } // $('#current_comments').delay(600).slideDown(600); $('.quote-icon').click(function(){ var comment = $(this).closest('[id*="comment"]'); quote_comment(comment.attr('id').split('_')[1]); }); }, }); $('button.active').removeClass('active'); $('button#batch_' + batch_num).addClass('active'); if (batch_num === 1){ $('button#first_batch').addClass('active'); } else if (!jQuery('button#batch_' + (parseInt(batch_num) + 1)).length){ $('button#last_batch').addClass('active'); } } var base_batch_button_html = function(batch_num){ return '' } function empty_comments(){ $('div#current_comments').attr('id', 'old_comments'); $('div#old_comments').fadeOut(600, function(){ $('div#old_comments').remove(); $('div#current_comments').fadeIn(600); }); } $.ajax({ url: get_comments_url, success: function(data){ if (data.result === 'success'){ data.posts.forEach(function(v, i){ if (v.message_state==="visible") { var date = new Date(v.post_date * 1000); var formatted_date = date.toString().substring(0, 21) $('#current_comments').append(base_comment_html(v.post_id, 'Posted by ' + v.username + ' - ' + formatted_date, v.user_id, v.username)); $('#comment_' + v.post_id).find('.comment_text').html(v.message_html); } }); var batches = Math.ceil((data.count)/5); if (batches > 1){ $('div#comments_nav') .append('') .prepend(''); var html = [] for (var i = 1; i <= batches; i++) html.push(base_batch_button_html(i)); $('div#comments_nav #batch_numbers').append(html); } else { $('#comments_nav').remove() } } else if (data.result === 'failed'){ console.log(data.error); } $('#first_batch').click(function(){ regenerate_comments_batch(1); }); $('#last_batch').click(function(){ regenerate_comments_batch(batches); }); $('#batch_numbers .comments_batch').click(function(){ var batch = jQuery(this).attr('id').split('_')[1]; regenerate_comments_batch(batch); }); $('button#first_batch').addClass('active'); $('button#batch_1').addClass('active'); $('.quote-icon').click(function(){ var comment = $(this).closest('[id*="comment"]'); quote_comment(comment.attr('id').split('_')[1]); }); }, }); // to post comments var comment_post_url = '/api/functions/create_xenforo_post/76787/'; // submit comment click $('#quick_comment_submit').click(function(){ // to prevent blank comments if ($('#quick_comment_text').val().length > 0){ // post comment as request.user.username $.post(comment_post_url, { 'message' : $('#quick_comment_text').val() }, // to handle response function(data){ if (data.success == true){ $('#quick_comment').html('

Thank you, your comment has been posted!

'); } else { $('#quick_comment').html('

Your comment failed to post.

'); } } ); } }); function quote_comment(comment_id){ // get comment, get vars needed for quote bb code var comment = $('#comment_' + comment_id); var username = comment.attr('data-username'); var post_id = comment.attr('data-id'); var member = comment.attr('data-member'); var text = comment.find('.comment_text').text(); // if quote already quotes, remove the nested quote from the text if (comment.find('.comment_text').html().split('
')[1]){ var text = comment.find('.comment_text').html().split('
')[1]; } var quote_text = '[QUOTE="' + username + ', post: ' + post_id + ', member: ' + member + '"]' + text + '[/QUOTE]'; $('#quick_comment_text').val(quote_text); } })(jQuery);