@@ -17,15 +17,15 @@ new class App {
17
17
const nouns = [ "table" , "chair" , "house" , "bbq" , "desk" , "car" , "pony" , "cookie" , "sandwich" , "burger" , "pizza" , "mouse" , "keyboard" ] ;
18
18
const l1 = adjectives . length , l2 = colours . length , l3 = nouns . length ;
19
19
20
- const nt = Math . round ( n / 100 ) ;
21
- const itemTemplate = document . getElementById ( ' itemTemplate' ) . content . cloneNode ( true ) ;
22
-
20
+ const itemTemplate = document . getElementById ( 'itemTemplate' ) . content ; // .cloneNode(true );
21
+ const nt = Math . max ( itemTemplate . children . length , n / 100 ) ; // Math.round(n / 50 );
22
+
23
23
while ( nt >= itemTemplate . children . length * 2 ) itemTemplate . appendChild ( itemTemplate . cloneNode ( true ) ) ;
24
24
while ( nt > itemTemplate . children . length ) itemTemplate . appendChild ( itemTemplate . firstElementChild . cloneNode ( true ) ) ;
25
25
26
26
const ids = Array . prototype . map . call ( itemTemplate . querySelectorAll ( 'td:first-child' ) , i => i . firstChild )
27
27
const labels = Array . prototype . map . call ( itemTemplate . querySelectorAll ( 'a.lbl' ) , i => i . firstChild ) ;
28
-
28
+
29
29
let i , j = 0 , r1 , r2 , r3 ; ;
30
30
while ( ( n -= nt ) >= 0 ) {
31
31
for ( i = 0 ; i < nt ; i ++ , j ++ ) {
@@ -39,23 +39,18 @@ new class App {
39
39
}
40
40
} ;
41
41
update ( ) {
42
- const children = this . tbody . children , data = this . data ;
43
- let child , lbl ;
44
- for ( let i = 0 ; i < this . data . length ; i += 10 ) {
45
- child = children [ i ] ;
46
- if ( child . hasOwnProperty ( 'lbl' ) ) lbl = child . lbl ;
47
- else child . lbl = lbl = children [ i ] . querySelector ( 'a.lbl' ) . firstChild ;
48
- lbl . nodeValue = this . data [ i ] = `${ this . data [ i ] } !!!`
49
- }
42
+ const labels = this . tbody . querySelectorAll ( 'tr:nth-child(10n+1)>td>a.lbl' ) , length = labels . length , data = this . data ;
43
+ let i = 0 , lbl ; for ( lbl of labels ) { lbl . firstChild . nodeValue = data [ i ] += ' !!!' ; i += 10 }
50
44
} ;
51
45
clear ( ) { this . tbody . textContent = '' ; this . data = [ ] } ;
52
46
53
47
swaprows ( ) {
54
- if ( this . data . length < 999 ) return ; // nb: swap does not affect labels
55
- const first = this . tbody . firstChild , sec = first . nextSibling ,
56
- third = sec . nextSibling , c998 = this . tbody . children [ 998 ] ;
57
- this . tbody . insertBefore ( this . tbody . insertBefore ( sec , c998 ) && c998 , third ) ;
58
- const temp = this . data [ 1 ] ; this . data [ 1 ] = this . data [ 998 ] ; this . data [ 998 ] = temp ;
48
+ const tbody = this . tbody , data = this . data ;
49
+ if ( tbody . children . length < 999 ) return ;
50
+ const first = tbody . firstElementChild ;
51
+ [ data [ 1 ] , data [ 998 ] ] = [ data [ 998 ] , data [ 1 ] ] ;
52
+ tbody . insertBefore ( tbody . insertBefore ( first . nextElementSibling ,
53
+ tbody . children [ 998 ] ) . nextElementSibling , first . nextElementSibling ) ;
59
54
} ;
60
55
onclick ( ) {
61
56
let selected ;
0 commit comments