« MediaWiki:Common.js » : différence entre les versions
Page de l’interface de MediaWiki
Autres actions
minicard |
fallback |
||
| Ligne 268 : | Ligne 268 : | ||
maxColsByWidth = Math.max( 1, Math.min( maxColsByWidth, total ) ); | maxColsByWidth = Math.max( 1, Math.min( maxColsByWidth, total ) ); | ||
var bestCols = 1; | var bestCols = 1; | ||
for ( var n = 1; n <= maxColsByWidth; n++ ) { | for ( var n = 1; n <= maxColsByWidth; n++ ) { | ||
| Ligne 276 : | Ligne 275 : | ||
} | } | ||
if ( bestCols === 1 && maxColsByWidth > 1 ) { | if ( bestCols === 1 && maxColsByWidth > 1 ) { | ||
bestCols = maxColsByWidth; | bestCols = maxColsByWidth; | ||
| Ligne 290 : | Ligne 288 : | ||
var containerWidth = grid.offsetWidth; | var containerWidth = grid.offsetWidth; | ||
if ( containerWidth === 0 ) { | if ( containerWidth === 0 ) { | ||
requestAnimationFrame( function () { adjustGrid( grid ); } ); | requestAnimationFrame( function () { adjustGrid( grid ); } ); | ||
| Ligne 300 : | Ligne 296 : | ||
grid.style.gridTemplateColumns = 'repeat(' + bestCols + ', 1fr)'; | grid.style.gridTemplateColumns = 'repeat(' + bestCols + ', 1fr)'; | ||
var cardWidth = ( containerWidth - ( bestCols - 1 ) * GAP ) / bestCols; | var cardWidth = ( containerWidth - ( bestCols - 1 ) * GAP ) / bestCols; | ||
var rowHeight = cardWidth < 120 ? '48px' : cardWidth < 160 ? '52px' : '60px'; | var rowHeight = cardWidth < 120 ? '48px' : cardWidth < 160 ? '52px' : '60px'; | ||
| Ligne 308 : | Ligne 303 : | ||
} ); | } ); | ||
grid.classList.add( 'is-ready' ); | grid.classList.add( 'is-ready' ); | ||
} | } | ||
| Ligne 316 : | Ligne 310 : | ||
} | } | ||
/* Exécution | /* Exécution initiale */ | ||
if ( document.readyState === 'loading' ) { | if ( document.readyState === 'loading' ) { | ||
document.addEventListener( 'DOMContentLoaded', adjustAllGrids ); | document.addEventListener( 'DOMContentLoaded', adjustAllGrids ); | ||
| Ligne 323 : | Ligne 317 : | ||
} | } | ||
/* | /* Resize fenêtre */ | ||
var resizeTimer; | var resizeTimer; | ||
window.addEventListener( 'resize', function () { | window.addEventListener( 'resize', function () { | ||
clearTimeout( resizeTimer ); | clearTimeout( resizeTimer ); | ||
resizeTimer = setTimeout( adjustAllGrids, | resizeTimer = setTimeout( adjustAllGrids, 80 ); | ||
} ); | |||
/* Observer les changements de classe sur :root (changement de mode Citizen) */ | |||
var rootObserver = new MutationObserver( function ( mutations ) { | |||
mutations.forEach( function ( mutation ) { | |||
if ( mutation.attributeName === 'class' ) { | |||
/* Petit délai pour laisser Citizen appliquer ses styles */ | |||
setTimeout( adjustAllGrids, 150 ); | |||
} | |||
} ); | |||
} ); | |||
rootObserver.observe( document.documentElement, { | |||
attributes: true, | |||
attributeFilter: [ 'class' ] | |||
} ); | } ); | ||
}() ); | }() ); | ||