-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathscript.js
73 lines (62 loc) · 2.42 KB
/
script.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
console.log('connected?');
//get elements
const editProfileButton = document.querySelector(".edit-profile-button");
const editProfileModal = document.querySelector(".edit-profile-modal");
const editProfileModalContent = document.querySelector(".edit-profile-modal-content");
const closeModalButton = document.querySelector(".close-modal");
//drop down comments
const commentsButton = document.querySelector(".comments-button");
const comments = document.querySelector(".comments");
if(commentsButton) {
commentsButton.addEventListener('click', () => {
comments.classList.toggle('open-panel');
});
}
//edit comments
const editCommentButtons = document.querySelectorAll(".edit-comment-button");
if(editCommentButtons) {
editCommentButtons.forEach(button => {
button.addEventListener('click', () => {
button.parentNode.parentNode.querySelector('.edit-comment-input').classList.toggle('show-edit-comment');
button.parentNode.parentNode.querySelector('.comment-paragraph').querySelector('.comment-paragraph-content').classList.toggle('hide-comment-paragraph');
});
});
}
// upload profile picture with uploader widget
var profilePic = document.querySelector('.profile-pic');
if(profilePic) {
var widget = uploadcare.Widget('[role=uploadcare-uploader]');
widget.onUploadComplete(function (fileInfo) {
const id = document.querySelector('.profile').id;
var myHeaders = new Headers({
'Accept': 'application/json',
'Content-Type': 'application/json'
});
var myInit = {
method: 'PUT',
headers: myHeaders,
body: JSON.stringify({image: fileInfo.cdnUrl}),
credentials: 'same-origin',
cache: 'default',
};
fetch(`/users/${id}/newProfilePicture`, myInit)
.then(response => {
return response.json();
})
.then(result => {
document.querySelector('.uploadcare--widget__file-size').style.display = 'none';
profilePic.src = result.image;
document.querySelector('.uploadcare--widget__file-name').textContent = 'Choose a file';
})
.catch(error => {
console.log(error);
});
});
}
$('select').material_select();
$(document).ready(function(){
// the "href" attribute of the modal trigger must specify the modal ID that wants to be triggered
$('.modal').modal();
$('.slider').slider();
$(".button-collapse").sideNav();
});