Last active
August 29, 2015 13:58
-
-
Save lukelex/10364670 to your computer and use it in GitHub Desktop.
StikJS refactoring example
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
$("#user_picture").change -> | |
userPictureFileName = $(this).val().split('\\').pop(); | |
$("#user_picture_text").html(userPictureFileName) | |
files = this.files | |
reader = new FileReader() | |
reader.readAsDataURL(files[0]) | |
reader.onloadend = -> | |
$("#profile_pic").css("background-image", "url(" + this.result + ")") | |
$("#user_cover_photo").change -> | |
userCoverFileName = $(this).val().split('\\').pop(); | |
$("#user_cover_text").html(userCoverFileName) | |
files = this.files | |
reader = new FileReader() | |
reader.readAsDataURL(files[0]) | |
reader.onloadend = -> | |
$("#blog_cover").css("background-image", "url(" + this.result + ")") |
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
#blog_cover style="background-image:url(#{@user.cover_photo_url})" | |
#profile_pic style="background-image:url(#{@user.thumb_picture_url})" | |
.form-group | |
label for="user_picture" Profile picture | |
input accept="image/jpeg, image/png, image/jpg" id="user_picture" name="user[picture]" type="file" | |
label.replace" for="picture" id="user_picture_text" Upload a profile picture | |
.form-group | |
label for="user_cover_photo" Cover photo | |
input accept="image/jpeg, image/png, image/jpg" id="user_cover_photo" name="user[cover_photo]" type="file" | |
label.replace" for="cover_photo" id="user_cover_text" Upload a cover picture |
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
stik.behavior 'url-updatable-recipient', ($template, $courier, $data) -> | |
$courier.$receive "picture-changed:#{$data.channel}", (url) -> | |
$template.style.backgroundImage = "url(" + url + ")" | |
stik.behavior 'url-updatable', ($template, $courier, $data) -> | |
inputFile = $template.querySelector("input[type=file]") | |
textContainer = $template.querySelector(".replace") | |
$template.onchange = -> | |
textContainer.innerHTML = inputFile.value.split('\\').pop() | |
reader = new FileReader() | |
reader.onloadend = (event) -> | |
$courier.$send "picture-changed:#{$data.channel}", event.target.result | |
reader.readAsDataURL inputFile.files[0] |
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
#blog_cover.url-updatable-recipient data-channel="cover-pic" style="background-image:url(#{@user.cover_photo_url})" | |
#profile_pic.url-updatable-recipient data-channel="profile-pic" style="background-image:url(#{@user.thumb_picture_url})" | |
.form-group.url-updatable data-channel="profile-pic" | |
label for="user_picture" Profile picture | |
input accept="image/jpeg, image/png, image/jpg" id="user_picture" name="user[picture]" type="file" | |
label.replace" for="picture" id="user_picture_text" Upload a profile picture | |
.form-group.url-updatable data-channel="cover-pic" | |
label for="user_cover_photo" Cover photo | |
input accept="image/jpeg, image/png, image/jpg" id="user_cover_photo" name="user[cover_photo]" type="file" | |
label.replace" for="cover_photo" id="user_cover_text" Upload a cover picture |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment