File tree Expand file tree Collapse file tree 3 files changed +14
-23
lines changed Expand file tree Collapse file tree 3 files changed +14
-23
lines changed Original file line number Diff line number Diff line change @@ -33,21 +33,19 @@ define([
33
33
}
34
34
35
35
/**
36
- * Searches for elements which has 'data-mage-init' attribute.
36
+ * Searches for elements with a 'data-mage-init' attribute.
37
37
*
38
- * @param {HTMLElement } [parent=document.body] - Optional node inside of which to perform search.
39
38
* @returns {Array } An array of elements with 'data-mage-init' attribute.
40
39
*/
41
- function getElems ( parent ) {
42
- var elems ;
40
+ function getElems ( ) {
41
+ var body = document . body ,
42
+ elems ;
43
43
44
- parent = parent || document . body ;
45
-
46
- elems = parent . querySelectorAll ( '[' + dataAttr + ']' ) ;
44
+ elems = body . querySelectorAll ( '[' + dataAttr + ']' ) ;
47
45
elems = _ . toArray ( elems ) ;
48
46
49
- if ( parent . hasAttribute ( dataAttr ) ) {
50
- elems . unshift ( parent ) ;
47
+ if ( body . hasAttribute ( dataAttr ) ) {
48
+ elems . unshift ( body ) ;
51
49
}
52
50
53
51
return elems ;
@@ -75,15 +73,13 @@ define([
75
73
/**
76
74
* Initializes components assigned to HTML elements via [data-mage-init].
77
75
*
78
- * @param {HTMLElement } [ctx=document.body] - Optional node to search inside.
79
- *
80
76
* @example Sample 'data-mage-init' declaration.
81
77
* data-mage-init='{"path/to/component": {"foo": "bar"}}'
82
78
*/
83
- apply : function ( ctx ) {
79
+ apply : function ( ) {
84
80
var virtual = processScripts ( ) ;
85
81
86
- getElems ( ctx )
82
+ getElems ( )
87
83
. map ( getData )
88
84
. concat ( virtual )
89
85
. forEach ( function ( item ) {
Original file line number Diff line number Diff line change @@ -64,14 +64,11 @@ define([
64
64
/**
65
65
* Searches for script tags whith a 'text/x-magento-init' type.
66
66
*
67
- * @param {HTMLElement } [parent=document.body] - Optional node inside of which to perform search.
68
67
* @returns {Array } An array of elements script nodes.
69
68
*/
70
- function getNodes ( parent ) {
69
+ function getNodes ( ) {
71
70
var elems ;
72
71
73
- parent = parent || document . body ;
74
-
75
72
elems = document . querySelectorAll ( scriptSelector ) ;
76
73
77
74
return _ . toArray ( elems ) ;
@@ -97,7 +94,6 @@ define([
97
94
* to a 'data-mage-init' attribute of an elemennt found by provided selector.
98
95
* Note: All found script nodes will be removed from DOM.
99
96
*
100
- * @param {HTMLElement } [ctx=document.body] - Optional node to search inside.
101
97
* @returns {Array } An array of components not assigned to the specific element.
102
98
*
103
99
* @example Sample declaration.
@@ -116,8 +112,8 @@ define([
116
112
* }
117
113
* }
118
114
*/
119
- return function ( ctx ) {
120
- getNodes ( ctx )
115
+ return function ( ) {
116
+ getNodes ( )
121
117
. map ( getNodeData )
122
118
. forEach ( function ( item ) {
123
119
_ . each ( item , processElems ) ;
Original file line number Diff line number Diff line change 3
3
* See COPYING.txt for license details.
4
4
*/
5
5
/*jshint eqnull:true browser:true expr:true */
6
- /*global require:true console:true*/
7
6
( function ( root , factory ) {
8
7
'use strict' ;
9
8
91
90
/**
92
91
* Init components inside of dynamically updated elements
93
92
*/
94
- $ ( 'body' ) . on ( 'contentUpdated' , function ( e ) {
93
+ $ ( 'body' ) . on ( 'contentUpdated' , function ( ) {
95
94
if ( mage ) {
96
- mage . apply ( e . target ) ;
95
+ mage . apply ( ) ;
97
96
}
98
97
} ) ;
99
98
You can’t perform that action at this time.
0 commit comments