Skip to content

Commit e67e942

Browse files
committed
#840 add image-loader.js to the Gradle build
1 parent 92b2a70 commit e67e942

File tree

3 files changed

+37
-7
lines changed

3 files changed

+37
-7
lines changed

gradleResources/build.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@
7171
from 'staticResources/js/moment-with-locales.min.js'
7272
from 'staticResources/js/fullcalendar.min.js'
7373
from 'staticResources/js/fullcalendar-lang-all.js'
74+
from 'staticResources/js/image-loader.js'
7475
from 'staticResources/js/jquery.blockUI.js'
7576
from 'staticResources/js/jquery.inputmask.bundle.min.js'
7677
from 'staticResources/js/jquery.scrollUp.min.js'
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
Image.prototype.load = function( url, onLoadStartCallback, onProgressCallback, onLoadEndCallback ) {
2+
var thisImg = this,
3+
xmlHTTP = new XMLHttpRequest();
4+
5+
thisImg.completedPercentage = 0;
6+
7+
xmlHTTP.open( 'GET', url , true );
8+
xmlHTTP.responseType = 'arraybuffer';
9+
10+
xmlHTTP.onload = function( e ) {
11+
var h = xmlHTTP.getAllResponseHeaders(),
12+
m = h.match( /^Content-Type\:\s*(.*?)$/mi ),
13+
mimeType = m[ 1 ] || 'image/png';
14+
15+
var blob = new Blob( [ this.response ], { type: mimeType } );
16+
thisImg.src = window.URL.createObjectURL( blob );
17+
};
18+
19+
xmlHTTP.onprogress = function( e ) {
20+
if ( e.lengthComputable )
21+
thisImg.completedPercentage = parseInt( ( e.loaded / e.total ) * 100 );
22+
if ( onProgressCallback ) onProgressCallback( thisImg );
23+
};
24+
25+
xmlHTTP.onloadstart = function() {
26+
thisImg.completedPercentage = 0;
27+
if ( onLoadStartCallback ) onLoadStartCallback( thisImg );
28+
};
29+
30+
xmlHTTP.onloadend = function() {
31+
thisImg.completedPercentage = 100;
32+
if ( onLoadEndCallback ) onLoadEndCallback( thisImg );
33+
}
34+
35+
xmlHTTP.send();
36+
};

mavenResources/META-INF/resources/bsf/js/image-loader.js

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ Image.prototype.load = function( url, onLoadStartCallback, onProgressCallback, o
1111
var h = xmlHTTP.getAllResponseHeaders(),
1212
m = h.match( /^Content-Type\:\s*(.*?)$/mi ),
1313
mimeType = m[ 1 ] || 'image/png';
14-
// Remove your progress bar or whatever here. Load is done.
1514

1615
var blob = new Blob( [ this.response ], { type: mimeType } );
1716
thisImg.src = window.URL.createObjectURL( blob );
@@ -20,21 +19,15 @@ Image.prototype.load = function( url, onLoadStartCallback, onProgressCallback, o
2019
xmlHTTP.onprogress = function( e ) {
2120
if ( e.lengthComputable )
2221
thisImg.completedPercentage = parseInt( ( e.loaded / e.total ) * 100 );
23-
// Update your progress bar here. Make sure to check if the progress value
24-
// has changed to avoid spamming the DOM.
25-
// Something like:
26-
// if ( prevValue != thisImage completedPercentage ) display_progress();
2722
if ( onProgressCallback ) onProgressCallback( thisImg );
2823
};
2924

3025
xmlHTTP.onloadstart = function() {
31-
// Display your progress bar here, starting at 0
3226
thisImg.completedPercentage = 0;
3327
if ( onLoadStartCallback ) onLoadStartCallback( thisImg );
3428
};
3529

3630
xmlHTTP.onloadend = function() {
37-
// You can also remove your progress bar here, if you like.
3831
thisImg.completedPercentage = 100;
3932
if ( onLoadEndCallback ) onLoadEndCallback( thisImg );
4033
}

0 commit comments

Comments
 (0)