@@ -617,113 +617,7 @@ <h3>Stay Updated</h3>
617617 < script defer src ="js/projects/number-sliding-puzzle.js "> </ script >
618618 < script defer src ="js/projects/budget-tracker.js "> </ script >
619619 < script defer src ="js/projects/minesweeper.js "> </ script >
620- <!-- FIX: Project Modal Loading - DIRECT OVERRIDE -->
621- < script >
622- ( function ( ) {
623- console . log ( '🔧 Applying DIRECT project modal fix...' ) ;
624620
625- // Wait for project.js to be fully loaded
626- function waitForProjectJS ( ) {
627- if ( typeof getProjectHTML === 'function' && typeof initializeProject === 'function' ) {
628- console . log ( '✅ project.js loaded, applying fix...' ) ;
629- applyFix ( ) ;
630- } else {
631- console . log ( '⏳ Waiting for project.js...' ) ;
632- setTimeout ( waitForProjectJS , 200 ) ;
633- }
634- }
635-
636- function applyFix ( ) {
637- // Store original if exists
638- const originalOpen = window . openProjectSafe ;
639-
640- // Override openProjectSafe
641- window . openProjectSafe = function ( projectName , element ) {
642- console . log ( `📂 Opening project: ${ projectName } ` ) ;
643-
644- const modal = document . getElementById ( 'projectModal' ) ;
645- const modalBody = document . getElementById ( 'modalBody' ) ;
646-
647- if ( ! modal || ! modalBody ) {
648- console . error ( '❌ Modal elements not found' ) ;
649- return ;
650- }
651-
652- // Show loading
653- modalBody . innerHTML = `
654- <div style="text-align:center;padding:60px 20px;">
655- <div style="font-size:3rem;margin-bottom:20px;">⏳</div>
656- <h3 style="color:#e2e8f0;">Loading ${ projectName . replace ( / - / g, ' ' ) } ...</h3>
657- <div style="margin:20px auto;width:40px;height:40px;border:4px solid #1e293b;border-top-color:#a78bfa;border-radius:50%;animation:spin 0.8s linear infinite;"></div>
658- </div>
659- ` ;
660- modal . style . display = 'flex' ;
661-
662- // Add to recently viewed
663- let recentlyViewed = JSON . parse ( localStorage . getItem ( 'recentlyViewed' ) || '[]' ) ;
664- recentlyViewed = recentlyViewed . filter ( name => name !== projectName ) ;
665- recentlyViewed . unshift ( projectName ) ;
666- if ( recentlyViewed . length > 10 ) recentlyViewed . pop ( ) ;
667- localStorage . setItem ( 'recentlyViewed' , JSON . stringify ( recentlyViewed ) ) ;
668-
669- // Update counter
670- setTimeout ( ( ) => {
671- if ( window . updateRecentlyViewedCounter ) {
672- window . updateRecentlyViewedCounter ( ) ;
673- }
674- } , 100 ) ;
675-
676- // Load the project - USE THE CORRECT FUNCTIONS FROM project.js
677- setTimeout ( ( ) => {
678- try {
679- console . log ( `🔄 Calling getProjectHTML for: ${ projectName } ` ) ;
680-
681- // Get HTML from project.js
682- let htmlContent = getProjectHTML ( projectName ) ;
683-
684- if ( htmlContent && ! htmlContent . includes ( 'error-state' ) ) {
685- modalBody . innerHTML = htmlContent ;
686- console . log ( `✅ HTML loaded for: ${ projectName } ` ) ;
687-
688- // Initialize the project using project.js
689- setTimeout ( ( ) => {
690- console . log ( `🔄 Initializing: ${ projectName } ` ) ;
691- initializeProject ( projectName ) ;
692- } , 100 ) ;
693- } else {
694- // Fallback: Try to find render function
695- const renderFn = 'render' + projectName . split ( '-' ) . map ( w => w . charAt ( 0 ) . toUpperCase ( ) + w . slice ( 1 ) ) . join ( '' ) ;
696- if ( typeof window [ renderFn ] === 'function' ) {
697- modalBody . innerHTML = window [ renderFn ] ( ) ;
698- console . log ( `✅ Used fallback render function: ${ renderFn } ` ) ;
699- } else {
700- throw new Error ( `No render function found for ${ projectName } ` ) ;
701- }
702- }
703- } catch ( error ) {
704- console . error ( `❌ Error loading ${ projectName } :` , error ) ;
705- modalBody . innerHTML = `
706- <div style="text-align:center;padding:60px 20px;">
707- <div style="font-size:3rem;margin-bottom:20px;">🚀</div>
708- <h2 style="color:#e2e8f0;">${ projectName . replace ( / - / g, ' ' ) . toUpperCase ( ) } </h2>
709- <p style="color:#94a3b8;margin:10px 0 20px;">This project is coming soon!</p>
710- <button onclick="document.getElementById('projectModal').style.display='none'"
711- style="background:#a78bfa;color:white;border:none;padding:12px 32px;border-radius:50px;cursor:pointer;font-size:1rem;">
712- Close
713- </button>
714- </div>
715- ` ;
716- }
717- } , 300 ) ;
718- } ;
719-
720- console . log ( '✅ openProjectSafe overridden successfully!' ) ;
721- }
722-
723- // Start waiting for project.js
724- waitForProjectJS ( ) ;
725- } ) ( ) ;
726- </ script >
727621 < script >
728622 window . addEventListener ( 'DOMContentLoaded' , ( ) => {
729623 if ( typeof lucide !== 'undefined' ) lucide . createIcons ( ) ;
@@ -1576,143 +1470,107 @@ <h3>${project.title}</h3>
15761470 console . log ( '✅ Focus error fixed' ) ;
15771471 } , 100 ) ;
15781472 </ script >
1579- <!-- FIX: Project Modal Loading - Ensure project.js functions are available -->
1473+
1474+ <!-- FIX: Surprise Me Button - Enhanced Random Project Loading -->
15801475< script >
15811476( function ( ) {
1582- console . log ( '🔧 Applying modal fix...' ) ;
1477+ console . log ( '🎲 Enhancing Surprise Me button...' ) ;
1478+
1479+ // Store reference to original function
1480+ const originalOpenProject = window . openProjectSafe ;
15831481
1584- function ensureProjectFunctions ( ) {
1585- if ( typeof getProjectHTML === 'function' && typeof initializeProject === 'function' ) {
1586- console . log ( '✅ Project functions available' ) ;
1587- return true ;
1482+ // Enhanced random project selector
1483+ function getRandomProject ( ) {
1484+ const projectCards = document . querySelectorAll ( '.project-card' ) ;
1485+ const visibleProjects = Array . from ( projectCards ) . filter ( card =>
1486+ card . style . display !== 'none'
1487+ ) ;
1488+
1489+ // If no visible projects, use all projects
1490+ const pool = visibleProjects . length > 0 ? visibleProjects : projectCards ;
1491+
1492+ if ( pool . length === 0 ) {
1493+ console . warn ( '⚠️ No projects available' ) ;
1494+ return null ;
15881495 }
1589- return false ;
1496+
1497+ const randomIndex = Math . floor ( Math . random ( ) * pool . length ) ;
1498+ const selectedCard = pool [ randomIndex ] ;
1499+ const projectName = selectedCard . getAttribute ( 'data-project' ) ;
1500+
1501+ console . log ( `🎲 Random project selected: ${ projectName } ` ) ;
1502+ return { name : projectName , element : selectedCard } ;
15901503 }
15911504
1592- function fixOpenProject ( ) {
1593- if ( ! ensureProjectFunctions ( ) ) {
1594- console . log ( '⏳ Waiting for project functions...' ) ;
1595- setTimeout ( fixOpenProject , 100 ) ;
1505+ // Override Surprise Me functionality
1506+ function handleSurpriseMe ( buttonElement ) {
1507+ const project = getRandomProject ( ) ;
1508+
1509+ if ( ! project ) {
1510+ // Show user-friendly message if no projects
1511+ const toast = document . createElement ( 'div' ) ;
1512+ toast . className = 'share-toast' ;
1513+ toast . textContent = 'No projects available. Try again!' ;
1514+ document . body . appendChild ( toast ) ;
1515+
1516+ setTimeout ( ( ) => {
1517+ toast . classList . add ( 'share-toast--visible' ) ;
1518+ setTimeout ( ( ) => {
1519+ toast . classList . remove ( 'share-toast--visible' ) ;
1520+ setTimeout ( ( ) => toast . remove ( ) , 300 ) ;
1521+ } , 2000 ) ;
1522+ } , 100 ) ;
15961523 return ;
15971524 }
15981525
1599- // Store original if exists
1600- const originalOpen = window . openProjectSafe ;
1526+ // Use the existing openProjectSafe function
1527+ if ( typeof originalOpenProject === 'function' ) {
1528+ originalOpenProject ( project . name , buttonElement || project . element ) ;
1529+ } else {
1530+ console . error ( '❌ openProjectSafe not found' ) ;
1531+ }
1532+ }
1533+
1534+ // Find all Surprise Me buttons
1535+ const surpriseButtons = document . querySelectorAll ( '#randomProjectBtn, #randomProjectBtnSidebar' ) ;
1536+
1537+ surpriseButtons . forEach ( button => {
1538+ // Remove existing listeners by cloning
1539+ const newButton = button . cloneNode ( true ) ;
1540+ button . parentNode . replaceChild ( newButton , button ) ;
16011541
1602- // Create new openProjectSafe
1603- window . openProjectSafe = function ( projectName , trigger ) {
1604- console . log ( `📂 Opening: ${ projectName } ` ) ;
1605-
1606- const modal = document . getElementById ( 'projectModal' ) ;
1607- const modalBody = document . getElementById ( 'modalBody' ) ;
1608-
1609- if ( ! modal || ! modalBody ) {
1610- console . error ( '❌ Modal elements not found' ) ;
1611- if ( originalOpen ) originalOpen ( projectName , trigger ) ;
1612- return ;
1613- }
1542+ // Add enhanced click handler
1543+ newButton . addEventListener ( 'click' , function ( e ) {
1544+ e . preventDefault ( ) ;
1545+ e . stopPropagation ( ) ;
16141546
1615- // Show loading
1616- modalBody . innerHTML = `
1617- <div style="text-align:center;padding:60px 20px;color:#e2e8f0;">
1618- <div style="font-size:3rem;margin-bottom:20px;">⏳</div>
1619- <h3>Loading ${ projectName . replace ( / - / g, ' ' ) } ...</h3>
1620- <div style="margin:20px auto;width:40px;height:40px;border:4px solid #1e293b;border-top-color:#a78bfa;border-radius:50%;animation:spin 0.8s linear infinite;"></div>
1621- </div>
1622- ` ;
1623- modal . style . display = 'flex' ;
1624- modal . classList . add ( 'active' ) ;
1625- document . body . style . overflow = 'hidden' ;
1626-
1627- // Add to recently viewed
1628- let recentlyViewed = JSON . parse ( localStorage . getItem ( 'recentlyViewed' ) || '[]' ) ;
1629- recentlyViewed = recentlyViewed . filter ( name => name !== projectName ) ;
1630- recentlyViewed . unshift ( projectName ) ;
1631- if ( recentlyViewed . length > 10 ) recentlyViewed . pop ( ) ;
1632- localStorage . setItem ( 'recentlyViewed' , JSON . stringify ( recentlyViewed ) ) ;
1633-
1634- // Update counter
1547+ // Add visual feedback
1548+ this . style . transform = 'scale(0.95)' ;
16351549 setTimeout ( ( ) => {
1636- if ( window . updateRecentlyViewedCounter ) {
1637- window . updateRecentlyViewedCounter ( ) ;
1638- }
1639- if ( window . updateRecentlyViewed ) {
1640- window . updateRecentlyViewed ( ) ;
1641- }
1642- } , 100 ) ;
1550+ this . style . transform = '' ;
1551+ } , 200 ) ;
16431552
1644- // Load project using project.js functions
1645- setTimeout ( ( ) => {
1646- try {
1647- console . log ( `🔄 Calling getProjectHTML for: ${ projectName } ` ) ;
1648-
1649- // Get HTML from project.js
1650- let htmlContent = getProjectHTML ( projectName ) ;
1651-
1652- if ( htmlContent && ! htmlContent . includes ( 'error-state' ) ) {
1653- modalBody . innerHTML = htmlContent ;
1654- console . log ( `✅ HTML loaded for: ${ projectName } ` ) ;
1655-
1656- // Initialize the project
1657- setTimeout ( ( ) => {
1658- console . log ( `🔄 Initializing: ${ projectName } ` ) ;
1659- if ( typeof initializeProject === 'function' ) {
1660- initializeProject ( projectName ) ;
1661- }
1662-
1663- // Try to find and setup info button
1664- const infoBtn = modalBody . querySelector ( '.inline-info-btn' ) ;
1665- if ( infoBtn && typeof getProjectInstructions === 'function' ) {
1666- const projectNameForInfo = modalBody . closest ( '.project-content' ) ?. getAttribute ( 'data-project' ) || projectName ;
1667- const info = getProjectInstructions ( projectNameForInfo ) ;
1668- if ( info && typeof showInfoModal === 'function' ) {
1669- infoBtn . addEventListener ( 'click' , function ( e ) {
1670- e . stopPropagation ( ) ;
1671- showInfoModal ( info . title , info . steps ) ;
1672- } ) ;
1673- }
1674- }
1675- } , 100 ) ;
1676-
1677- } else {
1678- throw new Error ( 'Project content not available' ) ;
1679- }
1680- } catch ( error ) {
1681- console . error ( `❌ Error loading ${ projectName } :` , error ) ;
1682- modalBody . innerHTML = `
1683- <div style="text-align:center;padding:60px 20px;">
1684- <div style="font-size:4rem;margin-bottom:1rem;">🚀</div>
1685- <h2 style="color:#e2e8f0;margin-bottom:0.5rem;">${ projectName . replace ( / - / g, ' ' ) . toUpperCase ( ) } </h2>
1686- <p style="color:#94a3b8;margin-bottom:1.5rem;">This project is coming soon!</p>
1687- <button onclick="document.getElementById('projectModal').style.display='none';document.body.style.overflow='';"
1688- style="background:#a78bfa;color:white;border:none;padding:12px 32px;border-radius:50px;cursor:pointer;font-size:1rem;">
1689- Close
1690- </button>
1691- </div>
1692- ` ;
1693- }
1694- } , 300 ) ;
1695- } ;
1553+ handleSurpriseMe ( this ) ;
1554+ } ) ;
16961555
1697- console . log ( '✅ openProjectSafe fixed successfully!' ) ;
1698- }
1556+ console . log ( `✅ Surprise Me button enhanced: ${ newButton . id || 'unnamed' } ` ) ;
1557+ } ) ;
16991558
1700- // Start fix
1701- fixOpenProject ( ) ;
1559+ // Also handle stats card click for Surprise
1560+ const statsCards = document . querySelectorAll ( '.stats-card' ) ;
1561+ statsCards . forEach ( card => {
1562+ if ( card . getAttribute ( 'data-filter' ) === 'surprise' ) {
1563+ card . addEventListener ( 'click' , function ( e ) {
1564+ e . preventDefault ( ) ;
1565+ handleSurpriseMe ( this ) ;
1566+ } ) ;
1567+ }
1568+ } ) ;
17021569
1703- // Add spin animation if missing
1704- if ( ! document . getElementById ( 'spinStyle' ) ) {
1705- const style = document . createElement ( 'style' ) ;
1706- style . id = 'spinStyle' ;
1707- style . textContent = `
1708- @keyframes spin {
1709- to { transform: rotate(360deg); }
1710- }
1711- ` ;
1712- document . head . appendChild ( style ) ;
1713- }
1570+ console . log ( '✅ Surprise Me feature enhanced successfully!' ) ;
17141571} ) ( ) ;
17151572</ script >
1573+
17161574 <!-- Info Modal Popup -->
17171575 < div id ="infoModalOverlay " class ="info-modal-overlay ">
17181576 < div class ="info-modal-content ">
0 commit comments