You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Nov 19, 2024. It is now read-only.
Copy file name to clipboardExpand all lines: guides/v2.2/javascript-dev-guide/widgets/widget_loader.md
+74-3Lines changed: 74 additions & 3 deletions
Original file line number
Diff line number
Diff line change
@@ -6,13 +6,37 @@ title: Loader widget
6
6
7
7
## Overview
8
8
9
-
The Loader [widget](https://glossary.magento.com/widget) blocks page content (all content or a part of it). Its intended use is blocking content when an Ajax request is being sent. But it can be initialized for non-Ajax tasks as well.
9
+
The Loader [widget](https://glossary.magento.com/widget) blocks page content (all content or a part of it). Its intended use is blocking content when an Ajax request is being sent, but it can be initialized for non-Ajax tasks as well.
10
10
11
11
The Loader widget source is [lib/web/mage/loader.js].
12
12
13
13
## Initialize the loader widget {#loader_init}
14
14
15
-
The loader widget is initialized as described in [JavaScript initialization].
15
+
For information about how to initialize a widget in a JS component or `.phtml` template, see the [Initialize JavaScript][] topic.
16
+
17
+
The following example shows how to instantiate the Loader widget:
18
+
19
+
```javascript
20
+
$('#example').loader({
21
+
icon:'path to icon'
22
+
});
23
+
```
24
+
25
+
Where:
26
+
27
+
-`#element` is the selector of the element for Loader is initialized.
28
+
29
+
```html
30
+
<script>
31
+
require(['jquery', 'loader'], function ($) {
32
+
'use strict';
33
+
34
+
$('#example').loader({
35
+
icon:'path to icon'
36
+
});
37
+
});
38
+
</script>
39
+
```
16
40
17
41
## Options {#loader_options}
18
42
@@ -22,13 +46,15 @@ The loader widget has the following options:
22
46
-[texts](#l_texts)
23
47
24
48
### `icon` {#l_icon}
49
+
25
50
The URL to the loader image. This image is displayed when the widget is active; that is, between the `ajaxSend` and `ajaxComplete` events.
26
51
27
52
**Type**: String
28
53
29
54
**Default value**: No image by default.
30
55
31
56
### `template` {#l_template}
57
+
32
58
HTML wrapper for the output, or a DOM element selector.
33
59
34
60
**Default value**:
@@ -81,6 +107,7 @@ Loader is subscribed to the following events:
81
107
-[processStop](#l_processStop)
82
108
83
109
### `processStart` {#l_processStart}
110
+
84
111
Display the loader. Can be triggered on any page element.
85
112
86
113
Start show loading:
@@ -89,6 +116,16 @@ Start show loading:
89
116
$("body").trigger('processStart');
90
117
```
91
118
119
+
The following is an example of adding a callback to `processStart` event.
120
+
121
+
```javascript
122
+
varcallback=function () {
123
+
// do something before showing the loader
124
+
};
125
+
126
+
$("body").on('processStart', callback);
127
+
```
128
+
92
129
### `processStop` {#l_processStop}
93
130
Hide the loader. Can be triggered on any page element.
94
131
@@ -98,5 +135,39 @@ Stop show loading:
98
135
$("body").trigger('processStop');
99
136
```
100
137
138
+
The following is an example of adding a callback to a `processStop` event.
139
+
140
+
```javascript
141
+
varcallback=function () {
142
+
// do something before hiding the loader
143
+
};
144
+
145
+
$("body").on('processStop', callback);
146
+
```
147
+
148
+
## Code Sample
149
+
150
+
The following example shows the loader when a `processStart` event triggers for the `#loader-example` element.
Lorem ipsum dolor sit amet, consectetur adipisicing elit. Dignissimos itaque numquam placeat quam recusandae velit voluptas. Ad architecto asperiores eos eveniet id nostrum officiis saepe soluta totam voluptate! Debitis, quibusdam.
156
+
</div>
157
+
<script>
158
+
require(['jquery', 'loader', 'domReady!'], function ($) {
159
+
'use strict';
160
+
161
+
$('#loader-example').trigger('processStart');
162
+
});
163
+
</script>
164
+
```
165
+
166
+
## Result
167
+
168
+
The loader shows when a `processStart` event triggers for the `#loader-example` element.
0 commit comments