94 lines
3.0 KiB
JavaScript
94 lines
3.0 KiB
JavaScript
(function(context,$) {
|
|
|
|
"use strict";
|
|
context.JK = context.JK || {};
|
|
context.JK.SessionHoverBubble = function(sessionId, x, y) {
|
|
|
|
var logger = context.JK.logger;
|
|
var rest = context.JK.Rest();
|
|
var hoverSelector = "#session-hover";
|
|
|
|
this.showBubble = function() {
|
|
var mouseLeft = x < (document.body.clientWidth / 2);
|
|
var mouseTop = y < (document.body.clientHeight / 2);
|
|
var css = {};
|
|
if (mouseLeft)
|
|
css.left = x + 20 + 'px';
|
|
else
|
|
css.left = x - (25 + $(hoverSelector).width()) + 'px';
|
|
if (mouseTop)
|
|
css.top = y + 10 + 'px';
|
|
else
|
|
css.top = y - (7 + $(hoverSelector).height()) + 'px';
|
|
|
|
$(hoverSelector).css(css);
|
|
$(hoverSelector).fadeIn(500);
|
|
|
|
rest.getSessionHistory(sessionId)
|
|
.done(function(response) {
|
|
$(hoverSelector).html('');
|
|
|
|
// musicians
|
|
var musicianHtml = '';
|
|
$.each(response.users, function(index, val) {
|
|
var instrumentHtml = '';
|
|
|
|
musicianHtml += '<tr><td width="50"><a href="#" class="avatar-tiny"><img src="' + context.JK.resolveAvatarUrl(val.user.photo_url) + '" /></a></td>';
|
|
musicianHtml += '<td width="75"><a href="#">' + val.user.name + '</a></td>';
|
|
|
|
instrumentHtml = '<td><div class="nowrap">';
|
|
var instruments = val.instruments.split("|");
|
|
$.each(instruments, function(index, instrument) {
|
|
instrumentHtml += '<img src="' + context.JK.getInstrumentIcon24(instrument) + '" width="24" height="24" /> ';
|
|
});
|
|
|
|
instrumentHtml += '</div></td>';
|
|
|
|
musicianHtml += instrumentHtml;
|
|
musicianHtml += '</tr>';
|
|
});
|
|
|
|
var template = $('#template-hover-session').html();
|
|
|
|
var sessionHtml = context.JK.fillTemplate(template, {
|
|
musicSessionId: response.id,
|
|
description: response.description,
|
|
genre: response.genres.toUpperCase(),
|
|
comment_count: response.comment_count,
|
|
like_count: response.like_count,
|
|
created_at: $.timeago(response.created_at),
|
|
musicians: musicianHtml
|
|
});
|
|
|
|
$(hoverSelector).append('<h2>Session Detail</h2>' + sessionHtml);
|
|
toggleActionButtons();
|
|
})
|
|
.fail(function(xhr) {
|
|
if(xhr.status >= 500) {
|
|
context.JK.fetchUserNetworkOrServerFailure();
|
|
}
|
|
else if(xhr.status == 404) {
|
|
context.JK.entityNotFound("Session");
|
|
}
|
|
else {
|
|
context.JK.app.ajaxError(arguments);
|
|
}
|
|
});
|
|
};
|
|
|
|
function toggleActionButtons() {
|
|
if (!context.JK.currentUserId) {
|
|
$("#btnLike", hoverSelector).hide();
|
|
$("#btnShare", hoverSelector).hide();
|
|
}
|
|
}
|
|
|
|
this.hideBubble = function() {
|
|
$(hoverSelector).hide();
|
|
};
|
|
|
|
this.id = function() {
|
|
return hoverSelector;
|
|
};
|
|
}
|
|
})(window,jQuery); |