Warning: file_exists(): open_basedir restriction in effect. File(/bin/bash) is not within the allowed path(s): (/var/www/vhosts/nothing-news.de/:/tmp/) in /var/www/vhosts/nothing-news.de/wiki.nothing-news.de/w/includes/shell/CommandFactory.php on line 119
MediaWiki:Common.js: Difference between revisions - Nothing Wiki
Toggle menu
Toggle preferences menu
Toggle personal menu
Not logged in
Your IP address will be publicly visible if you make any edits.

MediaWiki:Common.js: Difference between revisions

MediaWiki interface page
No edit summary
No edit summary
Line 4: Line 4:


(function() {
(function() {
  'use strict';
   const tooltip = document.createElement('div');
   const tooltip = document.createElement('div');
  tooltip.id = 'mw-smart-tooltip';
   Object.assign(tooltip.style, {
   Object.assign(tooltip.style, {
     position: 'absolute',
     position: 'absolute',
Line 43: Line 40:
     const el = e.target.closest('[title]');
     const el = e.target.closest('[title]');
     if (!el) return;
     if (!el) return;
     storedTitle = el.getAttribute('title');
     storedTitle = el.getAttribute('title');
     if (!storedTitle) return;
     if (!storedTitle) return;


     activeEl = el;
     activeEl = el;
     el.removeAttribute('title'); // native verhindern
     el.removeAttribute('title');


    // Tooltip vorbereiten, aber noch unsichtbar
     tooltip.textContent = storedTitle;
     tooltip.textContent = storedTitle;
     tooltip.appendChild(arrow);
     tooltip.appendChild(arrow);
     tooltip.style.opacity = '0';
     tooltip.style.opacity = '0';
    tooltip.style.transform = 'translateY(0)';


     // Force Reflow um korrekte Größe zu bekommen
     // Warten bis Browser die Größe kennt
     tooltip.getBoundingClientRect();
     requestAnimationFrame(() => {
      positionTooltip(el);
      tooltip.style.opacity = '1';
    });


     // Position berechnen
     el.addEventListener('mouseleave', hideTooltip, { once: true });
  }
 
  function hideTooltip() {
    if (!activeEl) return;
    tooltip.style.opacity = '0';
    activeEl.setAttribute('title', storedTitle);
    activeEl = null;
    storedTitle = null;
  }
 
  function positionTooltip(el) {
     const rect = el.getBoundingClientRect();
     const rect = el.getBoundingClientRect();
     const ttRect = tooltip.getBoundingClientRect();
     const ttRect = tooltip.getBoundingClientRect();
     const spacing = 6;
     const spacing = 6;
    let top, left;


     const spaceAbove = rect.top;
     let top = rect.bottom + spacing;
    const spaceBelow = window.innerHeight - rect.bottom;
     let left = rect.left + rect.width/2 - ttRect.width/2;
     const spaceRight = window.innerWidth - rect.right;
    const spaceLeft = rect.left;


     // Intelligente Position: genug Platz bevorzugen
     // Kollision mit Viewport
    let position = 'bottom';
     if (top + ttRect.height > window.innerHeight) {
     if (spaceAbove > ttRect.height + spacing) position = 'top';
       top = rect.top - ttRect.height - spacing; // nach oben
    else if (spaceRight > ttRect.width + spacing) position = 'right';
    else if (spaceLeft > ttRect.width + spacing) position = 'left';
 
    switch (position) {
       case 'top':
        top = rect.top - ttRect.height - spacing;
        left = rect.left + rect.width/2 - ttRect.width/2;
        Object.assign(arrow.style, {
          top: '100%',
          left: '50%',
          transform: 'translateX(-50%) rotate(0deg)',
          borderTopColor: 'rgba(20,20,20,0.95)',
        });
        break;
      case 'bottom':
        top = rect.bottom + spacing;
        left = rect.left + rect.width/2 - ttRect.width/2;
        Object.assign(arrow.style, {
          top: '-6px',
          left: '50%',
          transform: 'translateX(-50%) rotate(180deg)',
          borderTopColor: 'rgba(20,20,20,0.95)',
        });
        break;
      case 'right':
        top = rect.top + rect.height/2 - ttRect.height/2;
        left = rect.right + spacing;
        Object.assign(arrow.style, {
          top: '50%',
          left: '-6px',
          transform: 'translateY(-50%) rotate(90deg)',
          borderTopColor: 'rgba(20,20,20,0.95)',
        });
        break;
      case 'left':
        top = rect.top + rect.height/2 - ttRect.height/2;
        left = rect.left - ttRect.width - spacing;
        Object.assign(arrow.style, {
          top: '50%',
          left: '100%',
          transform: 'translateY(-50%) rotate(-90deg)',
          borderTopColor: 'rgba(20,20,20,0.95)',
        });
        break;
     }
     }
    // Clamp an Viewport
     if (left < 4) left = 4;
     if (left < 4) left = 4;
     if (left + ttRect.width > window.innerWidth - 4)
     if (left + ttRect.width > window.innerWidth - 4)
       left = window.innerWidth - ttRect.width - 4;
       left = window.innerWidth - ttRect.width - 4;
    if (top < 4) top = 4;
    if (top + ttRect.height > window.innerHeight - 4)
      top = window.innerHeight - ttRect.height - 4;


     tooltip.style.top = top + 'px';
     tooltip.style.top = `${top + window.scrollY}px`;
     tooltip.style.left = left + 'px';
     tooltip.style.left = `${left + window.scrollX}px`;
    tooltip.style.opacity = '1';


     // Verstecken bei Mouseleave
     // Pfeil positionieren (unten oder oben)
     el.addEventListener('mouseleave', hideTooltip, { once: true });
     if (top < rect.top) { // Tooltip oben
  }
      Object.assign(arrow.style, {
 
        top: '100%',
  function hideTooltip() {
        left: '50%',
    if (!activeEl) return;
        transform: 'translateX(-50%) rotate(0deg)',
    tooltip.style.opacity = '0';
      });
    activeEl.setAttribute('title', storedTitle);
    } else { // Tooltip unten
    activeEl = null;
      Object.assign(arrow.style, {
     storedTitle = null;
        top: '-6px',
        left: '50%',
        transform: 'translateX(-50%) rotate(180deg)',
      });
     }
   }
   }


   document.addEventListener('mouseover', showTooltip);
   document.addEventListener('mouseover', showTooltip);
})();
})();

Revision as of 23:52, 1 November 2025

/* Any JavaScript here will be loaded for all users on every page load. */
/* Schönes Tooltip-System auf Basis von alt-Attributen
   Funktioniert sicher mit Citizen & MediaWiki UI */

(function() {
  const tooltip = document.createElement('div');
  Object.assign(tooltip.style, {
    position: 'absolute',
    zIndex: 999999,
    background: 'rgba(20,20,20,0.95)',
    color: '#fff',
    padding: '8px 12px',
    borderRadius: '6px',
    fontSize: '13px',
    lineHeight: '1.4',
    maxWidth: '220px',
    wordWrap: 'break-word',
    pointerEvents: 'none',
    opacity: '0',
    transition: 'opacity 0.2s, transform 0.15s',
  });
  document.body.appendChild(tooltip);

  const arrow = document.createElement('div');
  Object.assign(arrow.style, {
    position: 'absolute',
    width: '0',
    height: '0',
    borderLeft: '6px solid transparent',
    borderRight: '6px solid transparent',
    borderTop: '6px solid rgba(20,20,20,0.95)',
    pointerEvents: 'none',
  });
  tooltip.appendChild(arrow);

  let activeEl = null;
  let storedTitle = null;

  function showTooltip(e) {
    const el = e.target.closest('[title]');
    if (!el) return;

    storedTitle = el.getAttribute('title');
    if (!storedTitle) return;

    activeEl = el;
    el.removeAttribute('title');

    tooltip.textContent = storedTitle;
    tooltip.appendChild(arrow);
    tooltip.style.opacity = '0';

    // Warten bis Browser die Größe kennt
    requestAnimationFrame(() => {
      positionTooltip(el);
      tooltip.style.opacity = '1';
    });

    el.addEventListener('mouseleave', hideTooltip, { once: true });
  }

  function hideTooltip() {
    if (!activeEl) return;
    tooltip.style.opacity = '0';
    activeEl.setAttribute('title', storedTitle);
    activeEl = null;
    storedTitle = null;
  }

  function positionTooltip(el) {
    const rect = el.getBoundingClientRect();
    const ttRect = tooltip.getBoundingClientRect();
    const spacing = 6;

    let top = rect.bottom + spacing;
    let left = rect.left + rect.width/2 - ttRect.width/2;

    // Kollision mit Viewport
    if (top + ttRect.height > window.innerHeight) {
      top = rect.top - ttRect.height - spacing; // nach oben
    }
    if (left < 4) left = 4;
    if (left + ttRect.width > window.innerWidth - 4)
      left = window.innerWidth - ttRect.width - 4;

    tooltip.style.top = `${top + window.scrollY}px`;
    tooltip.style.left = `${left + window.scrollX}px`;

    // Pfeil positionieren (unten oder oben)
    if (top < rect.top) { // Tooltip oben
      Object.assign(arrow.style, {
        top: '100%',
        left: '50%',
        transform: 'translateX(-50%) rotate(0deg)',
      });
    } else { // Tooltip unten
      Object.assign(arrow.style, {
        top: '-6px',
        left: '50%',
        transform: 'translateX(-50%) rotate(180deg)',
      });
    }
  }

  document.addEventListener('mouseover', showTooltip);
})();
Cookies help us deliver our services. By using our services, you agree to our use of cookies.