Created
June 14, 2016 22:15
-
-
Save delphinpro/4061230e731bb40e9e2887e206220eec to your computer and use it in GitHub Desktop.
Customized file input
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* File input | |
*/ | |
$(function () { | |
"use strict"; | |
var file_api = ( window.File && window.FileReader && window.FileList && window.Blob ) ? true : false; | |
$('.form-control-upload').each(function () { | |
var input = $('.form-control-upload__element', this); | |
var label = $('.form-control-upload__label', this); | |
input.change(function () { | |
var file_name; | |
if (file_api && input[0].files[0]) { | |
file_name = input[0].files[0].name; | |
} | |
if (!file_name.length) { | |
return; | |
} | |
label.text(file_name); | |
}).change(); | |
}); | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<label for="join-form-upload" class="form-control-upload"> | |
<input class="form-control-upload__element" type="file" name="photo" id="join-form-upload"> | |
<span class="form-control-upload__icon"></span> | |
<span class="form-control-upload__label">Загрузить фотографию</span> | |
</label> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment