Jump to content

MediaWiki:Common.js: Difference between revisions

The comprehensive free global encyclopedia of CEOs, corporate leadership, and business excellence
Updated to dynamically build 3D tag cloud from placeholder
Replaced with stylish weighted tag cloud - larger fonts for popular items, gradient colors, floating animations
Line 1: Line 1:
/* 3D Tag Cloud - Dynamic Builder */
/* Stylish Weighted Tag Cloud */
(function() {
(function() {
     if (typeof window.CEOTagCloudInit !== 'undefined') return;
     if (typeof window.CEOTagCloudInit !== 'undefined') return;
     window.CEOTagCloudInit = true;
     window.CEOTagCloudInit = true;


     function buildAndInitTagCloud() {
     function buildStylishTagCloud() {
         var placeholder = document.getElementById('ceo-tagcloud-placeholder');
         var placeholder = document.getElementById('ceo-tagcloud-placeholder');
         if (!placeholder) return;
         if (!placeholder) return;


         // Build the HTML structure
         // Tag data with weights (1-10, higher = more popular)
        var tagCloudHTML = '<div class="mp-card" style="margin-top: 1em;">' +
            '<div class="mp-card-title">Explore Popular Topics</div>' +
            '<div class="mp-card-content" style="padding: 2em 1em;">' +
            '<div style="text-align: center; margin-bottom: 1em; color: #54595d;">Interactive 3D cloud of most popular pages</div>' +
            '<div id="tagcloud-container" style="width: 100%; height: 350px; position: relative; perspective: 800px; background: radial-gradient(circle at center, #f8f9fa 0%, #e5e7eb 100%); border-radius: 12px; overflow: hidden; box-shadow: inset 0 2px 10px rgba(0, 0, 0, 0.05);">' +
            '<div id="tagcloud-sphere" style="position: absolute; width: 100%; height: 100%; transform-style: preserve-3d;"></div>' +
            '</div>' +
            '<div style="text-align: center; margin-top: 1em; font-size: 0.85em; color: #6b7280;"><em>Hover and move mouse to rotate</em></div>' +
            '</div></div>';
 
        placeholder.innerHTML = tagCloudHTML;
 
        // Tag data
         var tags = [
         var tags = [
             {text: 'Satya Nadella', href: '/wiki/Satya_Nadella', weight: 10},
             {text: 'Satya Nadella', href: '/wiki/Satya_Nadella', weight: 10},
            {text: 'Sundar Pichai', href: '/wiki/Sundar_Pichai', weight: 10},
             {text: 'Tim Cook', href: '/wiki/Tim_Cook', weight: 9},
             {text: 'Tim Cook', href: '/wiki/Tim_Cook', weight: 9},
            {text: 'Andy Jassy', href: '/wiki/Andy_Jassy', weight: 9},
             {text: 'Mary Barra', href: '/wiki/Mary_Barra', weight: 8},
             {text: 'Mary Barra', href: '/wiki/Mary_Barra', weight: 8},
             {text: 'Andy Jassy', href: '/wiki/Andy_Jassy', weight: 9},
             {text: 'Apple', href: '/wiki/Apple_Inc.', weight: 8},
             {text: 'Sundar Pichai', href: '/wiki/Sundar_Pichai', weight: 10},
             {text: 'Google', href: '/wiki/Google', weight: 8},
            {text: 'Tech CEOs', href: '/wiki/Category:Technology_CEOs', weight: 8},
            {text: 'Microsoft', href: '/wiki/Microsoft', weight: 7},
            {text: 'Amazon', href: '/wiki/Amazon', weight: 7},
            {text: 'American CEOs', href: '/wiki/Category:American_CEOs', weight: 7},
             {text: 'CEO Profiles', href: '/wiki/Category:Chief_executive_officers', weight: 7},
             {text: 'CEO Profiles', href: '/wiki/Category:Chief_executive_officers', weight: 7},
             {text: 'Companies', href: '/wiki/Category:Companies', weight: 6},
             {text: 'Companies', href: '/wiki/Category:Companies', weight: 6},
            {text: 'General Motors', href: '/wiki/General_Motors', weight: 6},
            {text: 'CEOs by Country', href: '/wiki/Category:CEOs_by_country', weight: 6},
            {text: 'Fortune 500', href: '/wiki/Category:Fortune_500_CEOs', weight: 6},
             {text: 'Business Strategy', href: '/wiki/Category:Business_strategies', weight: 5},
             {text: 'Business Strategy', href: '/wiki/Category:Business_strategies', weight: 5},
             {text: 'Governance', href: '/wiki/Category:Corporate_governance', weight: 5},
             {text: 'Governance', href: '/wiki/Category:Corporate_governance', weight: 5},
            {text: 'CEOs by Country', href: '/wiki/Category:CEOs_by_country', weight: 6},
            {text: 'American CEOs', href: '/wiki/Category:American_CEOs', weight: 7},
            {text: 'Tech CEOs', href: '/wiki/Category:Technology_CEOs', weight: 8},
            {text: 'Random', href: '/wiki/Special:Random', weight: 4},
             {text: 'Industry Analysis', href: '/wiki/Category:Industry_analysis', weight: 5},
             {text: 'Industry Analysis', href: '/wiki/Category:Industry_analysis', weight: 5},
             {text: 'Microsoft', href: '/wiki/Microsoft', weight: 7},
             {text: 'Random Article', href: '/wiki/Special:Random', weight: 4}
             {text: 'Apple', href: '/wiki/Apple_Inc.', weight: 8},
        ];
             {text: 'Amazon', href: '/wiki/Amazon', weight: 7},
 
             {text: 'Google', href: '/wiki/Google', weight: 8},
        // Shuffle tags for visual variety
             {text: 'General Motors', href: '/wiki/General_Motors', weight: 6},
        for (var i = tags.length - 1; i > 0; i--) {
             {text: 'Fortune 500', href: '/wiki/Category:Fortune_500_CEOs', weight: 6}
            var j = Math.floor(Math.random() * (i + 1));
            var temp = tags[i];
            tags[i] = tags[j];
            tags[j] = temp;
        }
 
        // Color palettes based on weight
        var colorSchemes = [
             {gradient: 'linear-gradient(135deg, #667eea 0%, #764ba2 100%)', hover: '#667eea'}, // Purple
            {gradient: 'linear-gradient(135deg, #f093fb 0%, #f5576c 100%)', hover: '#f093fb'}, // Pink
             {gradient: 'linear-gradient(135deg, #4facfe 0%, #00f2fe 100%)', hover: '#4facfe'}, // Blue
            {gradient: 'linear-gradient(135deg, #43e97b 0%, #38f9d7 100%)', hover: '#43e97b'}, // Green
             {gradient: 'linear-gradient(135deg, #fa709a 0%, #fee140 100%)', hover: '#fa709a'}, // Orange
             {gradient: 'linear-gradient(135deg, #30cfd0 0%, #330867 100%)', hover: '#30cfd0'}, // Teal
             {gradient: 'linear-gradient(135deg, #a8edea 0%, #fed6e3 100%)', hover: '#a8edea'}, // Pastel
            {gradient: 'linear-gradient(135deg, #ff9a9e 0%, #fecfef 100%)', hover: '#ff9a9e'} // Rose
         ];
         ];
        var cloudHTML = '<div class="mp-card" style="margin-top: 1em;">' +
            '<div class="mp-card-title">Most Popular Topics</div>' +
            '<div class="mp-card-content" style="padding: 2em 1.5em;">' +
            '<div class="stylish-tag-cloud" id="stylish-tag-cloud"></div>' +
            '<div style="text-align: center; margin-top: 1.5em; padding-top: 1em; border-top: 2px solid #e5e7eb;">' +
            '<div style="font-size: 0.85em; color: #6b7280; margin-bottom: 0.5em;">Font size represents popularity</div>' +
            '<div style="font-size: 0.8em; color: #9ca3af;">Click any topic to explore</div>' +
            '</div>' +
            '</div></div>';
        placeholder.innerHTML = cloudHTML;
        var cloudContainer = document.getElementById('stylish-tag-cloud');
        if (!cloudContainer) return;


         // Create tag elements
         // Create tag elements
        var container = document.getElementById('tagcloud-sphere');
         tags.forEach(function(tag, index) {
        if (!container) return;
 
         tags.forEach(function(tag) {
             var a = document.createElement('a');
             var a = document.createElement('a');
             a.href = tag.href;
             a.href = tag.href;
             a.className = 'tag-item';
             a.className = 'stylish-tag';
            a.textContent = tag.text;
             a.setAttribute('data-weight', tag.weight);
             a.setAttribute('data-weight', tag.weight);
            a.textContent = tag.text;
            a.style.position = 'absolute';
            a.style.left = '50%';
            a.style.top = '50%';
            a.style.whiteSpace = 'nowrap';
            a.style.textDecoration = 'none';
            a.style.color = '#1e3a5c';
            a.style.fontWeight = '600';
            a.style.padding = '0.4em 0.8em';
            a.style.background = 'linear-gradient(135deg, #ffffff 0%, #f0f9ff 100%)';
            a.style.border = '2px solid #0066cc';
            a.style.borderRadius = '20px';
            a.style.cursor = 'pointer';
            a.style.userSelect = 'none';
            a.style.boxShadow = '0 2px 8px rgba(0, 102, 204, 0.2)';
            a.style.transition = 'all 0.3s ease';
              
              
             var fontSize = 0.9 + (tag.weight / 10) * 0.5;
            // Font size based on weight (0.8em to 2.5em)
             var fontSize = 0.8 + (tag.weight / 10) * 1.7;
             a.style.fontSize = fontSize + 'em';
             a.style.fontSize = fontSize + 'em';
              
              
             a.addEventListener('mouseenter', function() {
             // Assign color scheme
                this.style.background = 'linear-gradient(135deg, #0066cc 0%, #0052a3 100%)';
            var colorScheme = colorSchemes[index % colorSchemes.length];
                this.style.color = '#ffffff';
            a.style.background = colorScheme.gradient;
                this.style.transform = 'scale(1.2)';
            a.setAttribute('data-hover-color', colorScheme.hover);
                this.style.boxShadow = '0 4px 16px rgba(0, 102, 204, 0.4)';
                this.style.zIndex = '100';
            });
              
              
             a.addEventListener('mouseleave', function() {
             // Random animation delay for staggered floating effect
                this.style.background = 'linear-gradient(135deg, #ffffff 0%, #f0f9ff 100%)';
            var delay = Math.random() * 3;
                this.style.color = '#1e3a5c';
            a.style.animationDelay = delay + 's';
                this.style.transform = 'scale(1)';
                this.style.boxShadow = '0 2px 8px rgba(0, 102, 204, 0.2)';
                this.style.zIndex = 'auto';
            });
              
              
             container.appendChild(a);
             cloudContainer.appendChild(a);
         });
         });


         // 3D Animation Engine
         // Add hover interaction
         var elements = container.getElementsByClassName('tag-item');
         var tagElements = cloudContainer.getElementsByClassName('stylish-tag');
        var radius = 150;
         for (var i = 0; i < tagElements.length; i++) {
        var dtr = Math.PI / 180;
             (function(elem) {
        var mcList = [];
                 elem.addEventListener('mouseenter', function() {
        var active = false;
                    this.style.transform = 'scale(1.15) translateY(-5px)';
        var lasta = 0.5;
                    this.style.boxShadow = '0 10px 30px rgba(0, 0, 0, 0.25)';
        var lastb = 0.5;
                    this.style.zIndex = '100';
        var tspeed = 2;
                 });
        var size = 200;
        var mouseX = 0;
        var mouseY = 0;
       
        var sa, ca, sb, cb, sc, cc;
 
        // Initialize positions
         for (var i = 0; i < elements.length; i++) {
             var oTag = {};
            oTag.offsetWidth = elements[i].offsetWidth;
            oTag.offsetHeight = elements[i].offsetHeight;
            mcList.push(oTag);
        }
 
        sineCosine(0, 0, 0);
        positionAll();
 
        setInterval(update, 30);
 
        function update() {
            var a, b;
           
            if (active) {
                 a = (-Math.min(Math.max(-mouseY, -size), size) / radius) * tspeed;
                b = (Math.min(Math.max(-mouseX, -size), size) / radius) * tspeed;
            } else {
                a = lasta * 0.98;
                b = lastb * 0.98;
            }
 
            lasta = a;
            lastb = b;
 
            if (Math.abs(a) <= 0.01 && Math.abs(b) <= 0.01 && !active) {
                a = 0.3;
                b = 0.3;
            }
 
            sineCosine(a, b, 0);
           
            for (var i = 0; i < mcList.length; i++) {
                var rx1 = mcList[i].cx;
                var ry1 = mcList[i].cy * ca + mcList[i].cz * (-sa);
                var rz1 = mcList[i].cy * sa + mcList[i].cz * ca;
 
                var rx2 = rx1 * cb + rz1 * sb;
                var ry2 = ry1;
                var rz2 = rx1 * (-sb) + rz1 * cb;
 
                mcList[i].cx = rx2;
                mcList[i].cy = ry2;
                mcList[i].cz = rz2;
 
                var per = 350 / (350 + rz2);
                mcList[i].x = rx2 * per;
                mcList[i].y = ry2 * per;
                mcList[i].scale = per;
                mcList[i].alpha = per;
                mcList[i].alpha = (mcList[i].alpha - 0.6) * (10 / 6);
            }
 
            doPosition();
            depthSort();
        }
 
        function depthSort() {
            var aTmp = [];
            for (var i = 0; i < elements.length; i++) {
                aTmp.push(elements[i]);
                elements[i].cz = mcList[i].cz;
            }
 
            aTmp.sort(function(vItem1, vItem2) {
                if (vItem1.cz > vItem2.cz) return -1;
                else if (vItem1.cz < vItem2.cz) return 1;
                else return 0;
            });
 
            for (var i = 0; i < aTmp.length; i++) {
                aTmp[i].style.zIndex = i;
            }
        }
 
        function positionAll() {
            var phi, theta, max = mcList.length;
 
            for (var i = 0; i < max; i++) {
                phi = Math.acos(-1 + (2 * i) / max);
                theta = Math.sqrt(max * Math.PI) * phi;
 
                mcList[i].cx = radius * Math.cos(theta) * Math.sin(phi);
                mcList[i].cy = radius * Math.sin(theta) * Math.sin(phi);
                mcList[i].cz = radius * Math.cos(phi);
 
                elements[i].style.left = mcList[i].cx + container.offsetWidth / 2 - mcList[i].offsetWidth / 2 + 'px';
                 elements[i].style.top = mcList[i].cy + container.offsetHeight / 2 - mcList[i].offsetHeight / 2 + 'px';
            }
        }
 
        function doPosition() {
            var l = container.offsetWidth / 2;
            var t = container.offsetHeight / 2;
           
            for (var i = 0; i < mcList.length; i++) {
                var item = elements[i];
                var mc = mcList[i];
 
                item.style.left = mc.x + l - mc.offsetWidth / 2 + 'px';
                item.style.top = mc.y + t - mc.offsetHeight / 2 + 'px';
                  
                  
                 var baseSize = parseFloat(item.getAttribute('data-weight')) / 10;
                 elem.addEventListener('mouseleave', function() {
                item.style.fontSize = (0.9 + baseSize * 0.5) * mc.scale + 'em';
                    this.style.transform = 'scale(1) translateY(0)';
                item.style.opacity = Math.max(0.3, mc.alpha);
                    this.style.boxShadow = '0 4px 15px rgba(0, 0, 0, 0.15)';
             }
                    this.style.zIndex = 'auto';
                });
             })(tagElements[i]);
         }
         }
        function sineCosine(a, b, c) {
            sa = Math.sin(a * dtr);
            ca = Math.cos(a * dtr);
            sb = Math.sin(b * dtr);
            cb = Math.cos(b * dtr);
            sc = Math.sin(c * dtr);
            cc = Math.cos(c * dtr);
        }
        // Mouse interaction
        var containerElem = document.getElementById('tagcloud-container');
        containerElem.addEventListener('mouseover', function() {
            active = true;
        });
        containerElem.addEventListener('mouseout', function() {
            active = false;
        });
        containerElem.addEventListener('mousemove', function(ev) {
            var rect = containerElem.getBoundingClientRect();
            mouseX = ev.clientX - rect.left - containerElem.offsetWidth / 2;
            mouseY = ev.clientY - rect.top - containerElem.offsetHeight / 2;
        });
     }
     }


     if (document.readyState === 'loading') {
     if (document.readyState === 'loading') {
         document.addEventListener('DOMContentLoaded', buildAndInitTagCloud);
         document.addEventListener('DOMContentLoaded', buildStylishTagCloud);
     } else {
     } else {
         buildAndInitTagCloud();
         buildStylishTagCloud();
     }
     }
})();
})();

