Skip to content
This repository was archived by the owner on Nov 19, 2024. It is now read-only.

Commit 7b89085

Browse files
serhiyzhovnirjeff-matthews
authored andcommitted
Adjusted Loader widget documentation (#5230)
* Adjusted loader widget documentation * Adjusted the loader documentation Co-Authored-By: Yaroslav Rogoza <[email protected]> * Adjusted the loader widget documentation * Fix the issue with trailing spaces * Added the loader widget result
1 parent bbf80a0 commit 7b89085

File tree

2 files changed

+74
-3
lines changed

2 files changed

+74
-3
lines changed
15.7 KB
Loading

guides/v2.2/javascript-dev-guide/widgets/widget_loader.md

Lines changed: 74 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,37 @@ title: Loader widget
66

77
## Overview
88

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.
1010

1111
The Loader widget source is [lib/web/mage/loader.js].
1212

1313
## Initialize the loader widget {#loader_init}
1414

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+
```
1640

1741
## Options {#loader_options}
1842

@@ -22,13 +46,15 @@ The loader widget has the following options:
2246
- [texts](#l_texts)
2347

2448
### `icon` {#l_icon}
49+
2550
The URL to the loader image. This image is displayed when the widget is active; that is, between the `ajaxSend` and `ajaxComplete` events.
2651

2752
**Type**: String
2853

2954
**Default value**: No image by default.
3055

3156
### `template` {#l_template}
57+
3258
HTML wrapper for the output, or a DOM element selector.
3359

3460
**Default value**:
@@ -81,6 +107,7 @@ Loader is subscribed to the following events:
81107
- [processStop](#l_processStop)
82108

83109
### `processStart` {#l_processStart}
110+
84111
Display the loader. Can be triggered on any page element.
85112

86113
Start show loading:
@@ -89,6 +116,16 @@ Start show loading:
89116
$("body").trigger('processStart');
90117
```
91118

119+
The following is an example of adding a callback to `processStart` event.
120+
121+
```javascript
122+
var callback = function () {
123+
// do something before showing the loader
124+
};
125+
126+
$("body").on('processStart', callback);
127+
```
128+
92129
### `processStop` {#l_processStop}
93130
Hide the loader. Can be triggered on any page element.
94131

@@ -98,5 +135,39 @@ Stop show loading:
98135
$("body").trigger('processStop');
99136
```
100137

138+
The following is an example of adding a callback to a `processStop` event.
139+
140+
```javascript
141+
var callback = 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.
151+
152+
```html
153+
<div id="loader-example" data-mage-init='{"loader": { "icon": "{store URL}/static/{static version}/frontend/Magento/luma/en_US/images/loader-2.gif"}}'>
154+
<h3>Block</h3>
155+
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.
169+
170+
![Loader Widget Example]({{ site.baseurl }}/common/images/widget/loader-widget-result.png)
171+
101172
[lib/web/mage/loader.js]: {{ site.mage2bloburl }}/{{ page.guide_version }}/lib/web/mage/loader.js
102-
[JavaScript initialization]: {{page.baseurl}}/javascript-dev-guide/javascript/js_init.html
173+
[Initialize JavaScript]: {{page.baseurl}}/javascript-dev-guide/javascript/js_init.html

0 commit comments

Comments
 (0)