jQuery.fn.qa = function(itemId, callback, silo) { console.log("SILO: " + silo); //NEED TO MAP LEADSOURCE TO NETSUITE INTERNAL ID var leadSource = ""; if(silo == 'architecturaldepot.com') { leadSource = -6; } else if(silo == 'buymanufacturers.com') { leadSource = 84717; } else if(silo == 'ekenamillwork.com') { leadSource = 76795; } else if(silo == 'millwork.com') { leadSource = 245368; } else if(silo == 'myhomesupply.com') { leadSource = 83798; } else if(silo == 'pacificcolumns.com') { leadSource = 15465; } else if(silo == 'shop.pacificcolumns.com') { leadSource = 15465; } else { leadSource = 2482299; } var fname = lname = email = customerId = questionIdAnswer = answerIdComment = null; var result = ""; var url = "https://scripts.architecturalinfo.com/qa/get_item_qa.php"; jQuery.ajax({ type: "GET", url: url, data: { itemId: itemId, silo: silo }, async: false, contentType: "application/json", dataType: "jsonp", jsonpCallback: callback, success: function(json) { jQuery('#qa_count').html('Ask a Question'); if (json.count > 0) { jQuery('#qa_count').html('Questions & Answers (' + json.count + ')'); //loop through questions jQuery.each(json.questions, function(b, d) { var i = 0; var answer_primary = "Not yet Answered"; var answer_all = ""; var totalvotes = 0; //loop through question responses jQuery.each(d.answers, function(e, f) { var commentCount = ""; var comment_list = ""; comment_list += '
'; if (f.commentCount > 0) { commentCount = " (" + f.commentCount + ")"; //loop through comments under answers jQuery.each(f.comments, function(g, h) { comment_list += '
'; comment_list += '' + h.nickname + ' said on ' + h.dateCommented + '
'; comment_list += '

' + h.comment + '

'; comment_list += '
'; }); } comment_list += '
'; //form to add a comment if (fname) { comment_list += ''; comment_list += ''; } else { comment_list += '
'; comment_list += '
'; } comment_list += '
'; comment_list += '
'; comment_list += '
'; comment_list += '
'; var verifiedPurchase = ""; var isPro = ""; if (f.verifiedPurchase == 1) { verifiedPurchase += ' Verified Purchase - '; } else if (f.isProAnswer == 1) { verifiedPurchase += ' PRO ANSWER - '; } if (i == 0) { answer_primary = '' + f.answer + '
'; if (f.upvotes > 0 || f.downvotes > 0) { totalvotes = Number(f.upvotes) + Number(f.downvotes); answer_primary += verifiedPurchase + 'By ' + f.customer.firstName + ' on ' + f.dateAnswered + '
'; answer_primary += 'Comment' + commentCount + ' | ' + f.upvotes + ' of ' + totalvotes + ' found this helpful. Do you? '; } else { answer_primary += verifiedPurchase + 'By ' + f.customer.firstName + ' on ' + f.dateAnswered + '
'; answer_primary += 'Comment' + commentCount + ' | Do you find this helpful? '; } answer_primary += comment_list; } else { answer_all += '
' + f.answer + '
'; answer_all += verifiedPurchase + 'By ' + f.customer.firstName + ' on ' + f.dateAnswered + '
'; if (f.upvotes > 0 || f.downvotes > 0) { totalvotes = Number(f.upvotes) + Number(f.downvotes); answer_all += 'Comment' + commentCount + ' | ' + f.upvotes + ' of ' + totalvotes + ' found this helpful. Do you? '; } else { answer_all += 'Comment' + commentCount + ' | Do you find this helpful? '; } answer_all += comment_list; } i++; }); result += '' + d.upvotes + 'votes' + d.downvotes + 'Question:' + d.question + ' Answer'; //form to answer question result += '
'; if (customerId) { result += ''; } else if (fname) { result += ''; } else { result += '
'; } result += '
'; result += 'Answer:' + answer_primary + '
'; if (d.count > 1) { result += '
'; result += '
' + answer_all + '
'; } result += '
'; }); var promises = 0; jQuery('.qa_table').html(result).promise().done(function() { promises++; if (promises >= 2) { if (questionIdAnswer) { jQuery("#answer_box_" + questionIdAnswer + "").attr("style", "display: block !important; height: auto !important; overflow: hidden;"); jQuery("html,body").animate({ scrollTop: jQuery("#answer_box_" + questionIdAnswer + "").offset().top - 40 }, "slow"); } else if (answerIdComment) { jQuery("#comment_" + answerIdComment).attr("style", "display: block !important; height: auto !important; overflow: hidden;"); jQuery("html,body").animate({ scrollTop: jQuery("#comment" + answerIdComment).offset().top - 40 }, "slow"); } } }); var question_box = ''; if (fname) { question_box += ''; } else { question_box += '
'; } if (email) { question_box += ''; } else { question_box += '
'; } question_box += '
'; let searchParams = new URLSearchParams(window.location.search); if(searchParams.has('test')) { question_box += '' } jQuery('.qa_input_details').html(question_box).promise().done(function() { promises++; if (promises >= 2) { if (questionIdAnswer) { jQuery("#answer_box_" + questionIdAnswer + "").attr("style", "display: block !important; height: auto !important; overflow: hidden;"); jQuery("html,body").animate({ scrollTop: jQuery("#answer_box_" + questionIdAnswer + "").offset().top - 40 }, "slow"); } else if (answerIdComment) { jQuery("#comment_" + answerIdComment).attr("style", "display: block !important; height: auto !important; overflow: hidden;"); jQuery("html,body").animate({ scrollTop: jQuery("#comment" + answerIdComment).offset().top - 40 }, "slow"); } } }); } else { jQuery.each(json.questions, function(b, d) { var i = 0; var answer_primary; var answer_all = ""; var totalvotes = 0; result += '' + d.upvotes + 'votes' + d.downvotes + 'Question:' + d.question + ' Answer'; //form to answer question result += '
'; if (customerId) { result += ''; } else if (fname) { result += ''; } else { result += '
'; } result += '
'; result += 'Answer:' + answer_primary + '
'; if (d.count > 1) { result += '
'; result += '
' + answer_all + '
'; } result += '
'; }); jQuery('.qa_table').html(result); var question_box = ''; if (fname) { question_box += ''; } else { question_box += '
'; } if (email) { question_box += ''; } else { question_box += '
'; } question_box += '
'; jQuery('.qa_input_details').html(question_box); } // Logic to show first 10 qa's and then reveal 5 more at a time if(jQuery("#show_more").length > 0){ let totalQAs = jQuery(".qa_table tr").length / 3; console.log("total qa: ", totalQAs) console.log(totalQAs > 10) if (totalQAs > 10) { totalQAs -= 10; console.log("new total qa: ", totalQAs) jQuery(".qa_table tr").hide(); //hides all qa's jQuery(".qa_table tr").slice(0, 30).show(); //Shows first 10 jQuery("#show_more").append(`Load More (${totalQAs})`); //initialize how many qa's are left on button } else { jQuery("#show_more").hide(); } jQuery("#show_more").click(function(e) { e.preventDefault(); jQuery(".qa_table tr:hidden").slice(0, 15).show(); //show 5 more on click totalQAs -= 5; jQuery("#show_more").text(`Load More (${totalQAs})`); //update remaining qa's in button if (jQuery(".qa_table tr:hidden").length === 0) { //if no more are left, hide button jQuery("#show_more").fadeOut('slow'); }; }); }; } }); //asking a question let timeout; let keyword; let initialize = true; let QAs; function filterQAs() { let startSlice = 0; let endSlice = 3; jQuery("#show_more").hide(); const totalQAs = jQuery(".qa_table tr").length / 3; for (let i = 0; i < totalQAs; i++) { const qa = jQuery(".qa_table tr").slice(startSlice, endSlice); let question = jQuery(qa).eq(0).find(".votes-question").html(); let answer = jQuery(qa).eq(1).find(".votes-answer").html(); // jQuery(qa).eq(0).find(".votes-question").html(question); if (question.toLowerCase().includes(keyword.toLowerCase())) { jQuery(qa).show(); // question = question.replace(new RegExp(keyword.toLowerCase(), "gi"), '$&'); // jQuery(qa).eq(0).find(".votes-question").html(question); } else if (answer.toLowerCase().includes(keyword.toLowerCase())) { jQuery(qa).show(); } else { jQuery(qa).hide(); // jQuery(qa).eq(0).find(".votes-question").html(question); } startSlice += 3; endSlice += 3; } } jQuery(".filter_qa_input").keyup(function(e) { // if (initialize) { // QAs = jQuery(".qa_table tr"); // console.log("2first: ", QAs[0]) // } initialize = false; clearTimeout(timeout); keyword = e.target.value; if (keyword == ""){ jQuery(".qa_table tr").show(); return; } timeout = setTimeout(filterQAs, 500); }); } jQuery.fn.answerQaEmail = function() { jQuery('#myModal').modal('show').find('.modal-content').html('
Testing
'); }