124 lines
4.0 KiB
JavaScript
124 lines
4.0 KiB
JavaScript
(function(context, $) {
|
|
|
|
context.JK.ShowRecording = function(app) {
|
|
var logger = context.JK.logger;
|
|
var rest = new JK.Rest();
|
|
var recordingId = null;
|
|
var claimedRecordingId = null;
|
|
var $scope = $(".landing-details");
|
|
var $controls = $('.recording-controls');
|
|
var $sliderBar = $('.recording-position');
|
|
var $statusBar = $('.recording-status');
|
|
var $currentTime = $('.recording-current');
|
|
var $status = $('.status-text');
|
|
var $playButton = $('.play-button');
|
|
var $playIcon = $('#imgPlayPause');
|
|
var playing = false;
|
|
|
|
function startPlay() {
|
|
$playIcon.attr('src', '/assets/content/icon_pausebutton.png');
|
|
$controls.trigger('play.listenRecording');
|
|
playing = true;
|
|
}
|
|
|
|
function stopPlay() {
|
|
$playIcon.attr('src', '/assets/content/icon_playbutton.png');
|
|
$controls.trigger('pause.listenRecording');
|
|
playing = false;
|
|
}
|
|
|
|
function togglePlay() {
|
|
|
|
if(playing) {
|
|
stopPlay();
|
|
}
|
|
else {
|
|
startPlay();
|
|
}
|
|
return false;
|
|
}
|
|
|
|
function stateChange(e, data) {
|
|
if(data.isEnd) stopPlay();
|
|
if(data.isError) {
|
|
$sliderBar.hide();
|
|
$playButton.hide();
|
|
$currentTime.hide();
|
|
$statusBar.show();
|
|
$status.text(data.displayText);
|
|
}
|
|
}
|
|
|
|
function like() {
|
|
rest.addRecordingLike(recordingId, claimedRecordingId, JK.currentUserId)
|
|
.done(function(response) {
|
|
$("#spnLikeCount").html(parseInt($("#spnLikeCount").text()) + 1);
|
|
$("#btnLike", $scope).unbind("click");
|
|
});
|
|
}
|
|
|
|
function play() {
|
|
rest.addPlayablePlay(recordingId, claimedRecordingId, JK.currentUserId)
|
|
.done(function(response) {
|
|
$("#spnPlayCount", $scope).html(parseInt($("#spnPlayCount").text()) + 1);
|
|
});
|
|
}
|
|
|
|
function addComment() {
|
|
var comment = $("#txtRecordingComment").val();
|
|
if ($.trim(comment).length > 0) {
|
|
rest.addRecordingComment(recordingId, JK.currentUserId, comment)
|
|
.done(function(response) {
|
|
$("#spnCommentCount", $scope).html(parseInt($("#spnCommentCount").text()) + 1);
|
|
|
|
var template = $('#template-landing-comment').html();
|
|
var commentHtml = context.JK.fillTemplate(template, {
|
|
avatar_url: context.JK.currentUserAvatarUrl,
|
|
name: context.JK.currentUserName,
|
|
comment: comment
|
|
});
|
|
|
|
$(".landing-comment-scroller").prepend(commentHtml);
|
|
});
|
|
}
|
|
}
|
|
|
|
function initialize(_claimedRecordingId, _recordingId) {
|
|
recordingId = _recordingId;
|
|
claimedRecordingId = _claimedRecordingId;
|
|
|
|
$('.timeago').timeago();
|
|
$playButton.click(togglePlay);
|
|
$controls.bind('statechange.listenRecording', stateChange);
|
|
|
|
$controls.listenRecording({recordingId: recordingId, claimedRecordingId: claimedRecordingId, sliderSelector:'.recording-slider', sliderBarSelector: '.recording-playback', currentTimeSelector:'.recording-current'});
|
|
|
|
if (JK.currentUserId) {
|
|
var shareDialog = new JK.ShareDialog(JK.app, claimedRecordingId, "recording");
|
|
shareDialog.initialize(JK.FacebookHelperInstance);
|
|
|
|
$("#btnShare", $scope).click(function(e) {
|
|
shareDialog.showDialog();
|
|
});
|
|
|
|
$("#btnPostComment").click(function(e) {
|
|
if ($.trim($("#txtRecordingComment").val()).length > 0) {
|
|
addComment();
|
|
$("#txtRecordingComment").val('');
|
|
$("#txtRecordingComment").blur();
|
|
}
|
|
});
|
|
}
|
|
else {
|
|
$("#txtRecordingComment", $scope).attr("disabled", "disabled");
|
|
$("#txtRecordingComment", $scope).val("You must be logged in to add a comment.");
|
|
}
|
|
|
|
$("#btnLike").click(like);
|
|
$("#btnPlay").click(play);
|
|
}
|
|
|
|
this.initialize = initialize;
|
|
}
|
|
|
|
})(window, jQuery); |