Last active
January 26, 2017 22:55
-
-
Save Arcolye/0dfa2fdde8e9f9db24cf09de5b429909 to your computer and use it in GitHub Desktop.
GoToStudy - Photo upload
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
# Selecting a photo to upload shows photo and filename instantly | |
placeSelectedPhotoPreview = (input) -> | |
if input.files && input.files[0] | |
reader = new FileReader() | |
reader.readAsDataURL(input.files[0]) | |
reader.onload = (e) -> | |
$(input).closest('.thumbnail').find('img#photo-preview').attr("src", e.target.result) | |
$(input).closest('.thumbnail').find("#upload-filename").html(input.files[0].name) | |
# When a photo is selected | |
$(document).on 'change', '.photo-inputs input', -> placeSelectedPhotoPreview(this) | |
# Clicking the photo preview also activates file_field input. | |
$(document).on 'click', '.photo-inputs img#photo-preview', -> | |
$(this).next('div').find('a.btn input').click() | |
# Add a new photo selection field when you select a photo. | |
# Only for .photo-inputs-auto_add_field | |
$(document).on 'change', '.photo-inputs-auto_add_field input', -> | |
$(this).closest('.photo-inputs-auto_add_field').find('a.add_fields').click() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment