2017-04-23 20:02:26 +02:00
|
|
|
let $ = require('unopinionate').selector;
|
|
|
|
let onClick = require('onclick');
|
|
|
|
let transitionComplete = require('transition-complete');
|
2014-05-07 21:56:48 +02:00
|
|
|
|
|
|
|
$(function() {
|
2014-11-12 12:14:37 +01:00
|
|
|
onClick('.entry .name', function() {
|
2017-04-23 20:02:26 +02:00
|
|
|
let $this = $(this);
|
|
|
|
let $entry = $this.closest('.entry');
|
2014-05-07 21:56:48 +02:00
|
|
|
|
2014-11-12 12:14:37 +01:00
|
|
|
if ($entry.hasClass('open')) {
|
|
|
|
// Close entry
|
|
|
|
$entry
|
|
|
|
.height($entry.outerHeight())
|
2017-04-23 20:02:26 +02:00
|
|
|
.removeClass('open');
|
2014-05-07 23:51:03 +02:00
|
|
|
|
2014-11-12 12:14:37 +01:00
|
|
|
setTimeout(function() {
|
2017-04-23 20:02:26 +02:00
|
|
|
$entry.css('height', $entry.attr('data-height') + 'px');
|
|
|
|
}, 0);
|
2014-05-07 23:51:03 +02:00
|
|
|
|
2014-11-12 12:14:37 +01:00
|
|
|
transitionComplete(function() {
|
2017-04-23 20:02:26 +02:00
|
|
|
$entry.find('.readme').remove();
|
|
|
|
$entry.css('height', 'auto');
|
|
|
|
});
|
2014-11-12 12:14:37 +01:00
|
|
|
} else {
|
|
|
|
// Open entry
|
|
|
|
$('.entry.open').each(function() {
|
|
|
|
// Close open entries
|
2017-04-23 20:02:26 +02:00
|
|
|
let $entry = $(this);
|
2014-11-12 12:14:37 +01:00
|
|
|
$entry
|
|
|
|
.height($entry.outerHeight())
|
2017-04-23 20:02:26 +02:00
|
|
|
.removeClass('open');
|
2014-05-08 18:13:39 +02:00
|
|
|
|
2014-11-12 12:14:37 +01:00
|
|
|
setTimeout(function() {
|
2017-04-23 20:02:26 +02:00
|
|
|
$entry.css('height', $entry.attr('data-height') + 'px');
|
|
|
|
}, 0);
|
2014-05-07 23:51:03 +02:00
|
|
|
|
2014-11-12 12:14:37 +01:00
|
|
|
transitionComplete(function() {
|
2017-04-23 20:02:26 +02:00
|
|
|
$entry.find('.readme').remove();
|
|
|
|
$entry.css('height', 'auto');
|
|
|
|
});
|
|
|
|
});
|
2014-05-07 21:56:48 +02:00
|
|
|
|
2014-11-12 12:14:37 +01:00
|
|
|
// Add the open class
|
2017-04-23 20:02:26 +02:00
|
|
|
$entry.addClass('open');
|
2014-05-07 23:51:03 +02:00
|
|
|
|
2014-11-12 12:14:37 +01:00
|
|
|
// Explicitly set heights for transitions
|
2017-04-23 20:02:26 +02:00
|
|
|
let height = $entry.outerHeight();
|
2014-11-12 12:14:37 +01:00
|
|
|
$entry
|
|
|
|
.attr('data-height', height)
|
2017-04-23 20:02:26 +02:00
|
|
|
.css('height', height);
|
2014-05-07 23:51:03 +02:00
|
|
|
|
2014-11-12 12:14:37 +01:00
|
|
|
// Get the data
|
|
|
|
$.ajax({
|
2014-11-17 19:18:07 +01:00
|
|
|
url: '-/readme/'
|
|
|
|
+ encodeURIComponent($entry.attr('data-name')) + '/'
|
|
|
|
+ encodeURIComponent($entry.attr('data-version')),
|
2014-11-12 12:14:37 +01:00
|
|
|
dataType: 'text',
|
|
|
|
success: function(html) {
|
2017-04-23 20:02:26 +02:00
|
|
|
let $readme = $('<div class=\'readme\'>')
|
2014-11-12 12:14:37 +01:00
|
|
|
.html(html)
|
2017-04-23 20:02:26 +02:00
|
|
|
.appendTo($entry);
|
2014-05-07 23:51:03 +02:00
|
|
|
|
2017-04-23 20:02:26 +02:00
|
|
|
$entry.height(height + $readme.outerHeight());
|
2014-11-12 12:14:37 +01:00
|
|
|
|
|
|
|
transitionComplete(function() {
|
2017-04-23 20:02:26 +02:00
|
|
|
$entry.css('height', 'auto');
|
|
|
|
});
|
|
|
|
},
|
|
|
|
});
|
2014-11-12 12:14:37 +01:00
|
|
|
}
|
2017-04-23 20:02:26 +02:00
|
|
|
});
|
|
|
|
});
|