9
9
'use strict' ;
10
10
11
11
var scriptSelector = 'script[type="text/x-magento-init"]' ,
12
+ dataAttr = 'data-mage-init' ,
12
13
virtual = [ ] ;
13
14
14
15
/**
@@ -31,13 +32,13 @@ define([
31
32
* @param {HTMLElement } elem - Element whose data should be modified.
32
33
*/
33
34
function setData ( components , elem ) {
34
- var data = elem . getAttribute ( 'data-mage-init' ) ;
35
+ var data = elem . getAttribute ( dataAttr ) ;
35
36
36
37
data = ! ! data ? JSON . parse ( data ) : { } ;
37
38
data = $ . extend ( true , data , components ) ;
38
39
data = JSON . stringify ( data ) ;
39
40
40
- elem . setAttribute ( 'data-mage-init' , data ) ;
41
+ elem . setAttribute ( dataAttr , data ) ;
41
42
}
42
43
43
44
/**
@@ -91,39 +92,37 @@ define([
91
92
return JSON . parse ( data ) ;
92
93
}
93
94
94
- return {
95
- /**
96
- * Parses 'script' tags with a custom type attribute and moves it's data
97
- * to a 'data-mage-init' attribute of an elemennt found by provided selector.
98
- * Note: All found script nodes would be removed from DOM.
99
- *
100
- * @param {HTMLElement } [ctx=document.body] - Optional node to search inside.
101
- * @returns {Array } An array of components not assigned to the specific element.
102
- *
103
- * @example Sample declaration.
104
- * <script type="text/x-magento-init">
105
- * {
106
- * "body": {
107
- * "path/to/component": {"foo": "bar"}
108
- * }
109
- * }
110
- * </script>
111
- *
112
- * @example Providing data without selector.
113
- * {
114
- * "*": {
115
- * "path/to/component": {"bar": "baz"}
116
- * }
117
- * }
118
- */
119
- process : function ( ctx ) {
120
- getNodes ( ctx )
121
- . map ( getNodeData )
122
- . forEach ( function ( item ) {
123
- _ . each ( item , processElems ) ;
124
- } ) ;
125
-
126
- return virtual . splice ( 0 , virtual . length ) ;
127
- }
95
+ /**
96
+ * Parses 'script' tags with a custom type attribute and moves it's data
97
+ * to a 'data-mage-init' attribute of an elemennt found by provided selector.
98
+ * Note: All found script nodes will be removed from DOM.
99
+ *
100
+ * @param {HTMLElement } [ctx=document.body] - Optional node to search inside.
101
+ * @returns {Array } An array of components not assigned to the specific element.
102
+ *
103
+ * @example Sample declaration.
104
+ * <script type="text/x-magento-init">
105
+ * {
106
+ * "body": {
107
+ * "path/to/component": {"foo": "bar"}
108
+ * }
109
+ * }
110
+ * </script>
111
+ *
112
+ * @example Providing data without selector.
113
+ * {
114
+ * "*": {
115
+ * "path/to/component": {"bar": "baz"}
116
+ * }
117
+ * }
118
+ */
119
+ return function ( ctx ) {
120
+ getNodes ( ctx )
121
+ . map ( getNodeData )
122
+ . forEach ( function ( item ) {
123
+ _ . each ( item , processElems ) ;
124
+ } ) ;
125
+
126
+ return virtual . splice ( 0 , virtual . length ) ;
128
127
} ;
129
128
} ) ;
0 commit comments