Revision as of 12:17, 19 October 2025

/* Stylish Weighted Tag Cloud */
(function() {
    if (typeof window.CEOTagCloudInit !== 'undefined') return;
    window.CEOTagCloudInit = true;

    function buildStylishTagCloud() {
        var placeholder = document.getElementById('ceo-tagcloud-placeholder');
        if (!placeholder) return;

        // Tag data with weights (1-10, higher = more popular)
        var tags = [
            {text: 'Satya Nadella', href: '/wiki/Satya_Nadella', weight: 10},
            {text: 'Sundar Pichai', href: '/wiki/Sundar_Pichai', weight: 10},
            {text: 'Tim Cook', href: '/wiki/Tim_Cook', weight: 9},
            {text: 'Andy Jassy', href: '/wiki/Andy_Jassy', weight: 9},
            {text: 'Mary Barra', href: '/wiki/Mary_Barra', weight: 8},
            {text: 'Apple', href: '/wiki/Apple_Inc.', weight: 8},
            {text: 'Google', href: '/wiki/Google', weight: 8},
            {text: 'Tech CEOs', href: '/wiki/Category:Technology_CEOs', weight: 8},
            {text: 'Microsoft', href: '/wiki/Microsoft', weight: 7},
            {text: 'Amazon', href: '/wiki/Amazon', weight: 7},
            {text: 'American CEOs', href: '/wiki/Category:American_CEOs', weight: 7},
            {text: 'CEO Profiles', href: '/wiki/Category:Chief_executive_officers', weight: 7},
            {text: 'Companies', href: '/wiki/Category:Companies', weight: 6},
            {text: 'General Motors', href: '/wiki/General_Motors', weight: 6},
            {text: 'CEOs by Country', href: '/wiki/Category:CEOs_by_country', weight: 6},
            {text: 'Fortune 500', href: '/wiki/Category:Fortune_500_CEOs', weight: 6},
            {text: 'Business Strategy', href: '/wiki/Category:Business_strategies', weight: 5},
            {text: 'Governance', href: '/wiki/Category:Corporate_governance', weight: 5},
            {text: 'Industry Analysis', href: '/wiki/Category:Industry_analysis', weight: 5},
            {text: 'Random Article', href: '/wiki/Special:Random', weight: 4}
        ];

        // Shuffle tags for visual variety
        for (var i = tags.length - 1; i > 0; i--) {
            var j = Math.floor(Math.random() * (i + 1));
            var temp = tags[i];
            tags[i] = tags[j];
            tags[j] = temp;
        }

        // Color palettes based on weight
        var colorSchemes = [
            {gradient: 'linear-gradient(135deg, #667eea 0%, #764ba2 100%)', hover: '#667eea'}, // Purple
            {gradient: 'linear-gradient(135deg, #f093fb 0%, #f5576c 100%)', hover: '#f093fb'}, // Pink
            {gradient: 'linear-gradient(135deg, #4facfe 0%, #00f2fe 100%)', hover: '#4facfe'}, // Blue
            {gradient: 'linear-gradient(135deg, #43e97b 0%, #38f9d7 100%)', hover: '#43e97b'}, // Green
            {gradient: 'linear-gradient(135deg, #fa709a 0%, #fee140 100%)', hover: '#fa709a'}, // Orange
            {gradient: 'linear-gradient(135deg, #30cfd0 0%, #330867 100%)', hover: '#30cfd0'}, // Teal
            {gradient: 'linear-gradient(135deg, #a8edea 0%, #fed6e3 100%)', hover: '#a8edea'}, // Pastel
            {gradient: 'linear-gradient(135deg, #ff9a9e 0%, #fecfef 100%)', hover: '#ff9a9e'}  // Rose
        ];

        var cloudHTML = '<div class="mp-card" style="margin-top: 1em;">' +
            '<div class="mp-card-title">Most Popular Topics</div>' +
            '<div class="mp-card-content" style="padding: 2em 1.5em;">' +
            '<div class="stylish-tag-cloud" id="stylish-tag-cloud"></div>' +
            '<div style="text-align: center; margin-top: 1.5em; padding-top: 1em; border-top: 2px solid #e5e7eb;">' +
            '<div style="font-size: 0.85em; color: #6b7280; margin-bottom: 0.5em;">Font size represents popularity</div>' +
            '<div style="font-size: 0.8em; color: #9ca3af;">Click any topic to explore</div>' +
            '</div>' +
            '</div></div>';

        placeholder.innerHTML = cloudHTML;

        var cloudContainer = document.getElementById('stylish-tag-cloud');
        if (!cloudContainer) return;

        // Create tag elements
        tags.forEach(function(tag, index) {
            var a = document.createElement('a');
            a.href = tag.href;
            a.className = 'stylish-tag';
            a.textContent = tag.text;
            a.setAttribute('data-weight', tag.weight);
            
            // Font size based on weight (0.8em to 2.5em)
            var fontSize = 0.8 + (tag.weight / 10) * 1.7;
            a.style.fontSize = fontSize + 'em';
            
            // Assign color scheme
            var colorScheme = colorSchemes[index % colorSchemes.length];
            a.style.background = colorScheme.gradient;
            a.setAttribute('data-hover-color', colorScheme.hover);
            
            // Random animation delay for staggered floating effect
            var delay = Math.random() * 3;
            a.style.animationDelay = delay + 's';
            
            cloudContainer.appendChild(a);
        });

        // Add hover interaction
        var tagElements = cloudContainer.getElementsByClassName('stylish-tag');
        for (var i = 0; i < tagElements.length; i++) {
            (function(elem) {
                elem.addEventListener('mouseenter', function() {
                    this.style.transform = 'scale(1.15) translateY(-5px)';
                    this.style.boxShadow = '0 10px 30px rgba(0, 0, 0, 0.25)';
                    this.style.zIndex = '100';
                });
                
                elem.addEventListener('mouseleave', function() {
                    this.style.transform = 'scale(1) translateY(0)';
                    this.style.boxShadow = '0 4px 15px rgba(0, 0, 0, 0.15)';
                    this.style.zIndex = 'auto';
                });
            })(tagElements[i]);
        }
    }

    if (document.readyState === 'loading') {
        document.addEventListener('DOMContentLoaded', buildStylishTagCloud);
    } else {
        buildStylishTagCloud();
    }
})();