From 1d287792df149a713a6d756bc7b110a111ae8e8a Mon Sep 17 00:00:00 2001 From: Alexandre Iooss Date: Fri, 11 Mar 2022 19:26:59 +0100 Subject: [PATCH] Move gallery JavaScript to gallery_detail.js --- photologue/static/gallery_detail.js | 9 +++++++++ .../static/lightgallery/plugins/admin/lg-admin.js | 4 ++-- photologue/templates/photologue/gallery_detail.html | 12 ++++-------- 3 files changed, 15 insertions(+), 10 deletions(-) create mode 100644 photologue/static/gallery_detail.js diff --git a/photologue/static/gallery_detail.js b/photologue/static/gallery_detail.js new file mode 100644 index 0000000..fbc9c80 --- /dev/null +++ b/photologue/static/gallery_detail.js @@ -0,0 +1,9 @@ +// This file is part of photo21 +// Copyright (C) 2022 Amicale des élèves de l'ENS Paris-Saclay +// SPDX-License-Identifier: GPL-3.0-or-later + +// Init gallery +lightGallery(document.getElementById('lightgallery'), { + plugins: [lgAdmin, lgHash, lgThumbnail, lgZoom], + customSlideName: true, +}); diff --git a/photologue/static/lightgallery/plugins/admin/lg-admin.js b/photologue/static/lightgallery/plugins/admin/lg-admin.js index f0ecf26..e9e143a 100644 --- a/photologue/static/lightgallery/plugins/admin/lg-admin.js +++ b/photologue/static/lightgallery/plugins/admin/lg-admin.js @@ -10,8 +10,8 @@ class lgAdmin { constructor(instance, $LG) { this.core = instance; this.$LG = $LG; - this.isStaff = instance.settings.isStaff; - this.csrfToken = instance.settings.csrfToken; + this.isStaff = document.querySelector('[name=is_staff]').value === "true"; + this.csrfToken = document.querySelector('[name=csrfmiddlewaretoken]').value; this.photoId = 0; return this; } diff --git a/photologue/templates/photologue/gallery_detail.html b/photologue/templates/photologue/gallery_detail.html index 5fa1999..83cab1a 100644 --- a/photologue/templates/photologue/gallery_detail.html +++ b/photologue/templates/photologue/gallery_detail.html @@ -15,19 +15,15 @@ SPDX-License-Identifier: GPL-3.0-or-later {% endblock %} {% block extrajs %} +{# Javascript code fetches CSRF token from HTML #} +{% csrf_token %} + - + {% endblock %} {% block content %}