/** * GitHub Code Viewer - Main JavaScript */ (function($) { 'use strict'; // GitHub Code Viewer Class class GitHubCodeViewer { constructor(element) { this.$element = $(element); this.repo = this.$element.data('repo'); this.theme = this.$element.data('theme'); this.showLineNumbers = this.$element.data('show-line-numbers'); this.initialFile = this.$element.data('initial-file'); this.files = []; this.openTabs = []; this.activeTab = null; this.fileCache = {}; this.activeRequests = []; // Track active AJAX requests this.currentPath = ''; // Track current folder path this.init(); } init() { this.bindEvents(); this.loadRepositoryFiles(); } bindEvents() { // Search functionality with debouncing let searchTimeout; this.$element.on('input', '.mcb-search-input', (e) => { clearTimeout(searchTimeout); searchTimeout = setTimeout(() => { this.filterFiles($(e.target).val()); }, 300); // Debounce for 300ms }); // File/folder selection this.$element.on('click', '.mcb-file-item', (e) => { const $item = $(e.currentTarget); const isFolder = $item.data('is-folder'); const path = $item.data('path'); if (isFolder) { // Navigate to folder this.loadRepositoryFiles(path); } else { // Load file this.loadFile(path); } }); // Tab management this.$element.on('click', '.mcb-tab', (e) => { const $tab = $(e.currentTarget); const filePath = $tab.data('path'); this.switchToTab(filePath); }); this.$element.on('click', '.mcb-tab-close', (e) => { e.stopPropagation(); const $tab = $(e.target).closest('.mcb-tab'); const filePath = $tab.data('path'); this.closeTab(filePath); }); // Copy button this.$element.on('click', '.mcb-copy-btn', (e) => { this.copyCode($(e.target)); }); // Home button - go to root this.$element.on('click', '.mcb-home-btn', () => { this.loadRepositoryFiles(''); // Load root }); // Refresh button this.$element.on('click', '.mcb-refresh-btn', () => { this.refreshFiles(); }); // Fullscreen toggle this.$element.on('click', '.mcb-fullscreen-btn', () => { this.toggleFullscreen(); }); } loadRepositoryFiles(path = '') { console.log('MCB: Loading repository files for:', this.repo, 'path:', path); const $fileList = this.$element.find('.mcb-file-list'); // Update current path this.currentPath = path; // Show loading indicator $fileList.html('