remove unused js

This commit is contained in:
Your Name 2023-01-26 21:24:37 -05:00 committed by Henri Dickson
parent 945d3c2058
commit 97d13e94f1
8 changed files with 10 additions and 401 deletions

View file

@ -28,7 +28,7 @@ function catalog_init(context) {
$(this).addClass('entity-desc__content--folded');
$(this).siblings(".entity-desc__unfold-button").removeClass("entity-desc__unfold-button--hidden");
}
copy.remove();
copy.remove();
});
// expand hidden long text
@ -42,4 +42,5 @@ $(function() {
document.body.addEventListener('htmx:load', function(evt) {
catalog_init(evt.detail.elt);
});
catalog_init(document.body);
});

View file

@ -15,20 +15,14 @@
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>{{ site_name }} - {% trans '搜索结果' %}</title>
<script src="https://cdn.staticfile.org/jquery/3.6.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/htmx/1.8.4/htmx.min.js"></script>
<script src="{% static 'lib/js/rating-star.js' %}"></script>
<script src="{% static 'js/rating-star-readonly.js' %}"></script>
<link rel="stylesheet" href="{% static 'css/boofilsic.min.css' %}">
<link rel="stylesheet" href="{% static 'lib/css/rating-star.css' %}">
<link rel="stylesheet" href="{% static 'lib/css/collection.css' %}">
{% 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">
@ -53,12 +47,12 @@
</div>
</div>
</div>
</div>
</div>
{% include "search_sidebar.html" %}
</div>
@ -67,8 +61,8 @@
{% include 'partial/_footer.html' %}
</div>
<script>
document.body.addEventListener('htmx:configRequest', (event) => {
event.detail.headers['X-CSRFToken'] = '{{ csrf_token }}';

View file

@ -1,27 +0,0 @@
$(document).ready( function() {
$(".markdownx-preview").hide();
$(".markdownx textarea").attr("placeholder", "从剪贴板粘贴或者拖拽文件至编辑框即可插入图片");
$(".review-form__preview-button").on('click', function() {
if ($(".markdownx-preview").is(":visible")) {
$(".review-form__preview-button").text("预览");
$(".markdownx-preview").hide();
$(".markdownx textarea").show();
} else {
$(".review-form__preview-button").text("编辑");
$(".markdownx-preview").show();
$(".markdownx textarea").hide();
}
});
let ratingLabels = $(".rating-star");
$(ratingLabels).each( function(index, value) {
let ratingScore = $(this).data("rating-score") / 2;
$(this).starRating({
initialRating: ratingScore,
readOnly: true,
});
});
});

View file

@ -1,137 +0,0 @@
$(document).ready( function() {
$(".modal-close").on('click', function() {
$(this).parents(".modal").hide();
$(".bg-mask").hide();
});
// pop up new rating modal
$("#addMarkPanel button").each(function() {
$(this).on('click', function(e) {
e.preventDefault();
let title = $(this).text().trim();
$(".mark-modal__title").text(title);
$(".mark-modal__body textarea").val("");
let status = $(this).data('status')
$("input[name='status'][value='"+status+"']").prop("checked", true)
$(".bg-mask").show();
$(".mark-modal").show();
// if wish, hide rating widget in modal
if ($(this).attr("id") == "wishButton") {
// console.log($(this).attr("id"))
$(".mark-modal .rating-star-edit").hide();
} else {
$(".mark-modal .rating-star-edit").show();
}
});
})
// pop up modify mark modal
$(".mark-panel a.edit").on('click', function(e) {
e.preventDefault();
let title = $(".mark-panel__status").text().trim();
$(".mark-modal__title").text(title);
$(".bg-mask").show();
$(".mark-modal").show();
});
// readonly star rating of detail display section
let ratingLabels = $("#main .rating-star");
$(ratingLabels).each( function(index, value) {
let ratingScore = $(this).data("rating-score") / 2;
$(this).starRating({
initialRating: ratingScore,
readOnly: true,
});
});
// readonly star rating at aside section
ratingLabels = $("#aside .rating-star");
$(ratingLabels).each( function(index, value) {
let ratingScore = $(this).data("rating-score") / 2;
$(this).starRating({
initialRating: ratingScore,
readOnly: true,
starSize: 15,
});
});
// editable rating star in modal
ratingLabels = $("#modals .rating-star-edit");
$(ratingLabels).each( function(index, value) {
let ratingScore = $("input[type='hidden'][name='rating']").val() / 2;
let label = $(this);
label.starRating({
initialRating: ratingScore,
starSize: 20,
onHover: function(currentIndex, currentRating, $el){
$("input[type='hidden'][name='rating']").val(currentIndex);
},
onLeave: function(currentIndex, currentRating, $el){
$("input[type='hidden'][name='rating']").val(currentRating * 2);
}
});
});
// hide rating star when select wish
const WISH_CODE = "wish";
if ($("#statusSelection input[type='radio']:checked").val() == WISH_CODE) {
$(".mark-modal .rating-star-edit").hide();
}
$("#statusSelection input[type='radio']").on('click', function() {
if ($(this).val() == WISH_CODE) {
$(".mark-modal .rating-star-edit").hide();
} else {
$(".mark-modal .rating-star-edit").show();
}
});
// show confirm modal
$(".mark-panel a.delete").on('click', function(e) {
e.preventDefault();
$(".confirm-modal").show();
$(".bg-mask").show();
});
// confirm modal
$(".confirm-modal input[type='submit']").on('click', function(e) {
e.preventDefault();
$(".mark-panel form").submit();
});
// hide long text
$(".entity-desc__content").each(function() {
let copy = $(this).clone()
.addClass('entity-desc__content--folded')
.css("visibility", "hidden");
$(this).after(copy);
if ($(this).height() > copy.height()) {
$(this).addClass('entity-desc__content--folded');
$(this).siblings(".entity-desc__unfold-button").removeClass("entity-desc__unfold-button--hidden");
}
copy.remove();
});
// expand hidden long text
$(".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.on('click', function() {
confirmDeleteMarkButton.prop("disabled", true);
});
// disable sumbit button after click
const confirmSumbitMarkButton = $('.mark-modal__confirm-button > input');
confirmSumbitMarkButton.on('click', function() {
confirmSumbitMarkButton.prop("disabled", true);
confirmSumbitMarkButton.closest('form')[0].submit();
});
});

View file

@ -129,116 +129,4 @@ $(document).ready( function() {
onClickDropdownButton();
}
};
// import panel
$("#uploadBtn").on('click', e => {
const btn = $("#uploadBtn")
const form = $(".import-panel__body form")
// validate form
let isValidForm = form[0].checkValidity();
if (!isValidForm) {
if (form[0].reportValidity) {
form[0].reportValidity();
} else {
alert("Invalid File");
}
return
}
e.preventDefault();
let formData = new FormData(form[0]);
// disable submit button
btn.prop('disabled', true);
// show progress bar & hide last status
$(".import-panel__progress").show();
$(".import-panel__last-task").hide();
// flush failed urls
$("#failedUrls").html("");
// reset progress bar
$("#importProgress").attr("max", 1);
$("#importProgress").attr("value", 0);
$("#progressPercent").text('0%');
$.ajax({
url: form.attr("action"),
type: 'POST',
data: formData,
contentType: false,
dataType: "json",
processData: false,
enctype: form.attr("enctype"),
success: function (response) {
// console.log(response);
// long polling
poll();
},
error: function (response) {
// console.log(response)
},
complete: function (response) {
// console.log(response)
},
});
});
// if progress is visible start to poll
if ($(".import-panel__progress").is(":visible")) {
poll();
}
// long polling function
const pollingInterval = 1500;
function poll() {
$.ajax({
url: $("#querySyncInfoURL").data("url"),
success: function (data) {
// console.log(data);
const progress = $("#importProgress");
const percent = $("#progressPercent");
if (!data.is_finished) {
// update progress bar
if (!data.total_items == 0) {
progress.attr("max", data.total_items);
progress.attr("value", data.finished_items);
progress.attr("value", data.finished_items);
percent.text("" + data.finished_items + "/" + data.total_items);
}
setTimeout(() => {
poll();
}, pollingInterval);
} else {
// task finishes
// update progress bar
percent.text('100%');
progress.attr("max", 1);
progress.attr("value", 1);
$("#uploadBtn").prop('disabled', false);
// update last task summary
$("#lastTaskTotalItems").text(data.total_items);
$("#lastTaskSuccessItems").text(data.success_items);
$("#lastTaskStatus").text(data.status);
// display failed urls
if (data.failed_urls.length > 0) {
$(".import-panel__fail-urls").show();
data.failed_urls.forEach((v, i) => {
$("#failedUrls").append($("<li>" + v + "</li>"));
});
}
// hide progress & show last task
$(".import-panel__progress").hide();
$(".import-panel__last-task").show();
}
},
dataType: "json",
complete: () => {
// setTimeout(() => {
// poll();
// }, pollingInterval);
},
});
}
});

