2626 >
2727 <button
2828 :disabled =" room.connected && !room.owner"
29- class =" language random"
29+ class =" language random-btn "
3030 :class =" {'selected': language.index === null}"
31+ :style =" {'--col-span': randomBtnColSpan}"
3132 @click =" selectRandom"
3233 >
3334 <span class =" language-name" >
@@ -70,6 +71,7 @@ export default {
7071 return {
7172 searchText: ' ' ,
7273 forceStats: false ,
74+ randomBtnColSpan: 1 ,
7375 };
7476 },
7577 computed: {
@@ -85,6 +87,10 @@ export default {
8587 }
8688 return [... Array (29 )].map (() => ({ name: ' Loading...' }));
8789 },
90+ fillEmptyCellsReference () {
91+ // .bind spawns new reference and will not work with removeEventListener without saving it here
92+ return this .fillEmptyCells .bind (this );
93+ },
8894 },
8995 watch: {
9096 ' room.owner' : {
@@ -106,12 +112,18 @@ export default {
106112 }
107113 },
108114 },
115+ filteredList () {
116+ this .fillEmptyCells ();
117+ },
109118 },
110119 activated () {
111120 this .$store .commit (' ADD_TRACKED_CONTAINER' , this .$refs .languagesList );
121+ window .addEventListener (' resize' , this .fillEmptyCellsReference );
112122 },
113123 deactivated () {
114124 this .$store .commit (' REMOVE_TRACKED_CONTAINER' , this .$refs .languagesList .className );
125+ console .log (' DEACTIVATED' );
126+ window .removeEventListener (' resize' , this .fillEmptyCellsReference );
115127 },
116128 methods: {
117129 clear () {
@@ -147,6 +159,32 @@ export default {
147159 this .$nextTick (() => this .$socket .client .emit (' languageChange' , ev .target .getAttribute (' data-index' )));
148160 }
149161 },
162+ fillEmptyCells () {
163+ // randomBtn prevents shrinking
164+ this .randomBtnColSpan = 1 ;
165+
166+ this .$nextTick (() => {
167+ const gridComputedStyle = window .getComputedStyle (this .$refs .languagesList );
168+ console .warn (gridComputedStyle .getPropertyValue (' grid-template-columns' ));
169+
170+ const columns = gridComputedStyle .getPropertyValue (' grid-template-columns' )
171+ .replace (/ 0px/ g , ' ' ) // webkit bug return 0px for non existing columns
172+ .split (' ' ).length ;
173+
174+ console .log (` cells: ${ this .filteredList .length + 1 } ` );
175+ console .log (` columns: ${ columns} ` );
176+
177+ const mod = (this .filteredList .length + 1 ) % columns;
178+ console .log (` mod: ${ mod} ` );
179+
180+ if (mod) {
181+ const emptyCells = columns - mod;
182+ console .blue (emptyCells);
183+
184+ this .randomBtnColSpan = emptyCells + 1 ;
185+ }
186+ });
187+ },
150188 toggleStats () {
151189 this .forceStats = ! this .forceStats ;
152190 },
@@ -211,12 +249,15 @@ export default {
211249.language-radio
212250 display : none
213251
214- .showStats .language :hover:not (.random ), .forceStats .language :not (.random )
252+ .showStats .language :hover:not (.random-btn ), .forceStats .language :not (.random-btn )
215253 & > .language-name
216254 transform : translateX(-25% )
217255 & > .stat
218256 opacity : 1
219257
258+ .random-btn
259+ grid-column-start : span var(-- col- span)
260+
220261.language
221262 display : flex
222263 align-items : center
0 commit comments