mirror of
https://github.com/commercialhaskell/stackage-server.git
synced 2026-01-12 04:08:29 +01:00
112 lines
2.8 KiB
Plaintext
112 lines
2.8 KiB
Plaintext
$(function(){
|
|
var loggedIn = $('.user-handle').length > 0;
|
|
var tags = Object.create(null);
|
|
$('.tags').find('.tag').each(function(){
|
|
tags[$(this).find('a').text()] = true;
|
|
});
|
|
$('.expanding').each(function(){
|
|
var $this = $(this);
|
|
if ($this.height() > 300) {
|
|
$this.addClass('collapsed');
|
|
$this.find('.bottom-gradient').click(function(){
|
|
$this.removeClass('collapsed');
|
|
});
|
|
}
|
|
});
|
|
$('#like').click(function(){
|
|
var $this = $(this);
|
|
|
|
if (loggedIn) {
|
|
var action = 'like';
|
|
if ($this.hasClass('fa-thumbs-up')) {
|
|
action = 'unlike';
|
|
}
|
|
|
|
$this.toggleClass('fa-thumbs-up');
|
|
$this.toggleClass('fa-thumbs-o-up');
|
|
|
|
$likes = $('#likes');
|
|
nLikes = parseInt($likes.text(), 10);
|
|
|
|
if (action == 'like') {
|
|
$this.attr('title','You liked this!');
|
|
$likes.text(nLikes + 1);
|
|
$.post("@{PackageLikeR pn}");
|
|
} else {
|
|
$this.attr('title','You disliked this.');
|
|
$likes.text(nLikes - 1);
|
|
$.post("@{PackageUnlikeR pn}");
|
|
}
|
|
} else {
|
|
login();
|
|
}
|
|
});
|
|
$('#add-tag').click(function(){
|
|
if (!loggedIn) login();
|
|
$('#add-tag-form').toggleClass('hidden');
|
|
$('#new-tag').focus();
|
|
});
|
|
$('#new-tag').change(function(){
|
|
$('#add-form-btn').val('Confirm');
|
|
$('#tag-msg').hide();
|
|
});
|
|
$('#new-tag').keypress(function(){
|
|
$('#add-form-btn').val('Confirm');
|
|
});
|
|
$('#add-tag-form').submit(function(){
|
|
try {
|
|
var candidate = $('#new-tag').val();
|
|
var normalized = candidate
|
|
.replace(/[^a-zA-Z0-9-.]/g,'-')
|
|
.replace(/-+/g,'-')
|
|
.replace(/^-/,'')
|
|
.replace(/-$/,'')
|
|
.toLowerCase();
|
|
if (candidate !== normalized) {
|
|
$('#new-tag').val(normalized);
|
|
$('#add-form-btn').val('Done');
|
|
} else {
|
|
$.ajax({
|
|
method: 'POST',
|
|
url: '@{PackageTagR pn}',
|
|
data: {slug:normalized},
|
|
success: function(){
|
|
|
|
$('.no-tags').remove();
|
|
|
|
$('#new-tag').val('');
|
|
$('#add-form-btn').val('Confirm');
|
|
|
|
if (!tags[normalized]) {
|
|
var tag = $('<span><a></a></span>');
|
|
tag.find('a').text(normalized);
|
|
$('.tags').prepend(', ');
|
|
$('.tags').prepend(tag);
|
|
}
|
|
|
|
tags[normalized] = true;
|
|
},
|
|
error: function(err){
|
|
$('#tag-msg').text('invalid slug; too short or too long').show();
|
|
}
|
|
});
|
|
}
|
|
} finally {
|
|
return false;
|
|
}
|
|
});
|
|
});
|
|
|
|
// Workaround for missing functionality in IE 8 and earlier.
|
|
if( Object.create === undefined ) {
|
|
Object.create = function( o ) {
|
|
function F(){}
|
|
F.prototype = o;
|
|
return new F();
|
|
};
|
|
}
|
|
|
|
function login(){
|
|
window.location.href = '@{AuthR LoginR}';
|
|
}
|