const COMMENTED_OBJECT_TYPE_ARTICLE = 0; const COMMENTED_OBJECT_TYPE_CONSULTANT = 1; var script = document.currentScript; if (!script) script = document.getElementById('comments-widget'); var comments_urlParams = new URLSearchParams(window.location.search); function ReadIntegerParam(param_name) { var result = parseInt(comments_urlParams.get(param_name), 10); if (isNaN(result)) result = 0; return result; } var article_id = script.getAttribute('article-id'); var consultant_id = script.getAttribute('consultant-id'); function GetCommentedObjectID() { if (consultant_id > 0) return consultant_id; return article_id; } function GetCommentedObjectType() { if (consultant_id > 0) return COMMENTED_OBJECT_TYPE_CONSULTANT; return COMMENTED_OBJECT_TYPE_ARTICLE; } var comments_lang = script.getAttribute('lang'); if (comments_lang == "zh-cn") comments_lang = "zh"; var comments_element_id = script.getAttribute('article-comments-control'); var comments_rating_element_id = script.getAttribute('article-rating-control'); var comments_widget_version = script.getAttribute('article-comments-version'); if ((!comments_widget_version) || (comments_widget_version == "")) { comments_widget_version = 1; } var hide_avatars = script.getAttribute('hide-avatars'); function LoadCommentsBlock() { if ($("#" + comments_element_id).length > 0) { $.ajax({ type: "POST", url: "/comments_widget.php", data: { "article_id": GetCommentedObjectID(), "type": GetCommentedObjectType(), "hide_avatars": hide_avatars, "version": comments_widget_version, "location_url": window.location.href, "lang": comments_lang }, success: function (response) { // console.log(response); if (response != "") { $("#" + comments_element_id).html(response); var goto_cooments_block = (comments_urlParams.get('comments_block') == "1"); if (goto_cooments_block) GoToCommentsBlock(); else { if (ReadIntegerParam('reply_to_comment_id') > 0) OnReplyToCommentClick(ReadIntegerParam('reply_to_comment_id'), true); else if (ReadIntegerParam('comment_id') > 0) OnReplyToCommentClick(ReadIntegerParam('comment_id'), false); } } if (comments_rating_element_id) $("." + comments_rating_element_id).show(); }, error: function (thrownError) { // do nothing } }); } } function LoadCommentsRatingBlock() { if ((comments_rating_element_id) && ($("." + comments_rating_element_id).length > 0)) { var script_path = location.href.substring(0, location.href.lastIndexOf("/")); $.ajax({ type: "POST", url: "/comments_widget.php", data: { "article_id": GetCommentedObjectID(), "type": GetCommentedObjectType(), "version": comments_widget_version, "mode": "generate_rating_block", "lang": comments_lang, "caller_script": script_path }, success: function (response) { if (response != "") { $("." + comments_rating_element_id).html(response); if (typeof PrepareCommentRatings == 'function') { PrepareCommentRatings(); } } }, error: function (thrownError) { // do nothing } }); } } function LoadArticleGoogleAggregateRating() { $.ajax({ type: "POST", url: "/comments_widget.php", data: { "article_id": GetCommentedObjectID(), "type": GetCommentedObjectType(), "consultant_id": consultant_id, "version": comments_widget_version, "mode": "generate_aggregate_rating_ajax", "lang": comments_lang }, success: function (response) { if ((response) && (response.trim() != "")) { var aggregate_rating_script = document.createElement('script'); aggregate_rating_script.setAttribute('type', 'application/ld+json'); aggregate_rating_script.text = response; document.head.appendChild(aggregate_rating_script); } }, error: function (thrownError) { // do nothing } }); } function isPageOfType(pageType) { const documentURL = new URL(window.location.href); const documentParams = new URLSearchParams(documentURL.search); const isPageOfTypeStr = documentParams.get(pageType) || ""; let result = (window.location.href.indexOf("/" + pageType + "/") >= 0); result = result || (isPageOfTypeStr === "1"); return result; } function isVacancyPage() { return isPageOfType("vacancy"); } function isInstitutionPage() { return isPageOfType("university"); } function shouldLoadWidgetContent() { let result = (article_id > 0); result = result || (consultant_id > 0); result = result && (!isVacancyPage()); result = result && (!isInstitutionPage()); return result; } if (shouldLoadWidgetContent()) { LoadCommentsBlock(); LoadCommentsRatingBlock(); LoadArticleGoogleAggregateRating(); }