1
0
mirror of https://github.com/verdaccio/verdaccio.git synced 2024-11-13 03:35:52 +01:00
verdaccio/lib/GUI/js/entry.js
Alex Kocharin 6a778e8c17 change code style to jshttp
close #155, see reasons there

This is a huge commit, so let me know if it will cause
any trouble, I might consider reverting it if it's the case.
2014-11-12 17:37:43 +03:00

72 lines
1.8 KiB
JavaScript

var $ = require('unopinionate').selector
var onClick = require('onclick')
var transitionComplete = require('transition-complete')
$(function() {
onClick('.entry .name', function() {
var $this = $(this)
var $entry = $this.closest('.entry')
if ($entry.hasClass('open')) {
// Close entry
$entry
.height($entry.outerHeight())
.removeClass('open')
setTimeout(function() {
$entry.css('height', $entry.attr('data-height') + 'px')
}, 0)
transitionComplete(function() {
$entry.find('.readme').remove()
$entry.css('height', 'auto')
})
} else {
// Open entry
$('.entry.open').each(function() {
// Close open entries
var $entry = $(this)
$entry
.height($entry.outerHeight())
.removeClass('open')
setTimeout(function() {
$entry.css('height', $entry.attr('data-height') + 'px')
}, 0)
transitionComplete(function() {
$entry.find('.readme').remove()
$entry.css('height', 'auto')
})
})
// Add the open class
$entry.addClass('open')
// Explicitly set heights for transitions
var height = $entry.outerHeight()
$entry
.attr('data-height', height)
.css('height', height)
// 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)
$entry.height(height + $readme.outerHeight())
transitionComplete(function() {
$entry.css('height', 'auto')
})
}
})
}
})
})