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