Skip to content

Commit 7aedb36

Browse files
author
Null McNull
committed
feature: Bypass loading screen on some requests
McNull#3
1 parent 2813355 commit 7aedb36

File tree

17 files changed

+296
-189
lines changed

17 files changed

+296
-189
lines changed

README.md

Lines changed: 33 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,22 @@ A simple AngularJS module that allows you to block user interaction on AJAX requ
55
#### Dependencies
66
Besides AngularJS (~1.2.4), none.
77

8+
#### Installation
9+
Either copy the contents of the `package` directory of the [Github](https://github.com/McNull/angular-block-ui) project or install with _bower_ from the command line (**recommended**):
10+
11+
bower install angular-block-ui
12+
13+
Include both the JS and CSS file in your html:
14+
15+
<link rel="stylesheet" href="path-to-block-ui/angular-block-ui.min.css"/>
16+
<!-- After AngularJS -->
17+
<script src="path-to-block-ui/angular-block-ui.min.js"></script>
18+
Create a dependency on `blockUI` in your main Angular module:
19+
20+
angular.module('myApp', ['blockUI'])
21+
822
#### Usage
9-
By default the module will block the user interface on each pending request made from the browser. This behavior can be modified in the configuration.
23+
By default the module will block the user interface on each pending request made from the browser. This behaviour can be modified in the configuration.
1024

1125
It's also possible to do the blocking manually. The blockUI module exposes a service by the same name. Access to the service is gained by injecting it into your controller or directive:
1226

@@ -31,9 +45,9 @@ BlockUI service methods
3145
=======================
3246

3347
#### start
34-
The start method will start the user interface block. Because multiple user interface elements can request a user interface block at the same time, the service keeps track of the number of start calls. Each call to start() will increase the count and every call to stop() will decrease the value. Whenever the count reaches 0 the block will end.
48+
The start method will start the user interface block. Because multiple user interface elements can request a user interface block at the same time, the service keeps track of the number of start calls. Each call to `start()` will increase the count and every call to `stop()` will decrease the value. Whenever the count reaches 0 the block will end.
3549

36-
*Note: By default the block is immediately active after calling this method, but to prevent trashing the user interface everytime a button is pressed, the block is visible after a short delay. This behaviour can be modified in the configuration.*
50+
*Note: By default the block is immediately active after calling this method, but to prevent trashing the user interface each time a button is pressed, the block is visible after a short delay. This behaviour can be modified in the configuration.*
3751

3852
**Arguments:**
3953

@@ -60,7 +74,7 @@ The callback function to queue.
6074
BlockUI overlay template
6175
========================
6276

63-
The html and styling of the builtin template is kept barebone. It consist of two divs (overlay and message):
77+
The html and styling of the builtin template is kept bare bone. It consist of two divs (overlay and message):
6478

6579
<div ng-show="blockCount > 0" class="block-ui-overlay" ng-class="{ 'block-ui-visible': blocking }"></div>
6680
<div ng-show="blocking" class="block-ui-message">{{ message }}</div>
@@ -118,7 +132,19 @@ By default the BlockUI module will start a block whenever the Angular *$http* se
118132
blockUIConfigProvider.autoBlock(false);
119133

120134
#### resetOnException
121-
By default the BlockUI module will reset the block count and hide the overlay whenever an exception has occured. You can set this value to *false* if you don't want this behaviour.
135+
By default the BlockUI module will reset the block count and hide the overlay whenever an exception has occurred. You can set this value to *false* if you don't want this behaviour.
136+
137+
// Disable clearing block whenever an exception has occurred
138+
blockUIConfigProvider.resetOnException(false);
139+
140+
#### requestFilter
141+
Allows you to specify a filter function to exclude certain ajax requests from blocking the user interface. The function is passed the [Angular request config object](http://docs.angularjs.org/api/ng/service/$http). The blockUI service will ignore requests when the function returns `false`.
122142

123-
// Disable clearing block whenever an exception has occured
124-
blockUIConfigProvider.resetOnException(false);
143+
// Tell the blockUI service to ignore certain requests
144+
blockUIConfigProvider.requestFilter(function(config) {
145+
146+
// If the request starts with '/api/quote' ...
147+
if(config.url.match(/^\/api\/quote($|\/).*/)) {
148+
return false; // ... don't block it.
149+
}
150+
});

bower.json

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,13 @@
11
{
22
"name": "angular-block-ui",
3-
"version": "0.0.3",
4-
"keywords": ["angular", "angularjs", "block", "block-ui", "blockui"],
3+
"version": "0.0.4",
4+
"keywords": [
5+
"angular",
6+
"angularjs",
7+
"block",
8+
"block-ui",
9+
"blockui"
10+
],
511
"authors": [
612
"Null McNull <[email protected]>"
713
],
@@ -31,6 +37,7 @@
3137
"angular-route": "~1.2.4",
3238
"angular-resource": "~1.2.4",
3339
"lodash": "~2.4.1",
34-
"angular-mocks": "~1.2.4"
40+
"angular-mocks": "~1.2.4",
41+
"showdown": "~0.3.1"
3542
}
3643
}

grunt/grunt-common.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@ module.exports = function(grunt) {
2626
grunt.registerTask('ejs', ['clean:render', 'render:index', 'render:karmaConf']);
2727
grunt.registerTask('test-single', ['render:karmaConf', 'karma:single']);
2828
grunt.registerTask('test', ['build', 'render:karmaConf', 'karma:unit']);
29+
grunt.registerTask('postBuild', 'Executed after build', function() {
30+
grunt.log.writeln('This task can be overwritten.');
31+
});
2932
},
3033
expandGlobs: function(globs, cwd) {
3134

grunt/grunt-debug.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,8 @@ module.exports = function (grunt) {
9494
var args = [1, 0].concat(areas);
9595
Array.prototype.splice.apply(buildTasks, args);
9696

97+
buildTasks.push('postBuild');
98+
9799
grunt.registerTask('build', buildTasks);
98100
grunt.registerTask('default', 'build');
99101

grunt/grunt-release.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,8 @@ module.exports = function (grunt) {
9595
var args = [2, 0].concat(areas);
9696
Array.prototype.splice.apply(buildTasks, args);
9797

98+
buildTasks.push('postBuild');
99+
98100
grunt.registerTask('build', buildTasks);
99101
grunt.registerTask('default', 'build');
100102

grunt/project-files-debug.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,14 +37,16 @@ var files = {
3737
'vendor/angular/angular.js',
3838
'vendor/angular-resource/angular-resource.js',
3939
'vendor/angular-route/angular-route.js',
40-
'vendor/lodash/dist/lodash.js'
40+
'vendor/lodash/dist/lodash.js',
41+
'vendor/showdown/src/showdown.js'
4142
],
4243
test: [
4344
'vendor/angular/angular.js',
4445
'vendor/angular-mocks/angular-mocks.js',
4546
'vendor/angular-resource/angular-resource.js',
4647
'vendor/angular-route/angular-route.js',
47-
'vendor/lodash/dist/lodash.js'
48+
'vendor/lodash/dist/lodash.js',
49+
'vendor/showdown/src/showdown.js'
4850
],
4951
css: [
5052
'vendor/bootstrap-css/css/bootstrap.css',

grunt/project-files-release.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,14 +41,16 @@ var files = {
4141
'vendor/angular/angular.min.js',
4242
'vendor/angular-resource/angular-resource.min.js',
4343
'vendor/angular-route/angular-route.min.js',
44-
'vendor/lodash/dist/lodash.min.js'
44+
'vendor/lodash/dist/lodash.min.js',
45+
'vendor/showdown/compressed/showdown.js'
4546
],
4647
test: [
4748
'vendor/angular/angular.js',
4849
'vendor/angular-resource/angular-resource.min.js',
4950
'vendor/angular-route/angular-route.min.js',
5051
'vendor/angular-mocks/angular-mocks.js',
51-
'vendor/lodash/dist/lodash.min.js'
52+
'vendor/lodash/dist/lodash.min.js',
53+
'vendor/showdown/compressed/showdown.js'
5254
],
5355
css: [
5456
'vendor/bootstrap-css/css/bootstrap.min.css',

gruntfile.js

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,25 @@
1+
var fs = require('fs');
12

23
module.exports = function(grunt) {
34

45
var target = grunt.option('target') || 'debug';
5-
var gruntTarget = require('./grunt/grunt-' + target);
6-
7-
gruntTarget(grunt).addArea('angularBlockUI', 'angular-block-ui')
8-
.addArea('app')
9-
.initConfig();
6+
var gruntTarget = require('./grunt/grunt-' + target)(grunt);
107

11-
};
8+
gruntTarget.addArea('angularBlockUI', 'angular-block-ui')
9+
.addArea('angularShowdown', 'angular-showdown')
10+
.addArea('app')
11+
.registerTasks();
12+
13+
var config = gruntTarget.getConfig();
14+
15+
grunt.task.registerTask('postBuild', 'Executed after build.', function() {
16+
var readme = fs.readFileSync('README.md');
17+
var license = fs.readFileSync('LICENSE');
18+
19+
fs.writeFileSync('dist/app/README.md', readme);
20+
fs.writeFileSync('dist/angular-block-ui/README.md', readme);
21+
fs.writeFileSync('dist/angular-block-ui/LICENSE', license);
22+
});
23+
24+
grunt.initConfig(config);
25+
};

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "angular-block-ui",
3-
"version": "0.0.3",
3+
"version": "0.0.4",
44
"description": "A simple AngularJS module that allows you to block user interaction on AJAX requests. Blocking is done automatically for each http request and/or manually via an injectable service.",
55
"main": "grunt",
66
"scripts": {

package/angular-block-ui/README.md

Lines changed: 34 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,23 @@ A simple AngularJS module that allows you to block user interaction on AJAX requ
55
#### Dependencies
66
Besides AngularJS (~1.2.4), none.
77

8+
#### Installation
9+
Either copy the contents of the `package` directory of the [Github](https://github.com/McNull/angular-block-ui) project or install with _bower_ from the command line (**recommended**):
10+
11+
bower install angular-block-ui
12+
13+
Include both the JS and CSS file in your html:
14+
15+
<link rel="stylesheet" href="path-to-block-ui/angular-block-ui.min.css"/>
16+
<!-- After AngularJS -->
17+
<script src="path-to-block-ui/angular-block-ui.min.js"></script>
18+
19+
Create a dependency on `blockUI` in your main Angular module:
20+
21+
angular.module('myApp', ['blockUI'])
22+
823
#### Usage
9-
By default the module will block the user interface on each pending request made from the browser. This behavior can be modified in the configuration.
24+
By default the module will block the user interface on each pending request made from the browser. This behaviour can be modified in the configuration.
1025

1126
It's also possible to do the blocking manually. The blockUI module exposes a service by the same name. Access to the service is gained by injecting it into your controller or directive:
1227

@@ -31,9 +46,9 @@ BlockUI service methods
3146
=======================
3247

3348
#### start
34-
The start method will start the user interface block. Because multiple user interface elements can request a user interface block at the same time, the service keeps track of the number of start calls. Each call to start() will increase the count and every call to stop() will decrease the value. Whenever the count reaches 0 the block will end.
49+
The start method will start the user interface block. Because multiple user interface elements can request a user interface block at the same time, the service keeps track of the number of start calls. Each call to `start()` will increase the count and every call to `stop()` will decrease the value. Whenever the count reaches 0 the block will end.
3550

36-
*Note: By default the block is immediately active after calling this method, but to prevent trashing the user interface everytime a button is pressed, the block is visible after a short delay. This behaviour can be modified in the configuration.*
51+
*Note: By default the block is immediately active after calling this method, but to prevent trashing the user interface each time a button is pressed, the block is visible after a short delay. This behaviour can be modified in the configuration.*
3752

3853
**Arguments:**
3954

@@ -60,7 +75,7 @@ The callback function to queue.
6075
BlockUI overlay template
6176
========================
6277

63-
The html and styling of the builtin template is kept barebone. It consist of two divs (overlay and message):
78+
The html and styling of the builtin template is kept bare bone. It consist of two divs (overlay and message):
6479

6580
<div ng-show="blockCount > 0" class="block-ui-overlay" ng-class="{ 'block-ui-visible': blocking }"></div>
6681
<div ng-show="blocking" class="block-ui-message">{{ message }}</div>
@@ -118,7 +133,19 @@ By default the BlockUI module will start a block whenever the Angular *$http* se
118133
blockUIConfigProvider.autoBlock(false);
119134

120135
#### resetOnException
121-
By default the BlockUI module will reset the block count and hide the overlay whenever an exception has occured. You can set this value to *false* if you don't want this behaviour.
136+
By default the BlockUI module will reset the block count and hide the overlay whenever an exception has occurred. You can set this value to *false* if you don't want this behaviour.
137+
138+
// Disable clearing block whenever an exception has occurred
139+
blockUIConfigProvider.resetOnException(false);
140+
141+
#### requestFilter
142+
Allows you to specify a filter function to exclude certain ajax requests from blocking the user interface. The function is passed the [Angular request config object](http://docs.angularjs.org/api/ng/service/$http). The blockUI service will ignore requests when the function returns `false`.
122143

123-
// Disable clearing block whenever an exception has occured
124-
blockUIConfigProvider.resetOnException(false);
144+
// Tell the blockUI service to ignore certain requests
145+
blockUIConfigProvider.requestFilter(function(config) {
146+
147+
// If the request starts with '/api/quote' ...
148+
if(config.url.match(/^\/api\/quote($|\/).*/)) {
149+
return false; // ... don't block it.
150+
}
151+
});

0 commit comments

Comments
 (0)