rejetto forum

Author Topic: The Throwback (retro) template. With large folder and mobile support.  (Read 150480 times)

Offline dj

  • Tireless poster
  • ****
  • Posts: 291
  • 👣 🐾
    • View Profile
    • PWAs
Re: Need help with file delete feature
« on: July 09, 2018, 06:27:37 PM »
[file]
Code: [Select]
{.if|{.get|can delete.}|<span onclick='del("%item-url%")'>x</span>.}
and add script
Code: [Select]
<script>
function del(it) {
if(!confirm("Delete "+it+"?")) return 0;
var xhr = new XMLHttpRequest();
xhr.open("POST", "%folder%")
xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded")
xhr.onload = function() {document.write(xhr.responseText);}
xhr.send("action=delete&selection="+it)
}
</script>

tested with chrome,FF,Edge


Update: more elegant

[file]
Code: [Select]
{.if|{.get|can delete.}|<span class='del' data-it='%item-url%'>x</span>.}
and add script at the end
Code: [Select]
<script>
document.querySelectorAll('.del').forEach(function(userItem) {
  userItem.addEventListener('click',function(){del(this.getAttribute("data-it"))})
})
</script>

or use a single event handler


Update2: if {.get|can delete.} slowes down, you can try

[file]
Code: [Select]
<span class='del' data-it='%item-url%'>x</span>
and add to function del
Code: [Select]
if (!'{.get|can delete.}') return 0
« Last Edit: July 10, 2018, 04:08:47 PM by dj »

Follow members gave a thank to your post:


Thank-o-Matic 3.0 By Adk Team