-
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.
For #63 webpack setup; clear base.html
- Loading branch information
Showing
32 changed files
with
3,231 additions
and
366 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,3 +22,4 @@ docs | |
.coverage | ||
reqs/req.txt | ||
reqs/req.in | ||
node_modules |
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,40 @@ | ||
import { getCookie } from "./utils"; | ||
// bookmarks | ||
const jsBox = document.getElementById("jsBox"); | ||
const bmarkDiv = document.getElementById("bmarkDiv"); | ||
const formBook = document.querySelector("#bookmark"); | ||
if(bmarkDiv){ | ||
const fd = new FormData(); | ||
fd.append("csrfmiddlewaretoken",getCookie("csrftoken")) | ||
formBook.addEventListener("submit",(e)=>{ | ||
e.preventDefault(); | ||
const url = formBook.getAttribute("action"); | ||
fd.append("post_uuid",formBook.post_uuid.value), | ||
fd.append("user_id",formBook.user_id.value) | ||
|
||
fetch(url,{ | ||
method:"POST", | ||
headers:{ "x-requested-with": "XMLHttpRequest"}, | ||
body:fd | ||
}).then((resp)=>resp.json()) | ||
.then((data)=>{ | ||
if(data.status_code ===200){ | ||
let msg = data.msg; | ||
jsBox.classList.add("green","slide"); | ||
jsBox.textContent= msg; | ||
if(data.del_button){ | ||
bmarkDiv.remove(); | ||
} | ||
} | ||
else if(data.status_code ===404){ | ||
// add error flash msg | ||
jsBox.classList.add("red","slide"); | ||
jsBox.textContent= "Failed to add to bookmarks"; | ||
throw new Error(message="Failed to add to bookmarks"); | ||
} | ||
}) | ||
.catch((err)=>{ | ||
console.log(err["message"]); | ||
}) | ||
}) | ||
} |
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,42 @@ | ||
//click button Categories-> toggle categs | ||
document.addEventListener('click',(e)=>{ | ||
let isCategBut = e.target.matches("[data-dropdown-but]"); | ||
if(!isCategBut&&e.target.closest("[data-dropdown]")!=null){ | ||
return | ||
} | ||
if(isCategBut){ | ||
// click button will show<->hide all categories | ||
const but = document.getElementById("show-cats") | ||
const ulMenu = document.querySelector(".root-cats"); | ||
if(!but.classList.contains('hide')){ | ||
but.classList.add("hide") | ||
but.innerHTML="Show Categories"; | ||
ulMenu.classList.remove("to-show") | ||
}else{ | ||
but.classList.remove('hide') | ||
but.innerHTML="Hide categories"; | ||
ulMenu.classList.add("to-show"); | ||
} | ||
} | ||
}); | ||
// help func to outroll (sub)categs; | ||
//maybe: custom click event(?) | ||
// by now: mouseover -> outroll categs; click -> make request | ||
let catSideBar = document.querySelector(".root-cats"); | ||
if(catSideBar){ | ||
catSideBar.addEventListener("mouseover",(e)=>{ | ||
const isDropDownLink = e.target.matches('[data-dropdown-link]'); | ||
if(!isDropDownLink&&e.target.closest("[data-li]")!=null){ | ||
return | ||
} | ||
if(isDropDownLink){ | ||
// get ul children (sibling "a" tag enbed in "li") | ||
let currentDropDown = e.target.nextElementSibling; | ||
// e.target is a a tag node-link to-toggle | ||
currentDropDown.classList.add("to-block"); | ||
} | ||
}) | ||
} | ||
|
||
|
||
|
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,34 @@ | ||
console.log("with css"); | ||
import "./utils"; | ||
import "./categs"; | ||
import "./checkState"; | ||
import "./bookmarks" | ||
|
||
|
||
// third parties | ||
import * as bootstrap from 'bootstrap'; | ||
window.bootstrap = bootstrap; | ||
|
||
window.htmx = require('htmx.org'); | ||
|
||
// css | ||
import "../styles/index.css"; | ||
|
||
const modal = new bootstrap.Modal(document.getElementById("modal")); | ||
htmx.on("htmx:afterSwap", (e) => { | ||
// Response targeting #dialog => show the modal | ||
if (e.detail.target.id == "dialog") { | ||
modal.show() | ||
} | ||
}) | ||
htmx.on("htmx:beforeSwap", (e) => { | ||
// Empty response targeting #dialog => hide the modal | ||
if (e.detail.target.id == "dialog" && !e.detail.xhr.response) { | ||
modal.hide() | ||
e.detail.shouldSwap = false | ||
} | ||
}) | ||
// form with errors->cancel-> open again(form + err should flush) | ||
htmx.on("hidden.bs.modal", () => { | ||
document.getElementById("dialog").innerHTML = "" | ||
}) |
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,34 @@ | ||
import { getCookie } from "./utils"; | ||
const sendAvaUpdate = function(url,avatar) { | ||
const fd = new FormData(); | ||
fd.append("csrfmiddlewaretoken",getCookie("csrftoken")); | ||
fd.append('avatar',avatar) | ||
fetch(url,{ | ||
method:"POST", | ||
headers:{ "x-requested-with": "XMLHttpRequest"}, | ||
body:fd | ||
}).then((resp)=>resp.json()) | ||
.then((data)=>{ | ||
if(data.status_code ===200){ | ||
setTimeout( | ||
window.location.reload(),3000 | ||
) | ||
} | ||
else if(data.status_code ===404){ | ||
jsErr.classList.remove("visually-hidden"); | ||
jsErr.textContent = "Failed upload avatar"; | ||
data.err.avatar.forEach((err)=>{ | ||
let div = document.createElement("div") | ||
div.classList.add("errorlist"); | ||
div.innerHTML = `${err}`; | ||
errDiv.appendChild(div) | ||
}); | ||
throw new Error(message="Custom error: upload failed"); | ||
} | ||
}) | ||
.catch((err)=>{ | ||
console.log(err["message"]); | ||
}) | ||
} | ||
|
||
export {sendAvaUpdate} |
Oops, something went wrong.