Skip to content

Commit 83eb27e

Browse files
author
Null McNull
committed
blockUI instance is not a number
1 parent 04d45c7 commit 83eb27e

File tree

11 files changed

+758
-10
lines changed

11 files changed

+758
-10
lines changed

gulpfile.js

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ require('./gulp-tasks/index-task.js')(gulp);
2020
// - - - - 8-< - - - - - - - - - - - - - - - - - - -
2121
// Builds the whole kitchensink including example website
2222

23-
gulp.task('kitchensink', [ 'modules', 'bower', 'index' ], function () {
23+
gulp.task('kitchensink', [ 'modules', 'bower', 'index', 'sandbox' ], function () {
2424

2525
var path = require('path');
2626

@@ -31,6 +31,18 @@ gulp.task('kitchensink', [ 'modules', 'bower', 'index' ], function () {
3131

3232
// - - - - 8-< - - - - - - - - - - - - - - - - - - -
3333

34+
gulp.task('sandbox-clean', [ 'modules', 'bower' ], function () {
35+
return gulp.src(path.join(config.folders.dest, 'sandbox'))
36+
.pipe(clean());
37+
});
38+
39+
gulp.task('sandbox', [ 'sandbox-clean', 'modules', 'bower' ], function () {
40+
return gulp.src(path.join(config.folders.src, 'sandbox/**/*'))
41+
.pipe(gulp.dest(path.join(config.folders.dest, 'sandbox')));
42+
});
43+
44+
// - - - - 8-< - - - - - - - - - - - - - - - - - - -
45+
3446
gulp.task('test-run', ['angular-block-ui'], function () {
3547

3648
return gulp.src([
@@ -42,7 +54,7 @@ gulp.task('test-run', ['angular-block-ui'], function () {
4254
.pipe(karma({
4355
configFile: 'karma.conf.js',
4456
action: 'run'
45-
})).on('error', function(err) {
57+
})).on('error', function (err) {
4658
throw err;
4759
});
4860

@@ -57,10 +69,10 @@ gulp.task('test-watch', ['angular-block-ui'], function () {
5769
path.join(config.folders.dest, 'angular-block-ui/angular-block-ui-templates.js'),
5870
path.join(config.folders.src, 'angular-block-ui/**/*.js')
5971
])
60-
.pipe(karma({
61-
configFile: 'karma.conf.js',
62-
action: 'watch'
63-
}));
72+
.pipe(karma({
73+
configFile: 'karma.conf.js',
74+
action: 'watch'
75+
}));
6476

6577
});
6678

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,12 @@ blkUI.config(function($provide, $httpProvider) {
1111
blockUIConfig = blockUIConfig || $injector.get('blockUIConfig');
1212

1313
if (blockUIConfig.resetOnException) {
14-
blockUI = blockUI || $injector.get('blockUI');
15-
blockUI.instances.reset();
14+
try {
15+
blockUI = blockUI || $injector.get('blockUI');
16+
blockUI.instances.reset();
17+
} catch(ex) {
18+
console.log('Exception occured while handling exception :S', exception);
19+
}
1620
}
1721

1822
$delegate(exception, cause);

src/angular-block-ui/interceptor.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ blkUI.factory('blockUIHttpInterceptor', function($q, $injector, blockUIConfig, $
77
}
88

99
function stopBlockUI(config) {
10-
if (blockUIConfig.autoBlock && !config.$_noBlock && config.$_blocks) {
10+
if (blockUIConfig.autoBlock && (config && !config.$_noBlock && config.$_blocks)) {
1111
injectBlockUI();
1212
config.$_blocks.stop();
1313
}

src/angular-block-ui/service.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ blkUI.factory('blockUI', function(blockUIConfig, $timeout, blockUIUtils, $docume
1313
blocking: false
1414
}, startPromise, doneCallbacks = [];
1515

16+
this._id = id;
17+
1618
this._refs = 0;
1719

1820
this.start = function(message) {
@@ -134,6 +136,11 @@ blkUI.factory('blockUI', function(blockUIConfig, $timeout, blockUIUtils, $docume
134136
var instances = [];
135137

136138
instances.get = function(id) {
139+
140+
if(!isNaN(id)) {
141+
throw new Error('BlockUI id cannot be a number');
142+
}
143+
137144
var instance = instances[id];
138145

139146
if(!instance) {

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

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ describe('block-ui-service', function() {
7070

7171
});
7272

73-
describe('add', function() {
73+
describe('get', function() {
7474

7575
it('should add new block-ui instance', function() {
7676

@@ -95,6 +95,28 @@ describe('block-ui-service', function() {
9595

9696
});
9797

98+
it('should not allow numeric instance ids', function() {
99+
100+
var idString = '123', idInt = 123;
101+
var idStringException, idIntException;
102+
103+
try {
104+
blockUI.instances.get(idString);
105+
} catch(ex) {
106+
idStringException = ex;
107+
}
108+
109+
try {
110+
blockUI.instances.get(idInt);
111+
} catch(ex) {
112+
idIntException = ex;
113+
}
114+
115+
expect(idStringException).toBeDefined();
116+
expect(idIntException).toBeDefined();
117+
118+
});
119+
98120
});
99121

100122
describe('release', function() {

src/sandbox/destroy-bug/README.md

Whitespace-only changes.

src/sandbox/destroy-bug/index.html

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
<!DOCTYPE html>
2+
<html>
3+
4+
<head>
5+
<link data-require="[email protected]" data-semver="0.0.9" rel="stylesheet" href="https://cdn.rawgit.com/McNull/angular-inform/v0.0.9/dist/angular-inform.min.css" />
6+
<link data-require="bootstrap-css@*" data-semver="3.2.0" rel="stylesheet" href="//maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css" />
7+
<link data-require="angular-block-ui@*" data-semver="0.1.0-beta.3" rel="stylesheet" href="https://cdn.rawgit.com/McNull/angular-block-ui/v0.1.0-beta.3/dist/angular-block-ui.min.css" />
8+
<link rel="stylesheet" href="style.css" />
9+
<script data-require="[email protected].*" data-semver="1.2.22" src="https://code.angularjs.org/1.2.22/angular.js"></script>
10+
<!-- <script data-require="angular-block-ui@*" data-semver="0.1.0-beta.3" src="https://cdn.rawgit.com/McNull/angular-block-ui/v0.1.0-beta.3/dist/angular-block-ui.min.js"></script> -->
11+
<script src="/angular-block-ui/angular-block-ui.js"></script>
12+
<script data-require="[email protected]" data-semver="0.0.9" src="https://cdn.rawgit.com/McNull/angular-inform/v0.0.9/dist/angular-inform.min.js"></script>
13+
<script data-require="[email protected]" data-semver="0.0.1" src="https://cdn.rawgit.com/McNull/angular-response-lag/master/angular-response-lag.min.js"></script>
14+
<script src="script.js"></script>
15+
</head>
16+
17+
<body ng-app="myApp">
18+
<div inform class="inform-fixed"></div>
19+
<div class="jumbotron">
20+
<h1>Blocking Table Rows</h1>
21+
<p>With <a href="https://github.com/McNull/angular-block-ui" target="_blank">angular-block-ui</a>
22+
</p>
23+
</div>
24+
<div class="container container-border"
25+
ng-controller="PeopleCtrl"
26+
block-ui block-ui-pattern="/people-data.json/">
27+
<div ng-if="grid.items.length">
28+
<div my-pager page-count="grid.pager.count" page-index="grid.pager.index"></div>
29+
<div class="people-list">
30+
<table class="table">
31+
<tbody>
32+
<tr>
33+
<th>Id</th>
34+
<th>Name</th>
35+
<th>Lastname</th>
36+
<th>Email</th>
37+
<th></th>
38+
</tr>
39+
<tr ng-repeat="person in grid.items" block-ui="person{{ person.id }}">
40+
<td>{{ person.id }}</td>
41+
<td>{{ person.firstName }}</td>
42+
<td>{{ person.lastName }}</td>
43+
<td>{{ person.email }}</td>
44+
<td>
45+
<button class="btn btn-default" ng-click="click(person)">Click</button>
46+
</td>
47+
</tr>
48+
</tbody>
49+
</table>
50+
</div>
51+
</div>
52+
</div>
53+
</body>
54+
55+
</html>
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<div class="my-pager center-block">
2+
<ul class="pagination">
3+
<li><a href="#" ng-click="move(-1)">&laquo;</a>
4+
</li>
5+
<li ng-repeat="page in pages" ng-class="{ active: index() == page }">
6+
<a href="#" ng-click="index(page)">{{ page + 1 }}</a>
7+
</li>
8+
<li><a href="#" ng-click="move(1)">&raquo;</a>
9+
</li>
10+
</ul>
11+
</div>

0 commit comments

Comments
 (0)