@@ -110,22 +110,35 @@ Doo.define(
110
110
this . tbody . textContent = ''
111
111
}
112
112
113
+ isRowSelected ( elem ) {
114
+ return elem . classList . contains ( 'danger' )
115
+ }
113
116
swapRows ( ) {
114
- if ( this . data . rows . length > 998 ) {
115
- let node1 = this . tbody . firstChild . nextSibling ,
116
- node2 = node1 . nextSibling ,
117
- node998 = this . tbody . childNodes [ 998 ] ,
118
- node999 = node998 . nextSibling ,
119
- row1 = this . data . rows [ 1 ]
117
+ const A = 1 , B = 998
118
+ if ( this . data . rows . length > B ) {
120
119
121
- this . data . rows [ 1 ] = this . data . rows [ 998 ] ;
122
- this . data . rows [ 998 ] = row1
120
+ let a = this . tbody . childNodes [ A ] ,
121
+ b = this . tbody . childNodes [ B ] ,
122
+ row1 = this . data . rows [ 1 ]
123
123
124
- this . tbody . insertBefore ( node998 , node2 )
125
- this . tbody . insertBefore ( node1 , node999 )
124
+ this . data . rows [ A ] = this . data . rows [ B ] ;
125
+ this . data . rows [ B ] = row1
126
+
127
+ const selected1 = this . isRowSelected ( a )
128
+ const selected2 = this . isRowSelected ( b )
129
+ this . updateRow ( A , this . data . rows , this . tbody )
130
+ this . updateRow ( B , this . data . rows , this . tbody )
131
+
132
+ if ( selected1 ) {
133
+ this . select ( this . tbody . childNodes [ B ] )
134
+ }
135
+ if ( selected2 ) {
136
+ this . select ( this . tbody . childNodes [ A ] )
137
+ }
126
138
}
127
139
}
128
140
141
+
129
142
addEventListeners ( ) {
130
143
document . getElementById ( "main" ) . addEventListener ( 'click' , e => {
131
144
e . preventDefault ( )
0 commit comments