From efd450e6b5931c9ec468a816803d8d172d2123e5 Mon Sep 17 00:00:00 2001 From: Your Name Date: Tue, 19 Jul 2022 22:19:59 -0400 Subject: [PATCH] move jq/cash to _common_libs template partial --- boofilsic/settings.py | 7 ++- books/templates/books/detail.html | 11 ++-- collection/templates/detail.html | 10 ++-- common/static/js/create_update_review.js | 2 +- common/static/js/detail.js | 16 +++--- common/static/js/home.js | 24 +-------- common/static/js/mastodon.js | 50 ++++++++----------- common/static/js/scrape.js | 2 +- common/static/js/sort_layout.js | 6 +-- common/templates/partial/_common_libs.html | 23 +++++++++ games/templates/games/detail.html | 9 ++-- .../movies/create_update_review.html | 4 +- movies/templates/movies/detail.html | 14 ++---- movies/templates/movies/mark_list.html | 2 +- movies/templates/movies/review_detail.html | 2 +- movies/templates/movies/review_list.html | 2 +- music/templates/music/album_detail.html | 12 ++--- music/templates/music/album_mark_list.html | 2 +- .../templates/music/album_review_detail.html | 2 +- music/templates/music/album_review_list.html | 2 +- .../music/create_update_album_review.html | 2 +- .../music/create_update_song_review.html | 2 +- music/templates/music/song_detail.html | 10 ++-- music/templates/music/song_mark_list.html | 2 +- music/templates/music/song_review_detail.html | 2 +- music/templates/music/song_review_list.html | 2 +- timeline/templates/timeline.html | 9 ++-- users/static/js/followers_list.js | 9 +--- users/static/js/following_list.js | 9 +--- users/templates/users/data.html | 5 +- users/templates/users/home.html | 6 +-- users/templates/users/login.html | 19 ++----- users/templates/users/preferences.html | 3 +- users/templates/users/relation_list.html | 6 +-- 34 files changed, 121 insertions(+), 167 deletions(-) create mode 100644 common/templates/partial/_common_libs.html diff --git a/boofilsic/settings.py b/boofilsic/settings.py index 9fbbbe03..0b029642 100644 --- a/boofilsic/settings.py +++ b/boofilsic/settings.py @@ -202,7 +202,12 @@ MEDIA_URL = '/media/' MEDIA_ROOT = os.path.join(BASE_DIR, 'media/') PROJECT_ROOT = os.path.abspath(os.path.dirname(__name__)) -SITE_INFO = {'site_name': 'NiceDB', 'support_link': 'https://github.com/doubaniux/boofilsic/issues', 'version_hash': current_commit_hash(PROJECT_ROOT)} +SITE_INFO = { + 'site_name': 'NeoDB', 'support_link': 'https://mastodon.social/@neodb', + 'version_hash': current_commit_hash(PROJECT_ROOT), + 'settings_module': os.getenv('DJANGO_SETTINGS_MODULE'), + 'sentry_dsn': None, +} # Mastodon configs CLIENT_NAME = 'NiceDB' diff --git a/books/templates/books/detail.html b/books/templates/books/detail.html index ff827329..2452bcf1 100644 --- a/books/templates/books/detail.html +++ b/books/templates/books/detail.html @@ -26,16 +26,13 @@ {% if book.isbn %} {% endif %} - + {{ site_name }} - {% trans '书籍详情' %} | {{ book.title }} - - - + + {% include "partial/_common_libs.html" with jquery=1 %} + - - - diff --git a/collection/templates/detail.html b/collection/templates/detail.html index fa87397d..d78513b9 100644 --- a/collection/templates/detail.html +++ b/collection/templates/detail.html @@ -19,15 +19,13 @@ + {{ site_name }} {% trans '收藏单' %} - {{ collection.title }} - + + {% include "partial/_common_libs.html" with jquery=1 %} + - - - - - diff --git a/common/static/js/create_update_review.js b/common/static/js/create_update_review.js index 12573798..60ab409d 100644 --- a/common/static/js/create_update_review.js +++ b/common/static/js/create_update_review.js @@ -3,7 +3,7 @@ $(document).ready( function() { $(".markdownx-preview").hide(); $(".markdownx textarea").attr("placeholder", "从剪贴板粘贴或者拖拽文件至编辑框即可插入图片"); - $(".review-form__preview-button").click(function() { + $(".review-form__preview-button").on('click', function() { if ($(".markdownx-preview").is(":visible")) { $(".review-form__preview-button").text("预览"); $(".markdownx-preview").hide(); diff --git a/common/static/js/detail.js b/common/static/js/detail.js index 01feac46..fe61e7c9 100644 --- a/common/static/js/detail.js +++ b/common/static/js/detail.js @@ -7,7 +7,7 @@ $(document).ready( function() { // pop up new rating modal $("#addMarkPanel button").each(function() { - $(this).click(function(e) { + $(this).on('click', function(e) { e.preventDefault(); let title = $(this).text().trim(); $(".mark-modal__title").text(title); @@ -29,7 +29,7 @@ $(document).ready( function() { }) // pop up modify mark modal - $(".mark-panel a.edit").click(function(e) { + $(".mark-panel a.edit").on('click', function(e) { e.preventDefault(); let title = $(".mark-panel__status").text().trim(); $(".mark-modal__title").text(title); @@ -79,7 +79,7 @@ $(document).ready( function() { if ($("#statusSelection input[type='radio']:checked").val() == WISH_CODE) { $(".mark-modal .rating-star-edit").hide(); } - $("#statusSelection input[type='radio']").click(function() { + $("#statusSelection input[type='radio']").on('click', function() { if ($(this).val() == WISH_CODE) { $(".mark-modal .rating-star-edit").hide(); } else { @@ -89,14 +89,14 @@ $(document).ready( function() { }); // show confirm modal - $(".mark-panel a.delete").click(function(e) { + $(".mark-panel a.delete").on('click', function(e) { e.preventDefault(); $(".confirm-modal").show(); $(".bg-mask").show(); }); // confirm modal - $(".confirm-modal input[type='submit']").click(function(e) { + $(".confirm-modal input[type='submit']").on('click', function(e) { e.preventDefault(); $(".mark-panel form").submit(); }); @@ -116,20 +116,20 @@ $(document).ready( function() { }); // expand hidden long text - $(".entity-desc__unfold-button a").click(function() { + $(".entity-desc__unfold-button a").on('click', function() { $(this).parent().siblings(".entity-desc__content").removeClass('entity-desc__content--folded'); $(this).parent(".entity-desc__unfold-button").remove(); }); // disable delete mark button after click const confirmDeleteMarkButton = $('.confirm-modal__confirm-button > input'); - confirmDeleteMarkButton.click(function() { + confirmDeleteMarkButton.on('click', function() { confirmDeleteMarkButton.prop("disabled", true); }); // disable sumbit button after click const confirmSumbitMarkButton = $('.mark-modal__confirm-button > input'); - confirmSumbitMarkButton.click(function() { + confirmSumbitMarkButton.on('click', function() { confirmSumbitMarkButton.prop("disabled", true); confirmSumbitMarkButton.closest('form')[0].submit(); }); diff --git a/common/static/js/home.js b/common/static/js/home.js index eaef3492..ca1cb32b 100644 --- a/common/static/js/home.js +++ b/common/static/js/home.js @@ -16,26 +16,6 @@ $(document).ready( function() { $("#followers h5").after(followersSpinner); $(".mast-following-more").hide(); $(".mast-followers-more").hide(); - // getUserInfo( - // id, - // mast_uri, - // token, - // function(userData) { - // let userName; - // if (userData.display_name) { - // userName = translateEmojis(userData.display_name, userData.emojis, true); - // } else { - // userName = userData.username; - // } - // //$("#userInfoCard .mast-acct").text(userData.acct); - // $("#userInfoCard .mast-acct").attr("href", userData.url); - // $("#userInfoCard .mast-avatar").attr("src", userData.avatar); - // $("#userInfoCard .mast-displayname").html(userName); - // $("#userInfoCard .mast-brief").text($("
"+userData.note.replace(/\
").text()); - // $("#userInfoCard .mast-brief").html($("#userInfoCard .mast-brief").html().replace(/\n/g,'
')); - // $(userInfoSpinner).remove(); - // } - // ); getFollowers( id, @@ -122,7 +102,7 @@ $(document).ready( function() { button.children('.icon-arrow').toggleClass("icon-arrow--expand"); button.siblings('.relation-dropdown__body').toggleClass("relation-dropdown__body--expand"); } - $(".relation-dropdown__button").click(onClickDropdownButton) + $(".relation-dropdown__button").on('click', onClickDropdownButton); // close when click outside window.onclick = evt => { @@ -133,7 +113,7 @@ $(document).ready( function() { }; // import panel - $("#uploadBtn").click(e => { + $("#uploadBtn").on('click', e => { const btn = $("#uploadBtn") const form = $(".import-panel__body form") diff --git a/common/static/js/mastodon.js b/common/static/js/mastodon.js index 91defcbe..5d1efe87 100644 --- a/common/static/js/mastodon.js +++ b/common/static/js/mastodon.js @@ -54,38 +54,32 @@ const NUMBER_PER_REQUEST = 20 // "fields": [] // } // ] -function getFollowers(id, mastodonURI, token, callback) { - let url = mastodonURI + API_FOLLOWERS.replace(":id", id); - $.ajax({ - url: url, - method: 'GET', - headers: { - 'Authorization': 'Bearer ' + token, - }, - data: { - 'limit': NUMBER_PER_REQUEST - }, - success: function(data, status, request){ - callback(data, request); - }, +async function getFollowers(id, mastodonURI, token, callback) { + const url = mastodonURI + API_FOLLOWERS.replace(":id", id); + const response = await fetch(url+'?limit='+NUMBER_PER_REQUEST, {headers: {'Authorization': 'Bearer ' + token}}); + const json = await response.json(); + let nextUrl = null; + response.headers.get('link').split(',').forEach(link => { + if (link.includes('next')) { + let regex = /<(.*?)>/; + nextUrl = link.match(regex)[1]; + } }); + callback(json, nextUrl); } -function getFollowing(id, mastodonURI, token, callback) { - let url = mastodonURI + API_FOLLOWING.replace(":id", id); - $.ajax({ - url: url, - method: 'GET', - headers: { - 'Authorization': 'Bearer ' + token, - }, - data: { - 'limit': NUMBER_PER_REQUEST - }, - success: function(data, status, request){ - callback(data, request); - }, +async function getFollowing(id, mastodonURI, token, callback) { + const url = mastodonURI + API_FOLLOWING.replace(":id", id); + const response = await fetch(url+'?limit='+NUMBER_PER_REQUEST, {headers: {'Authorization': 'Bearer ' + token}}); + const json = await response.json(); + let nextUrl = null; + response.headers.get('link').split(',').forEach(link => { + if (link.includes('next')) { + let regex = /<(.*?)>/; + nextUrl = link.match(regex)[1]; + } }); + callback(json, nextUrl); } // { diff --git a/common/static/js/scrape.js b/common/static/js/scrape.js index 67ce3e3a..bd05bbd8 100644 --- a/common/static/js/scrape.js +++ b/common/static/js/scrape.js @@ -1,6 +1,6 @@ $(document).ready( function() { - $(".submit").click(function(e) { + $(".submit").on('click', function(e) { e.preventDefault(); let form = $("#scrapeForm form"); if (form.data('submitted') === true) { diff --git a/common/static/js/sort_layout.js b/common/static/js/sort_layout.js index 1ac72eba..c20e370d 100644 --- a/common/static/js/sort_layout.js +++ b/common/static/js/sort_layout.js @@ -8,7 +8,7 @@ $(() => { $(e).data("visibility", true); } let btn = $("#toggleDisplayButtonTemplate").clone().removeAttr("id"); - btn.click(e => { + btn.on('click', e => { if ($(e.currentTarget).parent().data('visibility') === true) { // flip text $(e.currentTarget).children("span.showText").show(); @@ -72,7 +72,7 @@ $(() => { }); // activate sorting - $("#sortEditButton").click(evt => { + $("#sortEditButton").on('click', evt => { // test if edit mode is activated isActivated = $("#sortSaveIcon").is(":visible"); @@ -134,7 +134,7 @@ $(() => { }); // exit edit mode - $("#sortExitButton").click(evt => { + $("#sortExitButton").on('click', evt => { initialLayoutData.forEach(elem => { // set visiblity $('#' + elem.id).data('visibility', elem.visibility); diff --git a/common/templates/partial/_common_libs.html b/common/templates/partial/_common_libs.html new file mode 100644 index 00000000..9460e2da --- /dev/null +++ b/common/templates/partial/_common_libs.html @@ -0,0 +1,23 @@ +{% load static %} +{% if sentry_dsn %} + + +{% endif %} +{% if jquery %} + +{% else %} + +{% endif %} + + + + + + diff --git a/games/templates/games/detail.html b/games/templates/games/detail.html index 0e042e2f..fabd85a5 100644 --- a/games/templates/games/detail.html +++ b/games/templates/games/detail.html @@ -23,14 +23,11 @@ {{ site_name }} - {% trans '游戏详情' %} | {{ game.title }} - - - + {% include "partial/_common_libs.html" with jquery=1 %} + - - @@ -75,7 +72,7 @@ {% if game.other_title|length > 5 %} {% trans '更多' %} - - + {% include "partial/_common_libs.html" with jquery=1 %} + - - - @@ -102,7 +98,7 @@ {% if movie.director|length > 5 %} {% trans '更多' %} - - + {% include "partial/_common_libs.html" with jquery=1 %} + - - - @@ -76,7 +72,7 @@ {% if album.artist|length > 5 %} {% trans '更多' %} - - + {% include "partial/_common_libs.html" with jquery=1 %} + - - - @@ -75,7 +71,7 @@ {% if song.artist|length > 5 %} {% trans '更多' %} - + + {% include "partial/_common_libs.html" with jquery=1 %} + - - - - diff --git a/users/static/js/followers_list.js b/users/static/js/followers_list.js index ceec29a9..44680865 100644 --- a/users/static/js/followers_list.js +++ b/users/static/js/followers_list.js @@ -46,7 +46,7 @@ $(document).ready( function() { id, mast_uri, token, - function(userList, request) { + function(userList, nextPage) { let subUserList = null; if (userList.length == 0) { $(".mast-followers").hide(); @@ -102,12 +102,7 @@ $(document).ready( function() { }); mainSpinner.hide(); - request.getResponseHeader('link').split(',').forEach(link => { - if (link.includes('next')) { - let regex = /<(.*?)>/; - nextUrl = link.match(regex)[1]; - } - }); + nextUrl = nextPage; } ); diff --git a/users/static/js/following_list.js b/users/static/js/following_list.js index f0ac6c89..6b3ba278 100644 --- a/users/static/js/following_list.js +++ b/users/static/js/following_list.js @@ -83,7 +83,7 @@ $(document).ready( function() { id, mast_uri, token, - function(userList, request) { + function(userList, nextPage) { // aside let subUserList = null; if (userList.length == 0) { @@ -140,12 +140,7 @@ $(document).ready( function() { }); mainSpinner.hide(); - request.getResponseHeader('link').split(',').forEach(link => { - if (link.includes('next')) { - let regex = /<(.*?)>/; - nextUrl = link.match(regex)[1]; - } - }); + nextUrl = nextPage; } ); diff --git a/users/templates/users/data.html b/users/templates/users/data.html index e2756877..4677bc80 100644 --- a/users/templates/users/data.html +++ b/users/templates/users/data.html @@ -12,10 +12,9 @@ {{ site_name }} - 数据管理 - + {% include "partial/_common_libs.html" with jquery=1 %} - @@ -116,7 +115,7 @@ + + {% include "partial/_common_libs.html" %} + - - diff --git a/users/templates/users/login.html b/users/templates/users/login.html index cb558dd2..a1a8cdde 100644 --- a/users/templates/users/login.html +++ b/users/templates/users/login.html @@ -10,26 +10,13 @@ + {{ site_name }} - {% trans '登录' %} + {% include "partial/_common_libs.html" %} - - - - {{ site_name }} - {% trans '登录' %} -