get rid of jQuery, except for relation list which should be rewritten.

This commit is contained in:
Your Name 2023-01-26 14:24:50 -05:00 committed by Henri Dickson
parent b36ba0aa07
commit 6c6e41d3b0
26 changed files with 112 additions and 103 deletions

View file

@ -12,7 +12,7 @@
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>{{ site_name }} - {% if form.instance.id %}{% trans '编辑' %} {{ form.instance.title }} {% else %}{% trans '添加' %}{% endif %}</title>
{% include "common_libs.html" with jquery=1 %}
{% include "common_libs.html" with jquery=0 %}
</head>
<body>

View file

@ -15,7 +15,19 @@
{% if jquery %}
<script src="https://cdn.staticfile.org/jquery/3.6.1/jquery.min.js"></script>
{% else %}
<script src="https://cdn.staticfile.org/cash/8.1.1/cash.min.js"></script>
<script src="https://cdn.staticfile.org/cash/8.1.2/cash.min.js"></script>
<script type="text/javascript">
$.fn.is_visible = function visible() {
return this.filter((_, elt) => (elt.offsetWidth || elt.offsetHeight || elt.getClientRects().length)).length > 0;
};
if (!$.fn.submit) $.fn.submit = function () {
this.each(function () {
$(this).trigger('submit');
this.submit();
});
return this;
};
</script>
{% endif %}
<script src="https://cdnjs.cloudflare.com/ajax/libs/htmx/1.8.4/htmx.min.js"></script>
<script src="{% static 'lib/js/hyperscript-0.9.7.min.js' %}"></script>

View file

@ -24,7 +24,7 @@
{% block opengraph %}
{% endblock %}
<title>{{ site_name }} - {% trans item.category.label %} | {{ item.title }}</title>
{% include "common_libs.html" with jquery=1 %}
{% include "common_libs.html" with jquery=0 %}
</head>
<body>
@ -227,7 +227,7 @@
<div class="tag-collection">
{% for tag in mark.tags %}
<span class="tag-collection__tag">{{ tag }}</span>
<span class="tag-collection__tag"><a href="{% url 'journal:user_tag_member_list' user.mastodon_username tag %}">{{ tag }}</a></span>
{% endfor %}
</div>

View file

@ -13,14 +13,14 @@
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>{{ site_name }} - {{ item.title }}{% trans '的标记' %}</title>
{% include "common_libs.html" with jquery=1 %}
{% include "common_libs.html" with jquery=0 %}
</head>
<body>
<div id="page-wrapper">
<div id="content-wrapper">
{% include "partial/_navbar.html" %}
<section id="content">
<div class="grid">
<div class="grid__main" id="main">
@ -62,16 +62,16 @@
</ul>
</div>
<div class="pagination">
{% if marks.pagination.has_prev %}
<a href="?page=1"
class="pagination__nav-link pagination__nav-link">&laquo;</a>
<a href="?page={{ marks.previous_page_number }}"
class="pagination__nav-link pagination__nav-link--right-margin pagination__nav-link">&lsaquo;</a>
{% endif %}
{% for page in marks.pagination.page_range %}
{% if page == marks.pagination.current_page %}
<a href="?page={{ page }}"
class="pagination__page-link pagination__page-link--current">{{ page }}</a>
@ -79,20 +79,20 @@
<a href="?page={{ page }}"
class="pagination__page-link">{{ page }}</a>
{% endif %}
{% endfor %}
{% if marks.pagination.has_next %}
<a href="?page={{ marks.next_page_number }}"
class="pagination__nav-link pagination__nav-link--left-margin">&rsaquo;</a>
<a href="?page={{ marks.pagination.last_page }}"
class="pagination__nav-link">&raquo;</a>
{% endif %}
</div>
</div>
</div>
<div class="grid__aside" id="aside">
{% include "sidebar_item.html" %}
</div>

View file

@ -13,7 +13,7 @@
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>{{ site_name }} - {{ item.title }}{% trans '的评论' %}</title>
{% include "common_libs.html" with jquery=1 %}
{% include "common_libs.html" with jquery=0 %}
</head>
<body>
@ -81,7 +81,7 @@
{% include "partial/_footer.html" %}
</div>
<script>

