code.gitea.io/gitea@v1.22.3/web_src/js/modules/fomantic/transition.js (about)

     1  import $ from 'jquery';
     2  
     3  export function initFomanticTransition() {
     4    const transitionNopBehaviors = new Set([
     5      'clear queue', 'stop', 'stop all', 'destroy',
     6      'force repaint', 'repaint', 'reset',
     7      'looping', 'remove looping', 'disable', 'enable',
     8      'set duration', 'save conditions', 'restore conditions',
     9    ]);
    10    // stand-in for removed transition module
    11    $.fn.transition = function (arg0, arg1, arg2) {
    12      if (arg0 === 'is supported') return true;
    13      if (arg0 === 'is animating') return false;
    14      if (arg0 === 'is inward') return false;
    15      if (arg0 === 'is outward') return false;
    16  
    17      let argObj;
    18      if (typeof arg0 === 'string') {
    19        // many behaviors are no-op now. https://fomantic-ui.com/modules/transition.html#/usage
    20        if (transitionNopBehaviors.has(arg0)) return this;
    21        // now, the arg0 is an animation name, the syntax: (animation, duration, complete)
    22        argObj = {animation: arg0, ...(arg1 && {duration: arg1}), ...(arg2 && {onComplete: arg2})};
    23      } else if (typeof arg0 === 'object') {
    24        argObj = arg0;
    25      } else {
    26        throw new Error(`invalid argument: ${arg0}`);
    27      }
    28  
    29      const isAnimationIn = argObj.animation?.startsWith('show') || argObj.animation?.endsWith(' in');
    30      const isAnimationOut = argObj.animation?.startsWith('hide') || argObj.animation?.endsWith(' out');
    31      this.each((_, el) => {
    32        let toShow = isAnimationIn;
    33        if (!isAnimationIn && !isAnimationOut) {
    34          // If the animation is not in/out, then it must be a toggle animation.
    35          // Fomantic uses computed styles to check "visibility", but to avoid unnecessary arguments, here it only checks the class.
    36          toShow = this.hasClass('hidden'); // maybe it could also check "!this.hasClass('visible')", leave it to the future until there is a real problem.
    37        }
    38        argObj.onStart?.call(el);
    39        if (toShow) {
    40          el.classList.remove('hidden');
    41          el.classList.add('visible', 'transition');
    42          if (argObj.displayType) el.style.setProperty('display', argObj.displayType, 'important');
    43          argObj.onShow?.call(el);
    44        } else {
    45          el.classList.add('hidden');
    46          el.classList.remove('visible'); // don't remove the transition class because the Fomantic animation style is `.hidden.transition`.
    47          el.style.removeProperty('display');
    48          argObj.onHidden?.call(el);
    49        }
    50        argObj.onComplete?.call(el);
    51      });
    52      return this;
    53    };
    54  }