-
Notifications
You must be signed in to change notification settings - Fork 1
/
script.js
121 lines (100 loc) · 3.01 KB
/
script.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
$(document).ready(function() {
var video = comment = results = commentsArray = null;
init();
function init() {
video = document.getElementById('video');
comment = $('#comment');
results = $('#results');
commentsArray = new Array();
setup();
}
function setup() {
video.addEventListener('click', function(e){
e.preventDefault();
if(video.paused){
closeComment();
}else{
openComment();
}
}, false);
comment.find('.cancel').click(function(e){
closeComment();
});
comment.find('.save').click(function(e){
saveComment();
});
comment.keypress(function(e) {
if(e.which == 10 || e.which == 13) {
saveComment();
}
});
}
function saveComment() {
commentsArray.push(new Comment(commentsArray.length, comment.find('input[type="text"]').val(), Math.round(video.currentTime)));
refreshCommentList();
closeComment();
}
function closeComment() {
video.play();
comment.hide();
comment.find('input[type="text"]').val('');
}
function openComment() {
video.pause();
comment.find('p span').text(' ' + Math.round(video.currentTime) + ' secs');
comment.show();
comment.find('input[type="text"]').focus();
}
function refreshCommentList() {
results.text("");
for(var i = 0; i < commentsArray.length; i++) {
results.prepend(commentsArray[i].toString());
}
renewClickFunctions();
}
function renewClickFunctions() {
results.find('a').unbind('click');
results.find('a').bind('click',function(e){
e.preventDefault();
if($(this).hasClass('edit')){
editClicked($(this).parent().attr('class'));
}else if($(this).hasClass('delete')){
deleteClicked($(this).parent().attr('class'));
}
});
}
function editClicked($id) {
console.log('Edit: '+ $id);
}
function deleteClicked($id) {
commentsArray[$id].setActive(false);
refreshCommentList();
}
});
function Comment($id, $comment, $time, $type, $active) {
if( $id == undefined ){ $id = 0; }
if( $comment == undefined ){ $comment = '' }
if( $time == undefined ){ $time = 0 }
if( $type == undefined ){ $type = null }
if( $active == undefined ){ $active = true }
var _id = $id;
var _comment = $comment;
var _time = $time;
var _type = $type;
var _active = $active;
this.id = function() { return _id }
this.comment = function() { return _comment }
this.timestamp = function() { return _time }
this.type = function() { return _type }
this.active = function() {return _active }
this.setID = function($id) { _id = $id }
this.setComment = function($comment) { _comment = $comment }
this.setTime = function($time) { _time = $time }
this.setType = function($type) { _type = $type }
this.setActive = function($active) { _active = $active }
this.toString = function() {
if( _active ){
return '<p class="'+ _id +'"><a href="#" class="edit">Edit</a> - <a href="#" class="delete">Delete</a> | ' + _time + ' secs : <span>' + _comment + '</span></p>';
}
}
}