@@ -148,19 +148,19 @@ private class Select1SearchCompanion(containerElem: html.Element) extends XBLCom
148
148
if (isDatabound) {
149
149
updateValueLabel()
150
150
updateOpenSelection()
151
- onAttributeChange(elementWithData, DataValue , updateValueLabel)
152
- onAttributeChange(elementWithData, DataLabel , updateValueLabel)
153
- onAttributeChange(elementWithData, DataIsOpenSelection , updateOpenSelection)
151
+ mutationObservers = DomSupport . onAttributeChange(elementWithData, DataValue , updateValueLabel) :: mutationObservers
152
+ mutationObservers = DomSupport . onAttributeChange(elementWithData, DataLabel , updateValueLabel) :: mutationObservers
153
+ mutationObservers = DomSupport . onAttributeChange(elementWithData, DataIsOpenSelection , updateOpenSelection) :: mutationObservers
154
154
} else {
155
155
// Register and remember listener on value change
156
156
val listener : js.Function = onXFormsSelect1ValueChange _
157
157
onXFormsSelect1ValueChangeJs = Some (listener)
158
158
Controls .afterValueChange.subscribe(listener)
159
159
}
160
160
161
- onAttributeChange(elementWithData, DataPlaceholder , updatePlaceholder)
161
+ mutationObservers = DomSupport .onAttributeChange(elementWithData, DataPlaceholder , updatePlaceholder) :: mutationObservers
162
+ mutationObservers = DomSupport .onElementAdded(containerElem, " .select2-selection__clear" , makeClearAccessible) :: mutationObservers
162
163
makeClearAccessible()
163
- onElementAdded(containerElem, " .select2-selection__clear" , makeClearAccessible)
164
164
165
165
// Workaround for Select2 not closing itself on click below the `<body>`
166
166
EventSupport .addListener(
@@ -281,34 +281,6 @@ private class Select1SearchCompanion(containerElem: html.Element) extends XBLCom
281
281
private def querySelect = containerElem.querySelector(" select" ).asInstanceOf [html.Select ]
282
282
private def servicePerformsSearch = Option (queryElementWithData.getAttribute(DataServicePerformsSearch )).contains(" true" )
283
283
284
- // TODO: not specific to the autocomplete, should be moved to a utility class
285
- private def onAttributeChange (element : dom.Element , attributeName : String , listener : () => Unit ): Unit = {
286
- val observer = new MutationObserver ((_, _) => listener())
287
- mutationObservers = observer :: mutationObservers
288
-
289
- observer.observe(element, new MutationObserverInit {
290
- attributes = true
291
- attributeFilter = js.Array (attributeName)
292
- })
293
- }
294
-
295
- private def onElementAdded (container : dom.Element , selector : String , listener : () => Unit ): Unit = {
296
- val observer = new MutationObserver ((mutations, _) => {
297
- mutations.foreach { mutation =>
298
- mutation.addedNodes.foreach { node =>
299
- if (node.nodeType == dom.Node .ELEMENT_NODE && node.asInstanceOf [dom.Element ].matches(selector)) {
300
- listener()
301
- }
302
- }
303
- }
304
- })
305
- mutationObservers = observer :: mutationObservers
306
-
307
- val config = new MutationObserverInit { childList = true ; subtree = true }
308
- observer.observe(container, config)
309
- }
310
-
311
-
312
284
// For the non-databound case, when the value of the underlying dropdown changed, typically because it set based
313
285
// on that the server tells the client, tell the Select2 component that the value has changed
314
286
private def onXFormsSelect1ValueChange (event : js.Dynamic ): Unit = {
0 commit comments