Skip to content
Draft
10 changes: 10 additions & 0 deletions forum/qa-plugin/outdated-question-info/frontend/css/styles.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
.qa-outdated-question-container{
width: 100%;

text-align: center;
padding: 4%;

border: 6px solid #f74040;
margin-bottom: 5%;
font-size: 1.5rem;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
const showInfoAboutOutdatedQuestion = () => {
const publishDateSpan = document.querySelector('.published > .value-title');
const placeOfOutdatedQuestionInfo = document.querySelector('.qa-a-form');

const now = new Date();
const publishDate = new Date(publishDateSpan.title);

const publishYearOlderThanNow = publishDate.getFullYear() < now.getFullYear();
const publishMonthNewerThanNow = publishDate.getMonth() - 1 >= now.getMonth();
const doesQuestionElemExist = document.querySelector('.qa-outdated-question-container');

if (publishYearOlderThanNow && publishMonthNewerThanNow && !doesQuestionElemExist) {
placeOfOutdatedQuestionInfo.insertAdjacentHTML('beforebegin',
`<p class = "qa-outdated-question-container">
To pytanie zostało zadane ponad 2 miesiące temu i może być już nieaktualne.<br/>
Zastanów się, czy na pewno chcesz "odkopać" to pytanie.
</p>`);
}
}
if(document.querySelector('.qa-a-form')){
const placeOfOutdatedQuestionInfo = document.querySelector('.qa-a-form');
if(placeOfOutdatedQuestionInfo.getAttribute('style') === "display:none;"){
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wcześniej to przeoczyłem, myśląc że placeOfOutdatedQuestionInfo jest wyżej pobrane z DOM tylko po to, aby przekazać go zaraz do funkcji showInfoAboutOutdatedQuestion. Ale skoro ta zmienna jest używana w tym warunku, to jednak lepiej przekazać ją do funkcji, niż tam pobierać drugi raz to samo - czyli poprzednia wersja była ok.

Aczkolwiek, żeby nie commitować takiej w sumie mało istotnej zmiany osobno, to IMO lepiej ewentualnie przyłączyć ją do jakichś pozostałych - o ile będą.

document.querySelector('#q_doanswer').addEventListener('click', showInfoAboutOutdatedQuestion);
}else{
showInfoAboutOutdatedQuestion();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php

class qa_html_theme_layer extends qa_html_theme_base
{
public function head_script(){
parent::head_script();
$this->output('
<script src = "'. QA_HTML_THEME_LAYER_URLTOROOT .'frontend/show-outdated-question-info.js?v=" defer></script>
<link rel = "stylesheet" href = "'. QA_HTML_THEME_LAYER_URLTOROOT .'frontend/css/styles.css?v=" />
');
}
}
9 changes: 9 additions & 0 deletions forum/qa-plugin/outdated-question-info/qa-plugin.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php

//Don't let this page to be available directly from browser
if (!defined('QA_VERSION')) {
header('Location: ../../');
exit;
}

qa_register_plugin_layer('qa-outdated-question-info-layer.php', 'Outdated Question Info');