View file

@ -1,16 +0,0 @@
$(document).ready( function() {
let render = function() {
let ratingLabels = $(".rating-star");
$(ratingLabels).each( function(index, value) {
let ratingScore = $(this).data("rating-score") / 2;
$(this).starRating({
initialRating: ratingScore,
readOnly: true
});
});
};
document.body.addEventListener('htmx:load', function(evt) {
render();
});
render();
});

View file

@ -1,93 +0,0 @@
$(document).ready( function() {
$(".submit").on('click', function(e) {
e.preventDefault();
let form = $("#scrapeForm form");
if (form.data('submitted') === true) {
// Previously submitted - don't submit again
} else {
// Mark it so that the next submit can be ignored
form.data('submitted', true);
$("#scrapeForm form").submit();
}
});
// assume there is only one input[file] on page
// $("input[type='file']").each(function() {
// $(this).after('<img src="#" alt="" id="previewImage" style="margin:10px 0; max-width:500px;"/>');
// });
// preview uploaded pic
$("input[type='file']").on("change", function() {
if (this.files && this.files[0]) {
var reader = new FileReader();
reader.onload = function (e) {
$('#previewImage').attr('src', e.target.result);
}
reader.readAsDataURL(this.files[0]);
}
});
$("#parser textarea").on('paste', function(e) {
// access the clipboard using the api
let pastedData = e.originalEvent.clipboardData.getData('text');
let lines = pastedData.split('\n')
lines.forEach(line => {
words = line.split(': ');
if (words.length > 1) {
switch (words[0]) {
case '作者':
authors = words[1].replace(' / ', ',');
$("input[name='author']").val(authors);
break;
case '译者':
translators = words[1].replace(' / ', ',');
$("input[name='translator']").val(translators);
break;
case '出版社':
$("input[name='pub_house']").val(words[1]);
break;
case '页数':
let tmp = Number(words[1]);
$("input[name='pages']").val(tmp);
break;
case '出版年':
let regex = /\d+\d*/g;
let figures = words[1].match(regex)
figures.forEach(figure => {
if (figure > 1000) $("input[name='pub_year']").val(figure);
else if (figure < 13) $("input[name='pub_month']").val(figure);
});
break;
case '定价':
$("input[name='price']").val(words[1]);
break;
case '装帧':
$("input[name='binding']").val(words[1]);
break;
case 'ISBN':
$("input[name='isbn']").val(words[1]);
break;
case '副标题':
$("input[name='subtitle']").val(words[1]);
break;
case '原作名':
$("input[name='orig_title']").val(words[1]);
break;
case '语言':
$("input[name='language']").val(words[1]);
break;
default:
$(".widget-value-key-input :nth-last-child(2)").val(words[0]);
$(".widget-value-key-input :nth-last-child(1)").val(words[1]);
$(".widget-value-key-input :nth-last-child(1)").trigger("input");
break;
}
}
});
});
});

View file

@ -19,7 +19,6 @@
<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=0 %}
<script src="{% static 'js/mastodon.js' %}" defer></script>
<script src="{% static 'js/home.js' %}" defer></script>
</head>