(function (jQuery) { ("use strict"); jQuery(document).ready(function () { if ($('#myComment').length > 0) { var maxLength = parseInt($('#myComment').data('maxlength')); maxLength = maxLength <= 0 ? 500 : maxLength; var remaining = 0; remaining = maxLength - $('#myComment').val().length; if (remaining < 0) { $('#myComment').val($('#myComment').val().substring(0, maxLength)); remaining = 0; } $('#charCount').text(remaining + ' chars remaining'); $('#myComment').on('input', function () { var textlen = $(this).val().length; remaining = maxLength - textlen; if (remaining <= 0) { $(this).val($(this).val().substring(0, maxLength)); remaining = 0; } $('#charCount').text(remaining + ' chars remaining'); }); } /*--------------------------------------------------------------------- Sidebar Toggle -----------------------------------------------------------------------*/ function updateSidebarType() { if (typeof IQSetting !== typeof undefined) { const sidebarType = IQSetting.options.setting.sidebar_type.value; const newTypes = sidebarType; if (sidebarType.includes("sidebar-mini")) { const indexOf = newTypes.findIndex((x) => x == "sidebar-mini"); newTypes.splice(indexOf, 1); } else { newTypes.push("sidebar-mini"); } IQSetting.sidebar_type(newTypes); } } const sidebarToggle = (elem) => { elem.addEventListener("click", (e) => { console.log("onclick menu"); const sidebar = document.querySelector(".sidebar"); if (sidebar.classList.contains("sidebar-mini")) { sidebar.classList.remove("sidebar-mini"); sidebar.classList.add("shadow-sm"); //updateSidebarType(); } else { sidebar.classList.add("sidebar-mini"); sidebar.classList.remove("shadow-sm"); //updateSidebarType(); } /* const sidebarMini = document.getElementsByTagName("ASIDE")[0]; if (sidebarMini.classList.contains('sidebar-mini')) { sidebarMini.classList.remove('sidebar-mini') } else { sidebarMini.classList.add('sidebar-mini') } */ }); }; jQuery(document).on("click", '[data-toggle="sidebar"]', function () { jQuery("body").toggleClass("sidebar-main"); jQuery(this).toggleClass("mini"); }); const sidebarToggleBtn = document.querySelectorAll( '[data-toggle="sidebar"]' ); const sidebar = document.querySelector('[data-toggle="main-sidebar"]'); if (sidebar !== null) { const sidebarActiveItem = sidebar.querySelectorAll(".active"); Array.from(sidebarActiveItem, (elem) => { elem.classList.add("active"); if (!elem.closest("ul").classList.contains("iq-main-menu")) { const childMenu = elem.closest("ul"); const parentMenu = childMenu.closest("li").querySelector(".nav-link"); parentMenu.classList.add("active"); new bootstrap.Collapse(childMenu, { toggle: true, }); } }); } Array.from(sidebarToggleBtn, (sidebarBtn) => { sidebarToggle(sidebarBtn); }); /*--------------------------------------------------------------------- Sidebar Left Active Border -----------------------------------------------------------------------*/ window.addEventListener("load", () => { const leftSidebar = document.querySelector( '[data-toggle="main-sidebar"]' ); if (leftSidebar !== null) { const collapseElementList = [].slice.call( leftSidebar.querySelectorAll(".collapse") ); const collapseList = collapseElementList.map(function (collapseEl) { collapseEl.addEventListener("show.bs.collapse", function (elem) { collapseEl.closest("li").classList.add("active"); }); collapseEl.addEventListener("hidden.bs.collapse", function (elem) { collapseEl.closest("li").classList.remove("active"); }); }); const active = leftSidebar.querySelector(".active"); if (active !== null) { active.closest("li").classList.add("active"); } } }); /*--------------------------------------------------------------------- Scrollbar -----------------------------------------------------------------------*/ let Scrollbar; if (typeof Scrollbar !== typeof null) { if (document.querySelectorAll(".data-scrollbar").length) { Scrollbar = window.Scrollbar; Scrollbar.init(document.querySelector(".data-scrollbar"), { continuousScrolling: false, }); // Add event listeners to the entire sidebar sidebar.addEventListener('mouseenter', showScrollbar); sidebar.addEventListener('mouseleave', hideScrollbar); } } function showScrollbar() { const tracks = sidebar.querySelectorAll('.scrollbar-track'); tracks.forEach(track => track.style.opacity = 1); } function hideScrollbar() { const tracks = sidebar.querySelectorAll('.scrollbar-track'); tracks.forEach(track => track.style.opacity = 0); } }); /*--------------------------------------------------------------------- Form Validation -----------------------------------------------------------------------*/ // Example starter JavaScript for disabling form submissions if there are invalid fields window.addEventListener( "load", function () { // Fetch all the forms we want to apply custom Bootstrap validation styles to var forms = document.getElementsByClassName("needs-validation"); // Loop over them and prevent submission var validation = Array.prototype.filter.call(forms, function (form) { form.addEventListener( "submit", function (event) { if (form.checkValidity() === false) { event.preventDefault(); event.stopPropagation(); } form.classList.add("was-validated"); }, false ); }); }, false ); /*------------Resize Plugins--------------*/ const resizePlugins = () => { // For sidebar-mini & responsive const sidebarResponsive = document.querySelector( '[data-sidebar="responsive"]' ); if (window.innerWidth < 1025) { if (sidebarResponsive !== null) { if (!sidebarResponsive.classList.contains("sidebar-mini")) { sidebarResponsive.classList.add("sidebar-mini", "on-resize"); } } } else { if (sidebarResponsive !== null) { if ( sidebarResponsive.classList.contains("sidebar-mini") && sidebarResponsive.classList.contains("on-resize") ) { sidebarResponsive.classList.remove("sidebar-mini", "on-resize"); } } } }; /*------------DOMContentLoaded--------------*/ document.addEventListener("DOMContentLoaded", (event) => { resizePlugins(); }); /*------------Window Resize------------------*/ window.addEventListener("resize", function (event) { resizePlugins(); }); jQuery(document).on("click", ".modal-backdrop.show", function () { if (jQuery(".search-modal.show").length) { bootstrap.Modal.getInstance("#searchmodal").hide(); } }); })(jQuery); let bShowTab = false; let bInitedLoginModal = false; function showLoginModel() { if (!bInitedLoginModal) { window.location.href = '/'; return false; } if (bShowTab) { document.getElementById("apsenseTab").click() }else{ bShowTab = true; const modal = document.getElementById('apsenseSignupModal'); modal.classList.add('apsense-modal-show'); } return false; } function confirmDelete(_url) { Swal.fire({ title: 'Confirm', text: "Are you sure you want to delete it?", icon: 'warning', showCancelButton: true, confirmButtonColor: '#ff4040', cancelButtonColor: '#808080', confirmButtonText: 'Yes, delete it!' }).then((result) => { if (result.isConfirmed) { window.location.href = _url; } }); return false; } function confirmAction(_url) { Swal.fire({ title: 'Confirm', text: "Are you sure you want to perform this action?", icon: 'warning', showCancelButton: true, confirmButtonColor: '#ff4040', cancelButtonColor: '#808080', confirmButtonText: 'Yes, Do it!' }).then((result) => { if (result.isConfirmed) { window.location.href = _url; } }); return false; } function confirmActionWithMessage(_url, _msg) { Swal.fire({ title: 'Confirm', text: _msg, icon: 'warning', showCancelButton: true, confirmButtonColor: '#ff4040', cancelButtonColor: '#808080', confirmButtonText: 'Yes, Do it!' }).then((result) => { if (result.isConfirmed) { window.location.href = _url; } }); return false; } function confirmUpdateApiKey() { Swal.fire({ title: 'Update API Key', text: "Are you sure you want to update your API key? This action cannot be undone.", icon: 'warning', showCancelButton: true, confirmButtonColor: '#ff4040', cancelButtonColor: '#808080', confirmButtonText: 'Yes, Update Key', cancelButtonText: 'Cancel', }).then((result) => { if (result.isConfirmed) { window.location.href = '/coupon/update_key'; } }); return false; } function confirmUnfollow(uid) { Swal.fire({ title: 'Confirm', text: "Are you sure you want to unfollow this member?", icon: 'warning', showCancelButton: true, confirmButtonColor: '#ff4040', cancelButtonColor: '#808080', confirmButtonText: 'Yes, I confirm it!' }).then((result) => { if (result.isConfirmed) { window.location.href = '/account/unfollow?uid=' + uid; } }); return false; } function showError(msg) { Swal.fire({ title: '', text: msg, icon: 'warning', showCancelButton: false, cancelButtonColor: '#808080', confirmButtonText: 'OK' }).then((result) => { }); return false; } function showSuccess(msg, _url) { Swal.fire({ title: 'Success', text: msg, icon: 'success', showCancelButton: false, cancelButtonColor: '#808080', confirmButtonText: 'OK' }).then((result) => { if (result.isConfirmed && _url != '') { window.location.href = _url; } }); return false; } function showErrorRedirect(msg, _url) { Swal.fire({ title: 'Error', text: msg, icon: 'warning', showCancelButton: false, cancelButtonColor: '#808080', confirmButtonText: 'OK' }).then((result) => { if (result.isConfirmed && _url != '') { window.location.href = _url; } }); return false; } function showQuestionSubmissionConfirmation() { return Swal.fire({ title: 'Confirm', html: "Please note: After you submit your question, you'll not be able to edit it. You can only delete it if needed. Are you sure you want to submit your question?", icon: 'warning', showCancelButton: true, confirmButtonColor: '#3085d6', cancelButtonColor: '#808080', confirmButtonText: 'Yes, submit it!', cancelButtonText: 'No, I need to edit' }).then((result) => { if (result.isConfirmed) { return true; } else { return false; } }); } function showLeaveForumConfirmation(_url) { console.log(_url); return Swal.fire({ title: 'Confirm', html: "Are you sure you want to leave this forum?", icon: 'warning', showCancelButton: true, confirmButtonColor: '#3085d6', cancelButtonColor: '#808080', confirmButtonText: 'Yes, submit it!', cancelButtonText: 'Cancel' }).then((result) => { if (result.isConfirmed) { window.location.href = _url; return true; } else { return false; } }); } function showLoadingModal() { Swal.fire({ title: 'Loading...', html: 'Please wait', allowOutsideClick: false, didOpen: () => { Swal.showLoading(); } }); } function hideLoadingModal() { Swal.close(); } function navigateTo(_url) { window.location.href = _url; return false; } function openWindow(_url) { window.open(_url, '_blank'); return false; } function addToFavorites(_id, _title) { $('#addfav').remove(); let formData = new FormData(); formData.append("guid_id", _id); formData.append("title", _title); showLoadingModal(); $.ajax({ url: '/ajax/addfav', method: 'POST', data: formData, processData: false, contentType: false, dataType: 'json', success: function (data) { hideLoadingModal(); if (data.result === "login") { window.location.href = '/site/login'; } else if (data.result === 'success') { showSuccess('Added to your favorites.', '') } else { showError(data.msg); } }, error: function (jqXHR, textStatus, errorThrown) { hideLoadingModal(); showError('An error occurred while posting your content.', 'error'); } }); return true; } function likeComment(_id) { let _title = $("input[name=com_title]").val(); let _count = $('.com_' + _id + ' .total_likes').data('value'); let _likes = ''; _count++; if (_count > 1) { _likes = _count + ' Likes'; } else { _likes = '1 Like'; } $('.com_' + _id + ' .total_likes').replaceWith(', ' + _likes + ''); $('.com_' + _id + ' .action_like').replaceWith(', Liked'); let formData = new FormData(); formData.append("com_id", _id); formData.append("title", _title); $.ajax({ url: '/ajax/like_comment', method: 'POST', data: formData, processData: false, contentType: false, dataType: 'json', success: function (data) { if (data.result === "login") { window.location.href = '/site/login'; } else if (data.result === 'limited') { window.location.href = '/site/socialactionlimit'; } else if (data.result === 'success') { console.log("Liked a comment."); } else { console.log(data.msg); } }, error: function (jqXHR, textStatus, errorThrown) { console.log('An error occurred while posting your content.'); } }); return false; } function addComment() { let _title = $("input[name=com_title]").val(); let _url = $("input[name=com_url]").val(); let _guid_id = $("input[name=com_guid_id]").val(); let _comment = $("textarea[name=comment]").val(); if (_comment.length < 20) { alert('Your comment is too short. Please provide a more detailed response.'); return; } showLoadingModal(); let formData = new FormData(); formData.append("guid_id", _guid_id); formData.append("title", _title); formData.append("comment", _comment); $.ajax({ url: '/ajax/add_comment', method: 'POST', data: formData, processData: false, contentType: false, dataType: 'json', success: function (data) { hideLoadingModal(); if (data.result === "login") { window.location.href = '/site/login'; } else if (data.result === 'limited') { window.location.href = '/site/socialactionlimit'; } else if (data.result === 'success') { showSuccess('Thanks for commenting', _url); } else { showError(data.msg); } }, error: function (jqXHR, textStatus, errorThrown) { hideLoadingModal(); showError('An error occurred while posting your content.'); } }); } function confirmDeleteComment(_com_id) { Swal.fire({ title: 'Confirm', text: "Are you sure you want to delete this comment?", icon: 'warning', showCancelButton: true, confirmButtonColor: '#ff4040', cancelButtonColor: '#808080', confirmButtonText: 'Yes, delete it!' }).then((result) => { if (result.isConfirmed) { onDeleteComment(_com_id); } }); return false; } function onDeleteComment(_com_id) { let formData = new FormData(); formData.append("com_id", _com_id); $.ajax({ url: '/ajax/del_comment', method: 'POST', data: formData, processData: false, contentType: false, dataType: 'json', success: function (data) { if (data.result === 'success') { $(".com_" + _com_id).remove(); } else { showError(data.msg); } }, error: function (jqXHR, textStatus, errorThrown) { showError('An error occurred while posting your content.'); } }); return false; } function onDeleteFeed(_id) { Swal.fire({ title: 'Confirm', text: "Are you sure you want to delete it?", icon: 'warning', showCancelButton: true, confirmButtonColor: '#ff4040', cancelButtonColor: '#808080', confirmButtonText: 'Yes, delete it!' }).then((result) => { if (result.isConfirmed) { deleteFeed(_id); } }); return false; } function deleteFeed(_id) { let formData = new FormData(); formData.append("id", _id); $.ajax({ url: '/ajax/delete_feed', method: 'POST', data: formData, processData: false, contentType: false, dataType: 'json', success: function (data) { if (data.result === "login") { window.location.href = '/site/login'; } else if (data.result === 'success') { $('.feed_'+_id).slideUp(200); } else { console.log(data.msg); } }, error: function (jqXHR, textStatus, errorThrown) { console.log('An error occurred while posting your content.'); } }); return false; } function onClaimMission(_formData) { if (bCheckSharing) { if(!bShared) { showError('You haven\'t shared the link yet. Please click one of the social media icons above to share.'); return false; } } console.log("onClaimMission"); showLoadingModal(); $.ajax({ url: '/ajax/claim_mission', method: 'POST', data: _formData, processData: false, contentType: false, dataType: 'json', success: function (data) { hideLoadingModal(); if (data.result === "login") { window.location.href = '/site/login'; } else if (data.result === 'success') { $('#btnClaimReward').hide(); showSuccess(data.msg, '/'); } else if (data.result == 'incomplete') { showError(data.msg); } else { showErrorRedirect(data.msg, '/'); } }, error: function (jqXHR, textStatus, errorThrown) { hideLoadingModal(); showError('An error occurred while posting your content.', 'error'); } }); return false; } function onClaimMission2(_title, _error) { // Show URL input modal Swal.fire({ title: 'Verify Mission Completion', html: `