Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 37 additions & 12 deletions lms/templates/wiki/history.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,39 @@

{% addtoblock "js" %}
<script type="text/javascript" src="{{ STATIC_URL }}wiki/js/diffview.js"></script>
<script type="text/javascript" src="{{ STATIC_URL }}wiki/js/diff.js"></script>
<script type="text/javascript">
$(document).ready(
function() {
$('.accordion input[disabled!="disabled"][type="radio"]').first().attr('checked', 'true');
// Fix modal heights
// $('.modal-body').css('height', $(window).height()*0.70 + 'px');
// $('.modal').css('max-height', $(window).height() + 'px');

$( document ).ready(function() {
$('.accordion input[disabled!="disabled"][type="radio"]').first().attr('checked', 'true');

$('a.accordion-toggle').click(function(event) {
event.preventDefault();
var diffUrl = $(event.target).attr('href');
var accordionBody = $(this).parentsUntil('.accordion').find('.accordion-body');

jsonWrapper(diffUrl, function (data) {
if (!accordionBody.find('.diff-container tbody').length > 0) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This basically loads content of accordion if it's not loaded, right?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yes. This function is taken from https://github.com/edx/django-wiki/blob/master/wiki/static/wiki/js/diff.js. I have just cleaned it up a bit and added a few lines to toggleClass('collapsed') and do focus() at the appropriate places.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

you should delete wiki/js/diff.js if we're not using it too

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Its in the django-wiki repo. Then we will have to create a PR there, and then update the commit id in the requirements file. So best to skip it for now.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

ok

accordionBody.parentsUntil('.accordion').find('.progress').show(0 , function() {
tbody = pydifferviewer.as_tbody({differ_output: data.diff});
accordionBody.find('.diff-container table').append(tbody);
if (data.other_changes) {
for (var i=0; i < data.other_changes.length; i++) {
accordionBody.find('dl').append($('<dt>'+data.other_changes[i][0]+'</dt>' +
'<dd>'+data.other_changes[i][1]+'</dd>' ));
}
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I'm not really qualified to truly PR this section as I'm not incredibly familiar with this accordion content code...but it seems somewhat reasonable?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

See note above. I have just changed the name of the div. Otherwise the logic is the same as before.

accordionBody.parentsUntil('.accordion').find('.progress').detach();
accordionBody.removeClass('collapse');
accordionBody.focus();
});
} else {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

If the accordion content IS loaded, toggle collapse and focus it?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yup.

accordionBody.toggleClass('collapse');
if (!accordionBody.hasClass('collapse')) {
accordionBody.focus();
}

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Focus diff details after uncollapsing it.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This handler was previously in diff.js in the django-wiki repo. I have copied it over to remove twitter bootstrap collapse module whose behavior was causing screen readers to start reading from the start.

}
});
});
});
</script>
{% endaddtoblock %}
Expand Down Expand Up @@ -62,7 +87,7 @@
<div class="accordion" id="accordion{{ revision.revision_number }}">
<div class="accordion-group">
<div class="accordion-heading">
<a class="accordion-toggle" style="float: left;" href="#collapse{{ revision.revision_number }}" onclick="get_diff_json('{% url 'wiki:diff' revision.id %}', $('#collapse{{ revision.revision_number }}'))">
<a class="accordion-toggle" style="float: left;" href="{% url 'wiki:diff' revision.id %}">
<span class="icon-plus"></span>
{% include "wiki/includes/revision_info.html" with current_revision=article.current_revision %}
<div style="color: #CCC;">
Expand Down Expand Up @@ -95,7 +120,7 @@
</div>
<div style="clear: both"></div>
</div>
<div id="collapse{{ revision.revision_number }}" class="accordion-body collapse">
<div id="collapse{{ revision.revision_number }}" class="accordion-body collapse" tabindex="0">

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Make revision details div keyboard focusable.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Again, looks completely sane.

<div class="accordion-inner diff-container" style="padding: 0;">
<dl class="dl-horizontal">
<dt>{% trans "Auto log:" %}</dt>
Expand All @@ -104,9 +129,9 @@
<table class="table table-condensed" style="margin: 0; border-collapse: collapse;">
<thead>
<tr>
<th class="linenumber">{% if revision.previous_revision %}#{{revision.previous_revision.revision_number}}{% endif %}</th>
<th class="linenumber">#{{revision.revision_number}}</th>
<th>{% trans "Change" %}</th>
<th scope="col" class="linenumber">{% if revision.previous_revision %}#{{revision.previous_revision.revision_number}}{% endif %}</th>
<th scope="col" class="linenumber">#{{revision.revision_number}}</th>
<th scope="col">{% trans "Change" %}</th>
</tr>

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Annotate table cells.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Follows W3 table a11y syntax so, this lgtm...

</thead>
</table>
Expand Down