Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function comments_upload(event){
- let subcommentsHandler = event.currentTarget; // event.target; // .sub_comments__handler
- // alert(event.target.className)
- let target = event.target;
- let sub_comments = subcommentsHandler.parentElement;
- let comment_container = sub_comments.previousElementSibling;
- let comment__id = comment_container.id.split('__')[1]; // target_id
- let last_subcomment = subcommentsHandler.previousElementSibling;
- if (last_subcomment.className == 'sub_comments') // для общих комментариев
- {
- last_subcomment = last_subcomment.previousElementSibling;
- }
- var last_subcomment__id = last_subcomment.id.split('__')[1];
- if (!Number.parseInt(last_subcomment__id)) {
- // это прелодаер уже работает. Удаляем его и запускаем новый:
- last_subcomment.parentElement.removeChild(last_subcomment);
- last_subcomment = subcommentsHandler.previousElementSibling;
- last_subcomment__id = last_subcomment.id.split('__')[1];
- }
- focusImitate(target);
- let waitContainer = vom.create('div', {
- id: 'await__container'
- }).styles({
- position: 'relative',
- transition: '0.7s',
- height: '0',
- visibility: 'visible',
- })
- .tie(subcommentsHandler).styles({
- height: '5em'
- }, true);//*/
- let awaiting = Awaiter.Start({
- waitElem: waitContainer,
- blocks_amount: 3
- })
- var restCounter = subcommentsHandler.querySelector('.sub_comments_count');
- let persRest = subcommentsHandler.querySelector('.own_subcomments_count');
- let restCounterTypes = ['.sub_comments_count', '.own_subcomments_count']
- let personal = Number(['mine__upload', 'sub_comments__handler'].indexOf(target.className) >= 0);
- fetch('{% url "comments_upload" %}' + vom.encode({
- // target_type: target_type,
- target: comment__id,
- last_comment: last_subcomment__id,
- personal: personal
- }))
- .then(resp => resp.text())
- .then(r => {
- // alert(r)
- r = JSON.parse(r);
- awaiting.stop();
- waitContainer.parentElement.removeChild(waitContainer);
- subcommentsHandler.insertAdjacentHTML('beforebegin', r.comments);
- // если это подкомментарии
- if (restCounter){
- let rest_amount = restCounter.innerText - r.rest;
- if (rest_amount > 0) {
- restCounter.innerText = restCounter.innerText - r.rest;
- if (persRest || authUser){
- persRest.innerText = persRest.innerText - r.pers_rest;
- }//*/
- }
- else subcommentsHandler.parentElement.removeChild(subcommentsHandler);
- }
- // если рутовые комментарии
- else{
- if ( event.target.className != 'personal__more_comments'){
- var restCounter = target;
- var persRest = target.nextElementSibling;
- }
- else{
- var persRest = target;
- var restCounter = target.previousElementSibling;
- }
- let rest_amount = restCounter.innerText.match(/\d+/) - r.rest;
- if (rest_amount > 0){
- restCounter.innerText = restCounter.innerText.replace(/\d+/, match => rest_amount);
- if (authUser){
- // if all comments clicked:
- persRest.innerText = persRest.innerText.replace(/\d+/, match => match - r.pers_rest);
- }
- else{
- }
- }
- else subcommentsHandler.parentElement.removeChild(subcommentsHandler);
- }
- })
- // .catch(error => alert(error));
- /*
- let awaiting = new Awaiter();
- awaiting.start(null, {
- }); //*/
- // awaiter.start(); // waitContainer
- }
Add Comment
Please, Sign In to add comment