Skip to content

Commit ef52151

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

File tree

2 files changed

+50
-5
lines changed

2 files changed

+50
-5
lines changed

src/angular-block-ui/service.js

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,31 @@ blkUI.factory('blockUI', function(blockUIConfig, $timeout, blockUIUtils, $docume
1717

1818
this._refs = 0;
1919

20-
this.start = function(message) {
21-
20+
this.start = function(messageOrOptions) {
21+
22+
messageOrOptions = messageOrOptions || {};
23+
24+
if(angular.isString(messageOrOptions)) {
25+
messageOrOptions = {
26+
message: messageOrOptions
27+
};
28+
}
29+
30+
angular.extend(state, messageOrOptions);
31+
2232
if(state.blockCount > 0) {
23-
message = message || state.message || blockUIConfig.message;
33+
state.message = messageOrOptions.message || state.message || blockUIConfig.message;
2434
} else {
25-
message = message || blockUIConfig.message;
35+
state.message = messageOrOptions.message || blockUIConfig.message;
2636
}
37+
38+
// if(state.blockCount > 0) {
39+
// messageOrOptions = messageOrOptions || state.message || blockUIConfig.message;
40+
// } else {
41+
// messageOrOptions = messageOrOptions || blockUIConfig.message;
42+
// }
2743

28-
state.message = message;
44+
// state.message = messageOrOptions;
2945

3046
state.blockCount++;
3147

src/angular-block-ui/service.test.js

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -374,6 +374,35 @@ describe('block-ui-service', function() {
374374

375375
});
376376

377+
it('should set the message from the provided message option property', function() {
378+
379+
var customMessage = "My custom message ...";
380+
var state = blockUI.state();
381+
382+
blockUI.start({
383+
message: customMessage
384+
});
385+
386+
expect(state.message).toBe(customMessage);
387+
388+
});
389+
390+
it('should merge/extend custom properties', function() {
391+
392+
var myOptions = {
393+
data: {
394+
prop: 'someValue'
395+
}
396+
};
397+
398+
var state = blockUI.state();
399+
400+
blockUI.start(myOptions);
401+
402+
expect(state.data).toBe(myOptions.data);
403+
404+
});
405+
377406
}); // start
378407

379408
describe('stop', function() {

0 commit comments

Comments
 (0)