-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* addfunc: Split JavaScript files #54 * addfunc: Add function Ajax process to like #54 * addfunc: Add function Ajax process to follow #54 * addfunc: Fix like #54 * addfunc: Fix follow #54 * addfunc: Add function Ajax process to commnent #54 * refactor: Like #54 LGTM
- Loading branch information
Showing
19 changed files
with
165 additions
and
156 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
/* | ||
* Image uploader | ||
*/ | ||
$(document).on('turbolinks:load', () =>{ | ||
|
||
const imgUplorader = new ImgUplorader; | ||
imgUplorader.copyToSaveInput(); | ||
|
||
}); | ||
|
||
class ImgUplorader{ | ||
constructor(){ | ||
this.selectorPreview = '.form-image-uploader__preview'; | ||
this.selectorSave = '.form-image-uploader__save'; | ||
this.selectorCache = '.form-image-uploader__cache'; | ||
this.noPhotoImgPath = '/assets/nophoto-e1a743df0c155237d2677a50919e83279a8002ff93f24727582e52ffb2347dd1.jpg'; | ||
|
||
} | ||
|
||
/* | ||
* Change preview image to nophoto image when image is not selected | ||
* @param input : Element of current target | ||
*/ | ||
copyToSaveInput(){ | ||
$(document).on('change', this.selectorSave, event => { | ||
|
||
const input = $(event.currentTarget); | ||
const filesLength = input[0].files.length; | ||
const cacheDefaultVal = $(input).next(this.selectorCache)[0].defaultValue; | ||
|
||
|
||
// Change preview image to nophoto image when image is not selected | ||
if (this.hasNotImg(filesLength)) { | ||
this.changeNoPhotoImg(input); | ||
return; | ||
} | ||
|
||
// Change preview image to selected image when image is selected | ||
this.changeSelectedImg(input); | ||
|
||
}); | ||
} | ||
|
||
/* | ||
* Return true when input doesn't have file | ||
* @param filesLength : file length of input | ||
* @return bool | ||
*/ | ||
hasCacheDefaultImg(filesLength){ | ||
if(filesLength == 0){ | ||
return true; | ||
} | ||
|
||
return false; | ||
} | ||
|
||
/* | ||
* Return true when input doesn't have file | ||
* @param filesLength : file length of input | ||
* @return bool | ||
*/ | ||
hasNotImg(filesLength){ | ||
if(filesLength == 0){ | ||
return true; | ||
} | ||
|
||
return false; | ||
} | ||
|
||
/* | ||
* Change preview image to nophoto image when image is not selected | ||
* @param input : Element of current target | ||
*/ | ||
changeNoPhotoImg(input){ | ||
$(input).prev(this.selectorImg).children('img').attr('src', this.noPhotoImgPath); | ||
} | ||
|
||
/* | ||
* Change preview image to selected image when image is selected | ||
* @param input : Element of current target | ||
*/ | ||
changeSelectedImg(input){ | ||
const reader = new FileReader(); | ||
reader.onload = (progressEvent) => { | ||
$(input).prev(this.selectorImg).children('img').attr('src', progressEvent.currentTarget.result); | ||
} | ||
|
||
const file = input[0].files[0]; | ||
reader.readAsDataURL(file); | ||
} | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
/* | ||
* Slide Toggle | ||
*/ | ||
$(document).on('turbolinks:load', () =>{ | ||
$('.block-toggle__press .btn').on('click', event =>{ | ||
$(event.currentTarget).parent('.block-toggle__press').next('.block-toggle__content').slideToggle(700); | ||
}); | ||
}); |
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<div class="comment-id-<%= comment.id %>"> | ||
<div class="d-flex align-items-center"> | ||
<%= render 'users/user-info', user: comment.user %> | ||
<small class="color-text-l-gray ml-auto"><%= l comment.created_at %></small> | ||
</div> | ||
<div><%= comment.content %></div> | ||
<% if current_user == comment.user %> | ||
<small class="text-right d-block"><%= link_to '削除', post_comment_path(post, comment), method: :delete, remote: true %></small> | ||
<% end %> | ||
<hr> | ||
</div> |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
$('.post-comment').append('<%= j(render partial: 'comments/comment', locals: { comment: @comment, post: @post }) %>'); | ||
|
||
$('#comment_content').val(''); |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
$('.comment-id-<%= @comment.id %>').fadeOut().queue(function() { | ||
this.remove(); | ||
}); |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<% if current_user.already_liked?(post) %> | ||
<%= link_to 'Like', post_like_path(post, like), method: :delete, class:'post-like__cancel', remote: true %> | ||
<% else %> | ||
<%= link_to 'Like', post_likes_path(post), method: :post, class:'post-like__enable', remote: true %> | ||
<% end %> | ||
<div class="post-like__num"><%= post.likes.count %></div> |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
$('.post-like').html('<%= j(render partial: 'likes/like', locals: { post: @post, like: @like }) %>'); |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
$('.post-like').html('<%= j(render partial: 'likes/like', locals: { post: @post, like: @like }) %>'); |
Oops, something went wrong.