Skip to content

Commit e5e4c7d

Browse files
author
Null McNull
committed
feature: add custom data to start function
1 parent ef52151 commit e5e4c7d

File tree

3 files changed

+152
-100
lines changed

3 files changed

+152
-100
lines changed

README.md

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,9 +81,19 @@ The start method will start the user interface block. Because multiple user inte
8181

8282
**Arguments:**
8383

84-
* **message** (string)
85-
Indicates the message to be shown in the overlay. If none is provided, the default message from the configuration is used.
84+
* **messageOrOptions** | (string or object) | Either supply the message (string) to be show in the overlay or specify an object (see below) that will be merged/extended into the block ui instance state. If no argument is specified the default text message from the configuration is used.
8685

86+
```
87+
blockUI.start('My loading message ...'); // Start the block with the custom text message
88+
```
89+
90+
```
91+
blockUI.start({
92+
message: 'My loading message', // Text message to display
93+
myProperty: 'My value' // Any custom property that should be available in the template.
94+
// See the template configuration for more info.
95+
});
96+
```
8797
#### stop
8898
This will decrease the block count. The block will end if the count is 0.
8999

@@ -178,6 +188,14 @@ Specifies a custom template to use as the overlay.
178188

179189
// Provide a custom template to use
180190
blockUIConfig.template = '<pre><code>{{ state | json }}</code></pre>';
191+
192+
Any custom properties provided to the `start` method of the blockUI instance can be accessed via the `state` object. For example:
193+
194+
// Start a block with custom property values
195+
blockUI.start({ myProperty: 'My value' });
196+
197+
// Display the property value in the custom template.
198+
blockUIConfig.template = '<div>{{ state.myProperty }}</div>';
181199

182200
#### templateUrl
183201
Specifies a url to retrieve the template from. *The current release only works with pre-cached templates, which means that this url should be known in the $templateCache service of Angular. If you're using the grunt with html2js or angular-templates, which I highly recommend, you're already set.*

src/angular-block-ui/service.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
blkUI.factory('blockUI', function(blockUIConfig, $timeout, blockUIUtils, $document) {
22

33
var $body = $document.find('body');
4-
4+
5+
// These properties are not allowed to be specified in the start method.
6+
var reservedStateProperties = ['id', 'blockCount', 'blocking'];
7+
58
function BlockUI(id) {
69

710
var self = this;
@@ -25,6 +28,12 @@ blkUI.factory('blockUI', function(blockUIConfig, $timeout, blockUIUtils, $docume
2528
messageOrOptions = {
2629
message: messageOrOptions
2730
};
31+
} else {
32+
angular.forEach(reservedStateProperties, function(x) {
33+
if(messageOrOptions[x]) {
34+
throw new Error('The property ' + x + ' is reserved for the block state.');
35+
}
36+
});
2837
}
2938

3039
angular.extend(state, messageOrOptions);

0 commit comments

Comments
 (0)