summaryrefslogtreecommitdiffstats
path: root/src/selector.js
blob: 6ee1207203dc2bf5064620e616dbf64f6326528d (plain)
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
import { map } from './utils.js'
import { adopt } from './adopter.js'
import { registerMethods } from './methods.js'

// // Method for getting an element by id
// SVG.get = function (id) {
//   var node = document.getElementById(idFromReference(id) || id)
//   return SVG.adopt(node)
// }
//
// // Select elements by query string
// SVG.select = function (query, parent) {
//   return SVG.utils.map((parent || document).querySelectorAll(query), function (node) {
//     return SVG.adopt(node)
//   })
// }
//
// SVG.$$ = function (query, parent) {
//   return SVG.utils.map((parent || document).querySelectorAll(query), function (node) {
//     return SVG.adopt(node)
//   })
// }
//
// SVG.$ = function (query, parent) {
//   return SVG.adopt((parent || document).querySelector(query))
// }

export default function baseFind (query, parent) {
  return map((parent || document).querySelectorAll(query), function (node) {
    return adopt(node)
  })
}

// Scoped find method
export function find (query) {
  return baseFind(query, this.node)
}

registerMethods('Dom', { find })