[ Mini Kiebo ]
Server: Windows NT AKFAR_SERVER 10.0 build 26200 (Windows 10) AMD64
Path:
D:
/
xampp
/
htdocs
/
repository_afbs
/
assets
/
js
/
[
Home
]
File: main.js
// ===== MAIN JAVASCRIPT ===== // Document Ready $(document).ready(function() { // Initialize tooltips var tooltipTriggerList = [].slice.call(document.querySelectorAll('[data-bs-toggle="tooltip"]')) var tooltipList = tooltipTriggerList.map(function (tooltipTriggerEl) { return new bootstrap.Tooltip(tooltipTriggerEl) }); // Initialize popovers var popoverTriggerList = [].slice.call(document.querySelectorAll('[data-bs-toggle="popover"]')) var popoverList = popoverTriggerList.map(function (popoverTriggerEl) { return new bootstrap.Popover(popoverTriggerEl) }); // Loading spinner $(document).ajaxStart(function() { $('#loading-spinner').fadeIn(); }).ajaxStop(function() { $('#loading-spinner').fadeOut(); }); // Scroll to top button $(window).scroll(function() { if ($(this).scrollTop() > 100) { $('.scroll-to-top').fadeIn().addClass('show'); } else { $('.scroll-to-top').fadeOut().removeClass('show'); } }); $('.scroll-to-top').click(function() { $('html, body').animate({scrollTop: 0}, 500); return false; }); // Auto-hide alerts $('.alert').not('.alert-permanent').delay(5000).slideUp(500); // Confirm delete $('.btn-delete').click(function(e) { if (!confirm('Apakah Anda yakin ingin menghapus data ini?')) { e.preventDefault(); } }); // Character counter $('textarea[data-maxlength]').each(function() { var maxlength = $(this).data('maxlength'); var counter = $('<div class="form-text text-muted text-end">0/' + maxlength + ' karakter</div>'); $(this).after(counter); $(this).on('input', function() { var length = $(this).val().length; counter.text(length + '/' + maxlength + ' karakter'); if (length > maxlength) { counter.addClass('text-danger'); } else { counter.removeClass('text-danger'); } }); }); // File input preview $('input[type="file"]').change(function(e) { var fileName = e.target.files[0].name; $(this).next('.custom-file-label').html(fileName); }); // Search auto-complete $('#search-input').autocomplete({ source: function(request, response) { $.ajax({ url: BASE_URL + '/modules/search/suggest.php', data: { term: request.term }, success: function(data) { response(data); } }); }, minLength: 3, select: function(event, ui) { window.location.href = BASE_URL + '/detail.php?id=' + ui.item.id; } }); // Filter toggle $('#filter-toggle').click(function() { $('#filter-panel').slideToggle(); $(this).find('i').toggleClass('fa-chevron-down fa-chevron-up'); }); // Statistics animation $('.stats-box h3').each(function() { var $this = $(this); var countTo = $this.text(); $({ countNum: 0 }).animate({ countNum: countTo }, { duration: 2000, easing: 'swing', step: function() { $this.text(Math.floor(this.countNum)); }, complete: function() { $this.text(this.countNum); } }); }); }); // ===== FUNCTIONS ===== // Show toast notification function showToast(message, type = 'success', title = 'Notification') { var toast = $('#toast-notification'); var toastTitle = $('#toast-title'); var toastMessage = $('#toast-message'); toast.removeClass('bg-success bg-danger bg-warning bg-info'); switch(type) { case 'success': toast.addClass('bg-success text-white'); break; case 'error': toast.addClass('bg-danger text-white'); break; case 'warning': toast.addClass('bg-warning'); break; case 'info': toast.addClass('bg-info text-white'); break; } toastTitle.text(title); toastMessage.text(message); $('#toast-time').text('Just now'); var bsToast = new bootstrap.Toast(toast); bsToast.show(); } // Copy to clipboard function copyToClipboard(text) { navigator.clipboard.writeText(text).then(function() { showToast('Copied to clipboard!', 'success'); }, function(err) { showToast('Failed to copy!', 'error'); }); } // Format number function formatNumber(num) { return num.toString().replace(/(\d)(?=(\d{3})+(?!\d))/g, '$1,'); } // Time ago function timeAgo(timestamp) { const now = new Date(); const past = new Date(timestamp); const diff = Math.floor((now - past) / 1000); if (diff < 60) return diff + ' seconds ago'; if (diff < 3600) return Math.floor(diff / 60) + ' minutes ago'; if (diff < 86400) return Math.floor(diff / 3600) + ' hours ago'; if (diff < 2592000) return Math.floor(diff / 86400) + ' days ago'; if (diff < 31536000) return Math.floor(diff / 2592000) + ' months ago'; return Math.floor(diff / 31536000) + ' years ago'; } // Debounce function function debounce(func, wait) { let timeout; return function executedFunction(...args) { const later = () => { clearTimeout(timeout); func(...args); }; clearTimeout(timeout); timeout = setTimeout(later, wait); }; } // Validate email function validateEmail(email) { const re = /^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/; return re.test(String(email).toLowerCase()); } // ===== AJAX REQUESTS ===== // Download counter function incrementDownload(thesisId) { $.ajax({ url: BASE_URL + '/modules/ajax/increment-download.php', method: 'POST', data: { id: thesisId }, success: function(response) { if (response.success) { $('#download-count-' + thesisId).text(response.total); } } }); } // View counter function incrementView(thesisId) { $.ajax({ url: BASE_URL + '/modules/ajax/increment-view.php', method: 'POST', data: { id: thesisId } }); } // ===== INITIALIZATION ===== // Set BASE_URL window.BASE_URL = '<?php echo defined('BASE_URL') ? BASE_URL : ''; ?>'; // Check if user is logged in window.isLoggedIn = <?php echo isset($_SESSION['user_id']) ? 'true' : 'false'; ?>; // Auto increment view on detail page if (window.location.pathname.includes('detail.php')) { const urlParams = new URLSearchParams(window.location.search); const thesisId = urlParams.get('id'); if (thesisId) { incrementView(thesisId); } }