@@ -158,4 +158,49 export function locateNode(node: Node): | |||
|
158 | 158 | return next ? |
|
159 | 159 | [next, "before"] : |
|
160 | 160 | [node.parentNode, "last"]; |
|
161 | } | |
|
162 | ||
|
163 | export const placeAt = (node: Node, refNodeOrId: string | Node, position: DojoNodePosition) => { | |
|
164 | const collect = (collection: HTMLCollection) => { | |
|
165 | const items = []; | |
|
166 | for (let i = 0, n = collection.length; i < n; i++) { | |
|
167 | items.push(collection[i]); | |
|
168 | } | |
|
169 | return items; | |
|
170 | }; | |
|
171 | ||
|
172 | const startup = (node: Node) => { | |
|
173 | if (node.parentNode) { | |
|
174 | const parentWidget = registry.getEnclosingWidget(node.parentNode); | |
|
175 | if (parentWidget && parentWidget._started) | |
|
176 | return startupWidgets(node); | |
|
177 | } | |
|
178 | if (isInPage(node)) | |
|
179 | startupWidgets(node); | |
|
180 | }; | |
|
181 | ||
|
182 | const ref = typeof refNodeOrId == "string" ? document.getElementById(refNodeOrId) : refNodeOrId; | |
|
183 | if (!ref) | |
|
184 | return; | |
|
185 | ||
|
186 | const parent = ref.parentNode; | |
|
187 | ||
|
188 | if (typeof position == "number") { | |
|
189 | ||
|
190 | } else { | |
|
191 | switch(position) { | |
|
192 | case "before": | |
|
193 | if (parent) | |
|
194 | parent.insertBefore(node,ref); | |
|
195 | case "after": | |
|
196 | if (parent) | |
|
197 | parent.insertBefore(node, ref.nextSibling); | |
|
198 | } | |
|
199 | } | |
|
200 | ||
|
201 | const startupPending = isDocumentFragmentNode(node) ? collect(node.children) : [node]; | |
|
202 | ||
|
203 | dom.place(node, refNodeOrId, position); | |
|
204 | ||
|
205 | startupPending.forEach(startup); | |
|
161 | 206 | } No newline at end of file |
General Comments 0
You need to be logged in to leave comments.
Login now