-
-
Notifications
You must be signed in to change notification settings - Fork 44
Expand file tree
/
Copy pathtemplate-strategy-default.ts
More file actions
51 lines (43 loc) · 1.75 KB
/
template-strategy-default.ts
File metadata and controls
51 lines (43 loc) · 1.75 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import { IView, ITemplateStrategy } from './interfaces';
import { insertBeforeNode, getScrollerElement } from './utilities-dom';
import { DOM } from 'aurelia-pal';
/**
* A template strategy for any virtual repeat usage that is not placed on tr, tbody, li, dd
*/
export class DefaultTemplateStrategy implements ITemplateStrategy {
getScrollContainer(element: Element): HTMLElement {
return getScrollerElement(element);
}
moveViewFirst(view: IView, topBuffer: Element): void {
insertBeforeNode(view, DOM.nextElementSibling(topBuffer));
}
moveViewLast(view: IView, bottomBuffer: Element): void {
const previousSibling = bottomBuffer.previousSibling;
const referenceNode = previousSibling.nodeType === 8 && (previousSibling as Comment).data === 'anchor' ? previousSibling : bottomBuffer;
insertBeforeNode(view, referenceNode as Element);
}
createBuffers(element: Element): [HTMLElement, HTMLElement] {
const parent = element.parentNode;
return [
parent.insertBefore(DOM.createElement('div'), element),
parent.insertBefore(DOM.createElement('div'), element.nextSibling),
];
}
removeBuffers(el: Element, topBuffer: Element, bottomBuffer: Element): void {
const parent = el.parentNode;
if (parent.contains(topBuffer)) {
parent.removeChild(topBuffer);
}
if (parent.contains(bottomBuffer)) {
parent.removeChild(bottomBuffer);
}
}
getFirstElement(topBuffer: Element, bottomBuffer: Element): Element {
const firstEl = topBuffer.nextElementSibling;
return firstEl === bottomBuffer ? null : firstEl;
}
getLastElement(topBuffer: Element, bottomBuffer: Element): Element {
const lastEl = bottomBuffer.previousElementSibling;
return lastEl === topBuffer ? null : lastEl;
}
}