-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
53 lines (47 loc) · 1.06 KB
/
index.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
/**
* selectors-map
* Element selector manager
*
* Copyright 2013 Enrico Marino and Federico Spini
* MIT License
*/
/**
* Expose `selectors_map`
*/
module.exports = selectors_map;
/**
* @function selector_map
* @descriptiorn
* create an object of query selected elements
*
* @example
* //<div id="container">
* // <h1>hello</h1>
* // <div id="text">bla bla bla</div>
* // </div>
* var el = document.getElementById(container);
* var selectors = {
* "title": "h1"
* "text": "#text"
* };
* var map = selectors_map(el, selectors);
* // {
* // "title": <h1>hello</h1>,
* // "text": <div id="text">bla bla bla</div>
* // }
*
* @param {Element} el element
* @param {Object} selectors selectors
* @param {Object} [result] selectors map
* @return {Object} the selectors map
*/
function selectors_map (el, selectors, result) {
var result = result || {};
var selector;
var name;
for (name in selectors) {
selector = selectors[name];
result[name] = el.querySelector(selector);
}
return result;
}