@@ -112,19 +112,6 @@ export class TableRowStrategy implements ITemplateStrategy {
112112
113113 static inject = [ DomHelper ] ;
114114
115- // tableCssReset = '\
116- // display: block;\
117- // width: auto;\
118- // height: auto;\
119- // margin: 0;\
120- // padding: 0;\
121- // border: none;\
122- // border-collapse: inherit;\
123- // border-spacing: 0;\
124- // background-color: transparent;\
125- // -webkit-border-horizontal-spacing: 0;\
126- // -webkit-border-vertical-spacing: 0;';
127-
128115 domHelper : DomHelper ;
129116
130117 constructor ( domHelper : DomHelper ) {
@@ -136,71 +123,39 @@ export class TableRowStrategy implements ITemplateStrategy {
136123 }
137124
138125 moveViewFirst ( view : View , topBuffer : Element ) : void {
139- const tbody = this . _getFirstTbody ( topBuffer . nextSibling as HTMLTableElement ) ;
140- const tr = tbody . firstChild ;
141- const firstElement = DOM . nextElementSibling ( tr ) ;
142- insertBeforeNode ( view , firstElement ) ;
126+ insertBeforeNode ( view , topBuffer . nextElementSibling ) ;
143127 }
144128
145129 moveViewLast ( view : View , bottomBuffer : Element ) : void {
146- const lastElement = this . getLastElement ( bottomBuffer ) . nextSibling ;
147- const referenceNode = lastElement . nodeType === 8 && ( lastElement as Comment ) . data === 'anchor' ? lastElement : lastElement ;
130+ const previousSibling = bottomBuffer . previousSibling ;
131+ const referenceNode = previousSibling . nodeType === 8 && ( previousSibling as Comment ) . data === 'anchor' ? previousSibling : bottomBuffer ;
148132 insertBeforeNode ( view , referenceNode as Element ) ;
149133 }
150134
151135 createTopBufferElement ( element : Element ) : HTMLElement {
152- const elementName = / ^ [ U O ] L $ / . test ( ( element . parentNode as Element ) . tagName ) ? 'li' : 'div' ;
153- const buffer = DOM . createElement ( elementName ) ;
154- const tableElement = this . getTable ( element ) ;
155- tableElement . parentNode . insertBefore ( buffer , tableElement ) ;
156- buffer . innerHTML = ' ' ;
157- return buffer ;
136+ // append tbody with empty row before the element
137+ return element . parentNode . insertBefore ( DOM . createElement ( 'tr' ) , element ) ;
158138 }
159139
160140 createBottomBufferElement ( element : Element ) : HTMLElement {
161- const elementName = / ^ [ U O ] L $ / . test ( ( element . parentNode as Element ) . tagName ) ? 'li' : 'div' ;
162- const buffer = DOM . createElement ( elementName ) ;
163- const tableElement = this . getTable ( element ) ;
164- tableElement . parentNode . insertBefore ( buffer , tableElement . nextSibling ) ;
165- return buffer ;
141+ return element . parentNode . insertBefore ( DOM . createElement ( 'tr' ) , element . nextSibling ) ;
166142 }
167143
168144 removeBufferElements ( element : Element , topBuffer : Element , bottomBuffer : Element ) : void {
169- topBuffer . parentNode . removeChild ( topBuffer ) ;
170- bottomBuffer . parentNode . removeChild ( bottomBuffer ) ;
145+ DOM . removeNode ( topBuffer ) ;
146+ DOM . removeNode ( bottomBuffer ) ;
171147 }
172148
173149 getFirstElement ( topBuffer : Element ) : Element {
174- const tbody = this . _getFirstTbody ( DOM . nextElementSibling ( topBuffer ) as HTMLTableElement ) ;
175- const tr = tbody . firstElementChild as HTMLTableRowElement ;
176- // since the buffer is outside table, first element _is_ first element.
177- return tr ;
150+ return topBuffer . nextElementSibling ;
178151 }
179152
180153 getLastElement ( bottomBuffer : Element ) : Element {
181- const tbody = this . _getLastTbody ( bottomBuffer . previousSibling as HTMLTableElement ) ;
182- return tbody . lastElementChild as HTMLTableRowElement ;
154+ return bottomBuffer . previousElementSibling ;
183155 }
184156
185157 getTopBufferDistance ( topBuffer : Element ) : number {
186- const tbody = this . _getFirstTbody ( topBuffer . nextSibling as HTMLTableElement ) ;
187- return this . domHelper . getElementDistanceToTopOfDocument ( tbody ) - this . domHelper . getElementDistanceToTopOfDocument ( topBuffer ) ;
188- }
189-
190- private _getFirstTbody ( tableElement : HTMLTableElement ) : HTMLTableSectionElement {
191- let child = tableElement . firstElementChild ;
192- while ( child !== null && child . tagName !== 'TBODY' ) {
193- child = child . nextElementSibling ;
194- }
195- return child . tagName === 'TBODY' ? child as HTMLTableSectionElement : null ;
196- }
197-
198- private _getLastTbody ( tableElement : HTMLTableElement ) : HTMLTableSectionElement {
199- let child = tableElement . lastElementChild ;
200- while ( child !== null && child . tagName !== 'TBODY' ) {
201- child = child . previousElementSibling ;
202- }
203- return child . tagName === 'TBODY' ? child as HTMLTableSectionElement : null ;
158+ return 0 ;
204159 }
205160
206161 /**
0 commit comments