@@ -25,41 +25,55 @@ export function initGiteaFomantic() {
2525 return escape ( text , preserveHTML ) + svg ( 'octicon-x' , 16 , `${ className . delete } icon` ) ;
2626 } ;
2727
28+ const transitionNopBehaviors = new Set ( [
29+ 'clear queue' , 'stop' , 'stop all' , 'destroy' ,
30+ 'force repaint' , 'repaint' , 'reset' ,
31+ 'looping' , 'remove looping' , 'disable' , 'enable' ,
32+ 'set duration' , 'save conditions' , 'restore conditions' ,
33+ ] ) ;
2834 // stand-in for removed transition module
29- $ . fn . transition = function ( arg ) {
30- if ( arg === 'is supported' ) return true ;
31- if ( arg === 'is animating' ) return false ;
32- if ( arg === 'is inward' ) return false ;
33- if ( arg === 'is outward' ) return false ;
34- if ( arg === 'stop all' ) return ;
35+ $ . fn . transition = function ( arg0 , arg1 , arg2 ) {
36+ if ( arg0 === 'is supported' ) return true ;
37+ if ( arg0 === 'is animating' ) return false ;
38+ if ( arg0 === 'is inward' ) return false ;
39+ if ( arg0 === 'is outward' ) return false ;
3540
36- const isIn = arg ?. animation ?. endsWith ( ' in' ) ;
37- const isOut = arg ?. animation ?. endsWith ( ' out' ) ;
41+ let argObj ;
42+ if ( typeof arg0 === 'string' ) {
43+ // many behaviors are no-op now. https://fomantic-ui.com/modules/transition.html#/usage
44+ if ( transitionNopBehaviors . has ( arg0 ) ) return this ;
45+ // now, the arg0 is an animation name, the syntax: (animation, duration, complete)
46+ argObj = { animation : arg0 , ...( arg1 && { duration : arg1 } ) , ...( arg2 && { onComplete : arg2 } ) } ;
47+ } else if ( typeof arg0 === 'object' ) {
48+ argObj = arg0 ;
49+ } else {
50+ throw new Error ( `invalid argument: ${ arg0 } ` ) ;
51+ }
3852
39- let ret ;
40- if ( arg === 'show' || isIn ) {
41- arg ?. onStart ?. ( this ) ;
42- ret = this . each ( ( _ , el ) => {
53+ const isAnimationIn = argObj . animation ?. startsWith ( 'show' ) || argObj . animation ?. endsWith ( ' in' ) ;
54+ const isAnimationOut = argObj . animation ?. startsWith ( 'hide' ) || argObj . animation ?. endsWith ( ' out' ) ;
55+ this . each ( ( _ , el ) => {
56+ let toShow = isAnimationIn ;
57+ if ( ! isAnimationIn && ! isAnimationOut ) {
58+ // If the animation is not in/out, then it must be a toggle animation.
59+ // Fomantic uses computed styles to check "visibility", but to avoid unnecessary arguments, here it only checks the class.
60+ toShow = this . hasClass ( 'hidden' ) ; // maybe it could also check "!this.hasClass('visible')", leave it to the future until there is a real problem.
61+ }
62+ argObj . onStart ?. call ( el ) ;
63+ if ( toShow ) {
4364 el . classList . remove ( 'hidden' ) ;
44- el . classList . add ( 'visible' ) ;
45- if ( isIn ) el . classList . add ( 'transition' ) ;
46- if ( arg ?. displayType ) el . style . setProperty ( 'display' , arg . displayType , 'important' ) ;
47- arg ?. onShow ?. ( this ) ;
48- } ) ;
49- arg ?. onComplete ?. ( this ) ;
50- } else if ( arg === 'hide' || isOut ) {
51- arg ?. onStart ?. ( this ) ;
52- ret = this . each ( ( _ , el ) => {
65+ el . classList . add ( 'visible' , 'transition' ) ;
66+ if ( argObj . displayType ) el . style . setProperty ( 'display' , argObj . displayType , 'important' ) ;
67+ argObj . onShow ?. call ( el ) ;
68+ } else {
5369 el . classList . add ( 'hidden' ) ;
54- el . classList . remove ( 'visible' ) ;
55- // don't remove the transition class because fomantic didn't do it either
70+ el . classList . remove ( 'visible' ) ; // don't remove the transition class because the Fomantic animation style is `.hidden.transition`.
5671 el . style . removeProperty ( 'display' ) ;
57- arg ?. onHidden ?. ( this ) ;
58- } ) ;
59- arg ?. onComplete ?. ( this ) ;
60- }
61-
62- return ret ;
72+ argObj . onHidden ?. call ( el ) ;
73+ }
74+ argObj . onComplete ?. call ( el ) ;
75+ } ) ;
76+ return this ;
6377 } ;
6478
6579 initFomanticApiPatch ( ) ;
0 commit comments