1
1
import utils from './utils' ;
2
2
3
- const DC_ATTRIBUTE_COMPONENT = 'data-dc-component' ;
4
-
5
3
const DC_NAMESPACE = 'data-dc' ;
6
- const DC_NAMESPACED_ATTRIBUTE_OPTIONS = 'options' ;
7
4
const DC_NAMESPACED_ATTRIBUTE_REFERENCE = 'ref' ;
8
5
const DC_NAMESPACED_ATTRIBUTE_ID = 'id' ;
9
6
7
+ function getNamespacedAnchorAttribute ( namespace ) {
8
+ return `${ DC_NAMESPACE } -${ namespace } `
9
+ }
10
+
10
11
/**
11
12
* @param {HTMLElement } root
12
13
* @param {string } namespace
@@ -17,7 +18,7 @@ const DC_NAMESPACED_ATTRIBUTE_ID = 'id';
17
18
function findElementsForInit ( root , namespace , selector = null ) {
18
19
// by default we use namespace
19
20
if ( selector === null ) {
20
- selector = `[${ DC_ATTRIBUTE_COMPONENT } - ${ namespace } ]` ;
21
+ selector = `[${ getNamespacedAnchorAttribute ( namespace ) } ]` ;
21
22
}
22
23
23
24
let elements = [ ] ;
@@ -63,7 +64,7 @@ function scopedQuerySelectorAll(element, selector, namespace, id) {
63
64
* @return {Object }
64
65
*/
65
66
function getElementOptions ( element , namespace ) {
66
- return getElementAttributeAsObject ( element , getNamespacedAttributeName ( DC_NAMESPACED_ATTRIBUTE_OPTIONS , namespace ) ) || { } ;
67
+ return getElementAttributeAsObject ( element , getNamespacedAnchorAttribute ( namespace ) ) ;
67
68
}
68
69
69
70
/**
@@ -72,7 +73,7 @@ function getElementOptions(element, namespace) {
72
73
* @return {?Object }
73
74
*/
74
75
function getElementAttributeAsObject ( element , attribute ) {
75
- let result = null ;
76
+ let result = { } ;
76
77
const attributeValue = element . getAttribute ( attribute ) ;
77
78
if ( attributeValue ) {
78
79
try {
0 commit comments