profiles.min.js
1.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
(function($) {
$(document).ready(function() {
// Upload Submit
$('.upload-profile-container input[type="file"]').change(function(e) {
e.preventDefault();
var value = $(this).val(), file = this.files[0];
if (!value || !file) {
return false;
}
var url = $('form').attr('action'), fd = new FormData();
var args = {};
$('input[type="hidden"][value="1"]').each(function() {
args[this.name] = 1;
});
var xhr = new XMLHttpRequest();
xhr.open('POST', url + '&task=profiles.import', true);
// set request header
xhr.setRequestHeader('X-Requested-With', 'XMLHttpRequest');
xhr.onreadystatechange = function () {
if (xhr.readyState === 4) {
var data = {};
// success
if (xhr.status === 200) {
try {
data = JSON.parse(xhr.responseText);
} catch (e) {
alert(e);
return false;
}
}
// reset
xhr.onreadystatechange = $.noop;
xhr = fd = null;
document.location.href = data.redirect || 'index.php?option=com_jce&view=profiles';
}
};
$.each(args, function(key, value) {
fd.append(key, value);
});
// convert slashes
value = value.replace(/[\\\\]+/g, '/');
// extract name
var name = value.substr(value.lastIndexOf('/') + 1);
// append file
fd.append("profile_file", file, name);
xhr.send(fd);
});
});
})(jQuery);