You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
31 lines
1.3 KiB
31 lines
1.3 KiB
(function() {
|
|
document.addEventListener('DOMContentLoaded', function() {
|
|
var fields = document.getElementsByClassName('file-field');
|
|
for (var i = 0; i < fields.length; i++) {
|
|
var field = fields[i];
|
|
var input = field.getElementsByTagName('input')[0];
|
|
var image = field.getElementsByTagName('img')[0];
|
|
var state = field.getElementsByClassName('file-field-name')[0];
|
|
|
|
input.onchange = function() {
|
|
state.className = 'file-field-name selected';
|
|
state.innerHTML = this.value.split(/[\/\\]/).reverse()[0];
|
|
var uploadButton = this.form.querySelector('[value="upload"]');
|
|
if (uploadButton) {
|
|
uploadButton.setAttribute('data-enabled', '1');
|
|
}
|
|
|
|
if (this.files && this.files[0] && typeof FileReader !== "undefined") {
|
|
var reader = new FileReader();
|
|
|
|
reader.onload = function (e) {
|
|
image.className = 'changed';
|
|
image.src = e.target.result;
|
|
};
|
|
|
|
reader.readAsDataURL(this.files[0]);
|
|
}
|
|
}
|
|
}
|
|
}, false);
|
|
})();
|
|
|