Skip to content
Draft
17 changes: 17 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,17 @@
.qa-outdated-question-container{
width: 100%;

text-align: center;
padding: 1%;

border: 6px solid #f74040;
margin-bottom: 2.5%;
font-size: 1.30rem;
}

.hidden{
display: none;
}



Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
const placeOfOutdatedQuestionInfo = document.querySelector('.qa-a-form');
if(placeOfOutdatedQuestionInfo){
const publishDateSpan = document.querySelector('.published > .value-title');
const now = new Date();
const publishDate = new Date(publishDateSpan.title);
const publishYearOlderThanNow = publishDate.getFullYear() < now.getFullYear();
const publishMonthNewerThanNow = publishDate.getMonth() - 1 >= now.getMonth();

if (publishYearOlderThanNow || publishMonthNewerThanNow) {
const outdatedQuestionInfoVisibility = placeOfOutdatedQuestionInfo.style.display === 'none' ? 'hidden' : '';
placeOfOutdatedQuestionInfo.insertAdjacentHTML('beforebegin',
`<p class = "qa-outdated-question-container ${outdatedQuestionInfoVisibility}">
To pytanie zostało zadane już dawno temu i może być nieaktualne.<br/>
Upewnij się, że Twoja odpowiedź nadal będzie pomocna.
</p>`);
}
const questionElemExist = document.querySelector('.qa-outdated-question-container');

if(questionElemExist){
const outdatedInfoContainerClassList = questionElemExist.classList;
const doesCancelButtonExist = !CKEDITOR.instances.a_content;

document.querySelector('#q_doanswer').addEventListener('click', ()=>{
outdatedInfoContainerClassList.toggle('hidden');
Copy link
Member

Choose a reason for hiding this comment

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

Nie .toggle('hidden') tylko .remove('hidden') - eksplicytnie usuwamy klasę (pokazując tym samym komunikat) na kliknięcie w przycisk dodający odpowiedź. Tak jak pokazałem w komentarzu.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Nie jestem pewny czy to mogłoby zadziałać. Formularz odpowiedzi możemy zamknąć również przyciskiem otwierania odpowiedzi, a nie tylko czerwonym anuluj. Toggle jest tu aby nie było jasno narzucone, którym przyciskiem mamy zamykać formularz

Copy link
Member

@ScriptyChris ScriptyChris Jun 23, 2022

Choose a reason for hiding this comment

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

Faktycznie, przycisk "Odpowiedz" toggluje formularz z edytorem - nie zauważyłem. Więc .toggle('hidden') może zostać.

questionElemExist.scrollIntoView({ behavior: "smooth", block:'start', inline: 'start'})

if(doesCancelButtonExist){
const cancelAnswer = CKEDITOR.instances.a_content.element.$.form.docancel;
cancelAnswer.addEventListener('click', ()=>{
outdatedInfoContainerClassList.toggle('hidden');
Copy link
Member

Choose a reason for hiding this comment

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

Nie .toggle('hidden') tylko .add('hidden') - eksplicytnie dodajemy klasę (ukrywając tym samym komunikat) na kliknięcie w przycisk anulujący odpowiedź. Tak jak pokazałem w komentarzu.

}, {once: true});
}

})
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php

class qa_html_theme_layer extends qa_html_theme_base
{
public function head_script(){
parent::head_script();
if(qa_get_logged_in_userid()){
$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');