View file

@ -15,7 +15,7 @@
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>{{ site_name }} - {% trans '搜索结果' %}</title>
{% include "common_libs.html" with jquery=1 %}
{% include "common_libs.html" with jquery=0 %}
</head>
<body>

View file

@ -1,7 +1,7 @@
$(document).ready( function() {
$("#userInfoCard .mast-brief").text($("<div>"+$("#userInfoCard .mast-brief").text().replace(/\<br/g,'\n<br').replace(/\<p/g,'\n<p')+"</div>").text());
$("#userInfoCard .mast-brief").html($("#userInfoCard .mast-brief").html().replace(/\n/g,'<br/>'));
let token = $("#oauth2Token").text();
let mast_domain = $("#mastodonURI").text();
let mast_uri = 'https://' + mast_domain
@ -18,9 +18,9 @@ $(document).ready( function() {
$(".mast-followers-more").hide();
getUserInfo(
id,
mast_uri,
token,
id,
mast_uri,
token,
function(userData) {
let userName;
if (userData.display_name) {
@ -30,7 +30,7 @@ $(document).ready( function() {
}
$("#userInfoCard .mast-avatar").attr("src", userData.avatar);
$("#userInfoCard .mast-displayname").html(userName);
$("#userInfoCard .mast-brief").text($('<p>'+userData.note+'</p>').text());
$("#userInfoCard .mast-brief").text($('<div>'+userData.note+'</div>').text())
// $(userInfoSpinner).remove();
}
);
@ -151,7 +151,7 @@ $(document).ready( function() {
// disable submit button
btn.prop('disabled', true);
// show progress bar & hide last status
$(".import-panel__progress").show();
$(".import-panel__last-task").hide();

View file

@ -134,23 +134,24 @@ async function getFollowing(id, mastodonURI, token, callback) {
// }
function getUserInfo(id, mastodonURI, token, callback) {
let url = mastodonURI + API_GET_ACCOUNT.replace(":id", id);
$.ajax({
url: url,
method: 'GET',
headers: {
'Authorization': 'Bearer ' + token,
},
success: function(data){
callback(data);
},
});
fetch(url, {headers: {'Authorization': 'Bearer ' + token}}).then((response) => response.json()).then(callback);
// $.ajax({
// url: url,
// method: 'GET',
// headers: {
// 'Authorization': 'Bearer ' + token,
// },
// success: function(data){
// callback(data);
// },
// });
}
function getEmojiDict(emoji_list) {
let dict = new Object;
emoji_list.forEach(pair => {
dict[":" + pair.shortcode + ":"] = pair.url;
});
});
return dict;
}
@ -162,9 +163,9 @@ function translateEmojis(text, emoji_list, large) {
translation = text.replace(regex, function (match) {
return "<img src=" + dict[match] + " class=emoji--large alt=" + match + ">";
});
} else {
} else {
translation = text.replace(regex, function (match) {
return "<img src=" + dict[match] + " class=emoji alt=" + match + ">";
return "<img src=" + dict[match] + " class=emoji alt=" + match + ">";
});
}
return translation;

View file

@ -1,5 +1,5 @@
$(document).ready( function() {
$(".submit").on('click', function(e) {
e.preventDefault();
let form = $("#scrapeForm form");
@ -18,7 +18,7 @@ $(document).ready( function() {
// });
// preview uploaded pic
$("input[type='file']").change(function() {
$("input[type='file']").on("change", function() {
if (this.files && this.files[0]) {
var reader = new FileReader();
@ -89,5 +89,5 @@ $(document).ready( function() {
}
});
});
});
});

View file

@ -1,5 +1,4 @@
$(() => {
// initialization
// add toggle display button
@ -9,7 +8,7 @@ $(() => {
}
let btn = $("#toggleDisplayButtonTemplate").clone().removeAttr("id");
btn.on('click', e => {
if ($(e.currentTarget).parent().data('visibility') === true) {
if ($(e.currentTarget).parent().data('visibility') === true) {
// flip text
$(e.currentTarget).children("span.showText").show();
$(e.currentTarget).children("span.hideText").hide();
@ -74,14 +73,14 @@ $(() => {
// activate sorting
$("#sortEditButton").on('click', evt => {
// test if edit mode is activated
isActivated = $("#sortSaveIcon").is(":visible");
isActivated = $("#sortSaveIcon").is_visible();
if (isActivated) {
// save edited layout
// disable buttons
$("#sortEditButton").unbind();
$("#sortExitButton").unbind();
$("#sortEditButton").off();
$("#sortExitButton").off();
$("#sortEditButton").prop('disabled', true);
$("#sortExitButton").prop('disabled', true);
@ -130,9 +129,9 @@ $(() => {
}
});
}
isActivated = $("#sortSaveIcon").is(":visible");
isActivated = $("#sortSaveIcon").is_visible();
});
// exit edit mode
$("#sortExitButton").on('click', evt => {
initialLayoutData.forEach(elem => {
@ -159,7 +158,7 @@ $(() => {
}
$(elem).children(".entity-sort-control__button").hide();
});
isActivated = $("#sortSaveIcon").is(":visible");
isActivated = $("#sortSaveIcon").is_visible();
});
});
});

View file

@ -302,12 +302,10 @@
return this.each(function() {
// preventing against multiple instantiations
if ( !$.data( this, 'plugin_' + pluginName ) ) {
$.data( this, 'plugin_' + pluginName, new Plugin( this, options ) );
if ( !$(this).data( 'plugin_' + pluginName ) ) {
$(this).data( 'plugin_' + pluginName, new Plugin( this, options ) );
}
});
};
})( jQuery, window, document );
})( $, window, document );

View file

@ -1,7 +1,7 @@
<input type="{{ widget.type }}" name="{{ widget.name }}"{% include "django/forms/widgets/attrs.html" %}>
<img src="{{ widget.value|default_if_none:''|stringformat:'s' }}" alt="" id="previewImage" style="margin:10px 0; max-width:500px;">
<script>
$("input[type='file'][name='{{ widget.name }}']").change(function () {
$("input[type='file'][name='{{ widget.name }}']").on("change", function () {
if (this.files && this.files[0]) {
var reader = new FileReader();
@ -12,4 +12,4 @@
reader.readAsDataURL(this.files[0]);
}
});
</script>
</script>

View file

@ -23,7 +23,7 @@
<title>{{ site_name }} {% trans '收藏单' %} - {{ collection.title }}</title>
{% include "common_libs.html" with jquery=1 %}
{% include "common_libs.html" with jquery=0 %}
</head>
<body>

View file

@ -10,8 +10,8 @@
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>{{ site_name }} - {{ title }}</title>
{% include "common_libs.html" with jquery=1 %}
<title>{{ site_name }} - 编辑收藏单 - {{ title }}</title>
{% include "common_libs.html" with jquery=0 %}
<style type="text/css">
#id_collaborative li, #id_visibility li {display: inline-block !important;}
</style>

View file

@ -18,7 +18,7 @@
{% endif %}
<link rel="alternate" type="application/rss+xml" title="{{ site_name }} - {{ user.mastodon_username }}的评论" href="{{ request.build_absolute_uri }}feed/reviews/">
{% include "common_libs.html" with jquery=1 %}
{% include "common_libs.html" with jquery=0 %}
<script src="{% static 'js/mastodon.js' %}" defer></script>
<script src="{% static 'js/home.js' %}" defer></script>

View file

@ -17,7 +17,7 @@
<meta property="og:url" content="{{ request.build_absolute_uri }}">
<meta property="og:image" content="{{ review.item.cover|thumb:'normal' }}">
<title>{{ site_name }}{% trans '评论' %} - {{ review.title }}</title>
{% include "common_libs.html" with jquery=1 %}
{% include "common_libs.html" with jquery=0 %}
</head>
<body>
@ -44,7 +44,7 @@
<a href="{% url 'journal:user_profile' review.owner.mastodon_username %}" class="review-head__owner-link">{{ review.owner.username }}</a>
{% if mark %}
{% if mark %}
{% if mark.rating %}
<span class="review-head__rating-star rating-star" data-rating-score="{{ mark.rating | floatformat:0 }}"></span>

View file

@ -13,7 +13,7 @@
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>{{ site_name }} - {{ item.title }} - {% trans '评论' %}</title>
{% include "common_libs.html" with jquery=1 %}
{% include "common_libs.html" with jquery=0 %}
</head>
<body>

View file

@ -15,7 +15,7 @@
{% block title %}
<title>{{ site_name }} - {{ user.mastodon_username }}</title>
{% endblock %}
{% include "common_libs.html" with jquery=1 %}
{% include "common_libs.html" with jquery=0 %}
</head>
<body>
@ -43,7 +43,7 @@
{% endwith %}
{% empty %}
<div>{% trans '无结果' %}</div>
{% endfor %}
{% endfor %}
</ul>
</div>
<div class="pagination">

View file

@ -15,7 +15,7 @@
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>{{ site_name }} - 我的标签</title>
{% include "common_libs.html" with jquery=1 %}
{% include "common_libs.html" with jquery=0 %}
</head>
<body>
@ -27,7 +27,7 @@
<div class="grid">
<div class="grid__main" id="main">
<div class="main-section-wrapper">
<div class="entity-reviews">
<div class="entity-reviews">
<div class="tag-collection entity-reviews__review-list">
<h5>{% trans '全部标签' %}</h5>
{% for v in tags %}

View file

@ -2,9 +2,11 @@
{% load i18n %}
{% block title%}
<title>{{ site_name }} - {{ user.mastodon_username }} - {% trans '标签' %}</title>
<title>{{ site_name }} - {{ user.mastodon_username }} - {{ tag_title }} {% trans '标签' %}</title>
{% endblock %}
{% block head %}
{{ user.mastodon_username }} - {% trans '标签' %}
{{ tag_title }}
<br>
<small>{{ user.mastodon_username }}的{% trans '标签' %}</small>
{% endblock %}

View file

@ -493,10 +493,7 @@ def _render_list(
return render(
request,
f"user_{type}_list.html",
{
"user": user,
"members": members,
},
{"user": user, "members": members, "tag_title": tag_title},
)

View file

@ -13,7 +13,7 @@
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>{{ site_name }} - {% trans '动态' %}</title>
{% include "common_libs.html" with jquery=1 %}
{% include "common_libs.html" with jquery=0 %}
<script src="{% static 'js/mastodon.js' %}"></script>
<script src="{% static 'js/home.js' %}"></script>
</head>

View file

@ -1,6 +1,6 @@
$(document).ready( function() {
let token = $("#oauth2Token").text();
let mast_uri = $("#mastodonURI").text();
let mast_domain = new URL(mast_uri);
@ -14,7 +14,7 @@ $(document).ready( function() {
let followingSpinner = $("#spinner").clone().removeAttr("hidden");
let mainSpinner = $("#spinner").clone().removeAttr("hidden");
$(".mast-user:first").hide();
$(".mast-user").first().hide();
$(".mast-user-list").append(mainSpinner);
$("#userInfoCard").append(userInfoSpinner);
@ -98,7 +98,7 @@ $(document).ready( function() {
}
temp.find("a").attr('href', url);
temp.find(".mast-brief").text(data.note.replace(/(<([^>]+)>)/ig,""));
$(".mast-user:last").after(temp);
$(".mast-user").last().after(temp);
});
mainSpinner.hide();
@ -146,7 +146,7 @@ $(document).ready( function() {
$(document.body).on('touchmove', () => {
let scrollPosition = $(window).scrollTop();
// test if scoll to bottom
// test if scoll to bottom
// mobile phone has extra offset
if (scrollPosition + $(window).height() > $(document).height() - 70) {
onScroll();
@ -154,15 +154,15 @@ $(document).ready( function() {
});
$(window).scroll(function () {
$(window).on("scroll", function () {
let scrollPosition = $(window).scrollTop();
// test if scoll to bottom
// test if scoll to bottom
if (scrollPosition + $(window).height() > $(document).height() - 0.5) {
onScroll();
}
});
function onScroll() {
if (!requesting && nextUrl) {
// acquire lock
@ -182,7 +182,7 @@ $(document).ready( function() {
mainSpinner.hide();
return;
}
let template = $(".mast-user:first").clone().show();
let template = $(".mast-user").first().clone().show();
let newUrlFlag = false;
request.getResponseHeader('link').split(',').forEach(link => {
if (link.includes('next')) {
@ -211,12 +211,12 @@ $(document).ready( function() {
temp.find("a").attr('href', url);
temp.find(".mast-brief").text(data.note.replace(/(<([^>]+)>)/ig, ""));
// console.log($(temp).html())
$(".mast-user:last").after(temp);
$(".mast-user").last().after(temp);
});
mainSpinner.hide();
// release lock
// release lock
// console.log(userList[userList.length-1].username)
// console.log(nextUrl)
// console.log(nextUrl)
requesting = false;
},
});

View file

@ -1,6 +1,6 @@
$(document).ready( function() {
let token = $("#oauth2Token").text();
let mast_uri = $("#mastodonURI").text();
let mast_domain = new URL(mast_uri);
@ -14,7 +14,7 @@ $(document).ready( function() {
let followingSpinner = $("#spinner").clone().removeAttr("hidden");
let mainSpinner = $("#spinner").clone().removeAttr("hidden");
$(".mast-user:first").hide();
$(".mast-user").first().hide();
$(".mast-user-list").append(mainSpinner);
$("#userInfoCard").append(userInfoSpinner);
@ -136,7 +136,7 @@ $(document).ready( function() {
}
temp.find("a").attr('href', url);
temp.find(".mast-brief").text(data.note.replace(/(<([^>]+)>)/ig,""));
$(".mast-user:last").after(temp);
$(".mast-user").last().after(temp);
});
mainSpinner.hide();
@ -146,22 +146,22 @@ $(document).ready( function() {
$(document.body).on('touchmove', () => {
let scrollPosition = $(window).scrollTop();
// test if scoll to bottom
// test if scoll to bottom
// mobile phone has extra offset
if (scrollPosition + $(window).height() > $(document).height() - 70) {
onScroll();
}
});
$(window).scroll(function() {
$(window).on("scroll", function() {
let scrollPosition = $(window).scrollTop();
// test if scoll to bottom
// test if scoll to bottom
if (scrollPosition + $(window).height() > $(document).height() - 0.5) {
onScroll();
}
});
function onScroll() {
if (!requesting && nextUrl) {
// acquire lock
@ -181,7 +181,7 @@ $(document).ready( function() {
mainSpinner.hide();
return;
}
let template = $(".mast-user:first").clone().show();
let template = $(".mast-user").first().clone().show();
let newUrlFlag = false;
request.getResponseHeader('link').split(',').forEach(link => {
if (link.includes('next')) {
@ -211,12 +211,12 @@ $(document).ready( function() {
temp.find("a").attr('href', url);
temp.find(".mast-brief").text(data.note.replace(/(<([^>]+)>)/ig, ""));
// console.log($(temp).html())
$(".mast-user:last").after(temp);
$(".mast-user").last().after(temp);
});
mainSpinner.hide();
// console.log(userList[userList.length-1].username)
// console.log(nextUrl)
// release lock
// console.log(nextUrl)
// release lock
requesting = false;
},
});

View file

@ -12,7 +12,7 @@
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>{{ site_name }} - 数据管理</title>
{% include "common_libs.html" with jquery=1 %}
{% include "common_libs.html" with jquery=0 %}
<script src="{% static 'js/mastodon.js' %}"></script>
<script src="{% static 'js/home.js' %}"></script>
</head>

View file

@ -20,7 +20,7 @@
<div id="page-wrapper">
<div id="content-wrapper">
{% include "partial/_navbar.html" %}
<section id="content">
<div class="grid">
<div class="single-section-wrapper" id="main">
@ -30,19 +30,19 @@
<input class="button" type="submit" value="{% trans '提交' %}">
</form>
</div>
</div>
</section>
</div>
{% include "partial/_footer.html" %}
</div>
<script>
// preview uploaded pic
$("input[type='file']").change(function () {
$("input[type='file']").on("change", function () {
if (this.files && this.files[0]) {
var reader = new FileReader();
@ -52,7 +52,7 @@
reader.readAsDataURL(this.files[0]);
}
});
});
</script>
</body>