2014-11-12 12:14:37 +01:00
|
|
|
var $ = require('unopinionate').selector
|
|
|
|
var onClick = require('onclick')
|
|
|
|
var 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() {
|
|
|
|
var $this = $(this)
|
|
|
|
var $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())
|
|
|
|
.removeClass('open')
|
2014-05-07 23:51:03 +02:00
|
|
|
|
2014-11-12 12:14:37 +01:00
|
|
|
setTimeout(function() {
|
|
|
|
$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() {
|
|
|
|
$entry.find('.readme').remove()
|
|
|
|
$entry.css('height', 'auto')
|
|
|
|
})
|
2014-05-08 18:13:39 +02:00
|
|
|
|
2014-11-12 12:14:37 +01:00
|
|
|
} else {
|
|
|
|
// Open entry
|
|
|
|
$('.entry.open').each(function() {
|
|
|
|
// Close open entries
|
|
|
|
var $entry = $(this)
|
|
|
|
$entry
|
|
|
|
.height($entry.outerHeight())
|
|
|
|
.removeClass('open')
|
2014-05-08 18:13:39 +02:00
|
|
|
|
2014-11-12 12:14:37 +01:00
|
|
|
setTimeout(function() {
|
|
|
|
$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() {
|
|
|
|
$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
|
|
|
|
$entry.addClass('open')
|
2014-05-07 23:51:03 +02:00
|
|
|
|
2014-11-12 12:14:37 +01:00
|
|
|
// Explicitly set heights for transitions
|
|
|
|
var height = $entry.outerHeight()
|
|
|
|
$entry
|
|
|
|
.attr('data-height', height)
|
|
|
|
.css('height', height)
|
2014-05-07 23:51:03 +02:00
|
|
|
|
2014-11-12 12:14:37 +01:00
|
|
|
// Get the data
|
|
|
|
$.ajax({
|
|
|
|
url: '-/readme/'+$entry.attr('data-name')+'/'+$entry.attr('data-version'),
|
|
|
|
dataType: 'text',
|
|
|
|
success: function(html) {
|
|
|
|
var $readme = $("<div class='readme'>")
|
|
|
|
.html(html)
|
|
|
|
.appendTo($entry)
|
2014-05-07 23:51:03 +02:00
|
|
|
|
2014-11-12 12:14:37 +01:00
|
|
|
$entry.height(height + $readme.outerHeight())
|
|
|
|
|
|
|
|
transitionComplete(function() {
|
|
|
|
$entry.css('height', 'auto')
|
|
|
|
})
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
})
|
|
|
|
})
|