@@ -12,20 +12,28 @@ function submitForm(formId) {
12
12
xhr . upload . onprogress = function ( event ) {
13
13
if ( event . lengthComputable ) {
14
14
var percentage = ( event . loaded / event . total ) * 100 ;
15
- document . getElementById ( 'progress' ) . innerText = '' + percentage . toFixed ( 2 ) + '%' ;
15
+ document . getElementById ( 'progress' ) . innerText = 'Cargando imagen: ' + percentage . toFixed ( 2 ) + '%' ;
16
+ if ( percentage === 100 ) {
17
+ document . getElementById ( 'progress' ) . innerText = 'Procesando imagen...' ;
18
+ }
16
19
}
17
20
} ;
18
21
19
22
xhr . onreadystatechange = function ( ) {
20
23
if ( xhr . readyState == 4 && xhr . status == 200 ) {
21
- var blob = new Blob ( [ xhr . response ] , { type : 'application/octet-stream' } ) ;
24
+ var blob ;
25
+ if ( formId === 'removeBackgroundForm' ) {
26
+ blob = new Blob ( [ xhr . response ] , { type : 'image/png' } ) ;
27
+ } else {
28
+ blob = new Blob ( [ xhr . response ] , { type : 'application/octet-stream' } ) ;
29
+ }
22
30
var link = document . createElement ( 'a' ) ;
23
31
link . href = window . URL . createObjectURL ( blob ) ;
24
- var fileInput = formId === 'resizeForm' ? document . getElementById ( 'file' ) : document . getElementById ( 'convertFile' ) ;
32
+ var fileInput = formId === 'resizeForm' ? document . getElementById ( 'file' ) : ( formId === 'convertForm' ? document . getElementById ( 'convertFile' ) : document . getElementById ( 'removeBackgroundFile' ) ) ;
25
33
var fileName = fileInput . files [ 0 ] . name ;
26
34
var fileExtension = fileName . split ( '.' ) . pop ( ) ;
27
- var format = formId === 'resizeForm' ? 'resizeFormat' : ' convertFormat';
28
- var selectedFormat = document . getElementById ( format ) . value . toLowerCase ( ) ;
35
+ var format = formId === 'resizeForm' ? 'resizeFormat' : ( formId === 'convertForm' ? ' convertFormat' : 'png' ) ;
36
+ var selectedFormat = document . getElementById ( format ) ? document . getElementById ( format ) . value . toLowerCase ( ) : 'png' ;
29
37
link . download = fileName . replace ( fileExtension , selectedFormat ) ;
30
38
link . click ( ) ;
31
39
document . getElementById ( 'loading' ) . style . display = 'none' ;
@@ -41,16 +49,42 @@ function submitForm(formId) {
41
49
}
42
50
43
51
52
+
53
+
54
+
44
55
document . getElementById ( 'resizeButton' ) . addEventListener ( 'click' , function ( ) {
45
56
document . getElementById ( 'resizeDiv' ) . style . display = 'block' ;
46
57
document . getElementById ( 'convertDiv' ) . style . display = 'none' ;
58
+ document . getElementById ( 'removeBackgroundDiv' ) . style . display = 'none' ;
47
59
document . getElementById ( 'resizeButton' ) . classList . add ( 'active' ) ;
48
60
document . getElementById ( 'convertButton' ) . classList . remove ( 'active' ) ;
61
+ document . getElementById ( 'removeBackgroundButton' ) . classList . remove ( 'active' ) ;
49
62
} ) ;
50
63
51
64
document . getElementById ( 'convertButton' ) . addEventListener ( 'click' , function ( ) {
52
65
document . getElementById ( 'convertDiv' ) . style . display = 'block' ;
53
66
document . getElementById ( 'resizeDiv' ) . style . display = 'none' ;
67
+ document . getElementById ( 'removeBackgroundDiv' ) . style . display = 'none' ;
54
68
document . getElementById ( 'convertButton' ) . classList . add ( 'active' ) ;
55
69
document . getElementById ( 'resizeButton' ) . classList . remove ( 'active' ) ;
70
+ document . getElementById ( 'removeBackgroundButton' ) . classList . remove ( 'active' ) ;
56
71
} ) ;
72
+
73
+ document . getElementById ( 'removeBackgroundButton' ) . addEventListener ( 'click' , function ( ) {
74
+ document . getElementById ( 'removeBackgroundDiv' ) . style . display = 'block' ;
75
+ document . getElementById ( 'resizeDiv' ) . style . display = 'none' ;
76
+ document . getElementById ( 'convertDiv' ) . style . display = 'none' ;
77
+ document . getElementById ( 'removeBackgroundButton' ) . classList . add ( 'active' ) ;
78
+ document . getElementById ( 'resizeButton' ) . classList . remove ( 'active' ) ;
79
+ document . getElementById ( 'convertButton' ) . classList . remove ( 'active' ) ;
80
+ } ) ;
81
+
82
+ document . getElementById ( 'teramont-logo' ) . addEventListener ( 'mouseover' , function ( ) {
83
+ this . style . filter = 'grayscale(0%)' ;
84
+ } ) ;
85
+
86
+ document . getElementById ( 'teramont-logo' ) . addEventListener ( 'mouseout' , function ( ) {
87
+ this . style . filter = 'grayscale(100%)' ;
88
+ } ) ;
89
+
90
+
0 commit comments