-
Notifications
You must be signed in to change notification settings - Fork 1
/
html5geomap.domobserver.js
73 lines (57 loc) · 1.72 KB
/
html5geomap.domobserver.js
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
HTML5Geomap.DOMObserver = {}
HTML5Geomap.DOMObserver.observer = function(mutations) {
mutations.forEach(function(mutation) {
// TODO: mysteriously no muttaionRecord from leaflet's div elements?
console.log("MUTATION", mutation.type, mutation)
switch (mutation.target.nodeName) {
case "GEOMAP":
var geomap = HTML5Geomap.maps[mutation.target]
for (var i = 0; i < mutation.addedNodes.length; i++) {
var node = mutation.addedNodes[i]
switch (node.nodeName) {
case "MARKER":
var marker = new HTML5Geomap.Marker(node)
geomap.add(marker)
console.log("ADD MARKER", node, marker)
break
default:
console.log("UNSUPPORTED", node)
}
}
for (var i = 0; i < mutation.removedNodes.length; i++) {
var node = mutation.removedNodes[i]
switch (node.nodeName) {
case "MARKER":
var marker = node._geomap
geomap.remove(marker)
console.log("REMOVE MARKER", node, marker)
break
default:
console.log("UNSUPPORTED", node)
}
}
break
case "MARKER":
switch (mutation.type) {
case "attributes":
console.log("ATTR", mutation.attributeName, mutation.target.getAttribute(mutation.attributeName))
break
}
}
})
}
HTML5Geomap.DOMObserver.initialize = function(rootElem) {
var observer = new MutationObserver(HTML5Geomap.DOMObserver.observer)
// NOTE: not observing subtree
// TODO: filter out leaflet crap from subtree MutationRecords
var config = {
subtree: true,
attributes: true,
attributeOldValue: true,
childList: true,
characterData: true
}
observer.observe(rootElem, config)
}
// OLETETAAN ET ON YKS
HTML5Geomap.DOMObserver.initialize(document.querySelector("geomap"))