Ensure that CW-expander is present when threads page is AJAX-loaded

This commit is contained in:
Jason McBrayer 2018-09-06 12:07:31 -04:00
parent 6e087eb45f
commit 4f8bba7765
3 changed files with 36 additions and 29 deletions

View File

@ -64,3 +64,32 @@ function menuPrepare() {
}
}
function expandCWButtonPrepare()
{
var theButton = document.createElement('p');
theButton.textContent = "Expand CWs";
theButton.classList.toggle('button');
document.querySelector('#title').insertAdjacentElement('afterend', theButton);
var details = document.querySelectorAll('details');
var openState = false;
if (details != null) {
theButton.addEventListener('click', function() {
openState = details.item(0).hasAttribute('open');
details.forEach(function ($el) {
if (openState)
{
$el.removeAttribute('open');
} else
{
$el.setAttribute('open', '');
}
});
openState = !openState;
if (openState) { theButton.textContent = 'Collapse CWs'; }
else { theButton.textContent = "Expand CWs"; };
theButton.classList.toggle('is-active');
});
};
}

View File

@ -29,37 +29,15 @@ mastodon.status_context(<numerical id>)
<hr class="is-hidden">
{% endfor %}
{% if not preferences.theme.is_brutalist %}
<script type="application/javascript">
Intercooler.ready(expandCWButtonPrepare);
</script>
{% endif %}
{% endblock %}
{% block page_scripts_inline %}
<script type="application/javascript">
document.addEventListener('DOMContentLoaded', function () {
var theButton = document.createElement('p');
theButton.textContent = "Expand CWs";
theButton.classList.toggle('button');
document.querySelector('#title').insertAdjacentElement('afterend', theButton);
var details = document.querySelectorAll('details');
var openState = false;
if (details != null) {
theButton.addEventListener('click', function() {
openState = details.item(0).hasAttribute('open');
details.forEach(function ($el) {
if (openState)
{
$el.removeAttribute('open');
} else
{
$el.setAttribute('open', '');
}
});
openState = !openState;
if (openState) { theButton.textContent = 'Collapse CWs'; }
else { theButton.textContent = "Expand CWs"; };
theButton.classList.toggle('is-active');
});
};
});
document.addEventListener('DOMContentLoaded', expandCWButtonPrepare);
</script>
{% endblock %}

View File

@ -144,7 +144,7 @@
ic-target="#main"
ic-select-from-response="#main"
ic-push-url="true"
ic-on-success="afterPage('{{ own_acct.username }}', 'thread');"
ic-on-success="afterPage('{{ own_acct.username }}', 'thread')"
ic-indicator="#page-load-indicator"">
thread
</a>