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

73 lines
1.9 KiB
JavaScript
Raw Normal View History

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