| author | Anthony Ly <anthonyly.com@gmail.com> |
| Fri, 31 May 2013 17:32:56 +0200 | |
| changeset 62 | 42919bf5d4e1 |
| parent 58 | 9e14b6f964fe |
| child 70 | 2542e988f80c |
| permissions | -rw-r--r-- |
| 28 | 1 |
var myMedia = null, |
2 |
currentChapter = null, |
|
|
34
e3a17ec94cd8
edition annotation first part
Anthony Ly <anthonyly.com@gmail.com>
parents:
28
diff
changeset
|
3 |
currentAnnotation = null, |
| 28 | 4 |
chapters = [], |
5 |
annotations = []; |
|
6 |
||
| 9 | 7 |
$(function(){ |
| 6 | 8 |
|
9 |
var global = { |
|
| 28 | 10 |
colorsIndex : 0, |
11 |
colors : |
|
12 |
['#f39c12', '#2ecc71', '#3498db', '#9b59b6', |
|
| 62 | 13 |
'#f1c40f', '#e67e22', '#e74c3c', |
| 28 | 14 |
'#16a085', '#27ae60', '#2980b9', '#8e44ad', |
| 62 | 15 |
'#d35400', '#c0392b', '#bdc3c7'] |
| 28 | 16 |
}; |
17 |
||
18 |
||
| 58 | 19 |
//position de la video setCurrentTime |
20 |
$(".indicateur-annotation").draggable({ |
|
21 |
axis: "x", |
|
22 |
containment: "parent", |
|
23 |
drag: function(e, ui) { |
|
24 |
var t = myMedia.duration * parseInt(ui.helper.css("left")) / ( $(".timeline-annotations").width() - 2 * ui.helper.width() ); |
|
25 |
myMedia.setCurrentTime(t); |
|
26 |
} |
|
27 |
}); |
|
|
55
cedadc7d039a
modal delete in html title update
Anthony Ly <anthonyly.com@gmail.com>
parents:
54
diff
changeset
|
28 |
|
| 58 | 29 |
$('.timeline-annotations').bind('click', function(e){ |
30 |
var x = e.pageX - $(this).offset().left; |
|
31 |
myMedia.setCurrentTime(myMedia.duration * x / $(this).width()); |
|
32 |
}); |
|
|
55
cedadc7d039a
modal delete in html title update
Anthony Ly <anthonyly.com@gmail.com>
parents:
54
diff
changeset
|
33 |
|
| 16 | 34 |
myProject.onLoad(function() { |
35 |
||
36 |
$(".project-title").text(myProject.title); |
|
| 62 | 37 |
$('.project-title-nav').text(myProject.title); |
38 |
||
| 16 | 39 |
myMedia = myProject.getCurrentMedia(); |
|
55
cedadc7d039a
modal delete in html title update
Anthony Ly <anthonyly.com@gmail.com>
parents:
54
diff
changeset
|
40 |
|
|
cedadc7d039a
modal delete in html title update
Anthony Ly <anthonyly.com@gmail.com>
parents:
54
diff
changeset
|
41 |
//load Chapitre |
|
cedadc7d039a
modal delete in html title update
Anthony Ly <anthonyly.com@gmail.com>
parents:
54
diff
changeset
|
42 |
var _chapters = myProject.getAnnotationsByTypeTitle("chapitrage"); |
|
cedadc7d039a
modal delete in html title update
Anthony Ly <anthonyly.com@gmail.com>
parents:
54
diff
changeset
|
43 |
if(_chapters.length){ |
|
cedadc7d039a
modal delete in html title update
Anthony Ly <anthonyly.com@gmail.com>
parents:
54
diff
changeset
|
44 |
$.each(_chapters, function(k, v){ |
| 58 | 45 |
v.color = getRandomColor(); |
46 |
chapters.push(v); |
|
|
55
cedadc7d039a
modal delete in html title update
Anthony Ly <anthonyly.com@gmail.com>
parents:
54
diff
changeset
|
47 |
if((k+1) == _chapters.length){ |
| 58 | 48 |
renderChapter(); |
|
55
cedadc7d039a
modal delete in html title update
Anthony Ly <anthonyly.com@gmail.com>
parents:
54
diff
changeset
|
49 |
} |
| 58 | 50 |
}); |
51 |
} |
|
52 |
||
53 |
//load Annotations |
|
54 |
var _annotations = myProject.getAnnotationsByTypeTitle("annotations"); |
|
55 |
if(_annotations.length){ |
|
56 |
$.each(_annotations, function(k, v){ |
|
57 |
||
58 |
v.color = getRandomColor(); |
|
59 |
var type = v.content.mimetype.split('-'); |
|
60 |
type = type[type.length-1] |
|
61 |
v.type = type; |
|
62 |
||
63 |
annotations.push(v); |
|
64 |
if((k+1) == _annotations.length){ |
|
65 |
renderAnnotation(); |
|
66 |
} |
|
67 |
||
|
55
cedadc7d039a
modal delete in html title update
Anthony Ly <anthonyly.com@gmail.com>
parents:
54
diff
changeset
|
68 |
}); |
|
cedadc7d039a
modal delete in html title update
Anthony Ly <anthonyly.com@gmail.com>
parents:
54
diff
changeset
|
69 |
} |
|
cedadc7d039a
modal delete in html title update
Anthony Ly <anthonyly.com@gmail.com>
parents:
54
diff
changeset
|
70 |
|
| 16 | 71 |
IriSP.htmlPlayer( |
72 |
myMedia, |
|
73 |
$(".main-video"), |
|
74 |
{ |
|
75 |
width: 460, |
|
76 |
height: 345, |
|
77 |
controls: true, |
|
| 54 | 78 |
autostart: true, |
79 |
url_transform: function(src) { |
|
80 |
return [{ |
|
81 |
type: "video/mp4", |
|
82 |
src: src.replace(/\.[\d\w]+$/,'.mp4') |
|
83 |
}, { |
|
84 |
type: "video/webm", |
|
85 |
src: src.replace(/\.[\d\w]+$/,'.webm') |
|
86 |
}]; |
|
87 |
} |
|
| 16 | 88 |
} |
89 |
); |
|
90 |
||
91 |
myMedia.on("timeupdate", function(t) { |
|
92 |
||
93 |
//curseur chapitre |
|
|
21
abd04f346dbe
delete row on enter key press in modal
Anthony Ly <anthonyly.com@gmail.com>
parents:
18
diff
changeset
|
94 |
var wContainer = $('.chapitre-cut-wrap').width() - 1, |
|
abd04f346dbe
delete row on enter key press in modal
Anthony Ly <anthonyly.com@gmail.com>
parents:
18
diff
changeset
|
95 |
pos = wContainer * t / myMedia.duration, |
| 16 | 96 |
btnCutChapter = $('.btn-cut-chapter'), |
97 |
wBtnCutChapter = btnCutChapter.outerWidth(); |
|
|
34
e3a17ec94cd8
edition annotation first part
Anthony Ly <anthonyly.com@gmail.com>
parents:
28
diff
changeset
|
98 |
|
|
e3a17ec94cd8
edition annotation first part
Anthony Ly <anthonyly.com@gmail.com>
parents:
28
diff
changeset
|
99 |
$(".indicateur-chapter, .indicateur-annotation").css("left",pos); |
| 16 | 100 |
if(pos+wBtnCutChapter>wContainer){ |
101 |
btnCutChapter.css("left",(pos - wBtnCutChapter)); |
|
102 |
}else{ |
|
103 |
btnCutChapter.css("left",pos); |
|
104 |
} |
|
|
36
4c2428524c22
annotation display view
Anthony Ly <anthonyly.com@gmail.com>
parents:
35
diff
changeset
|
105 |
|
|
4c2428524c22
annotation display view
Anthony Ly <anthonyly.com@gmail.com>
parents:
35
diff
changeset
|
106 |
//annotations view |
|
4c2428524c22
annotation display view
Anthony Ly <anthonyly.com@gmail.com>
parents:
35
diff
changeset
|
107 |
var currentAnnotationsDisplay = new Array(); |
|
4c2428524c22
annotation display view
Anthony Ly <anthonyly.com@gmail.com>
parents:
35
diff
changeset
|
108 |
$.each(annotations, function(k, v){ |
|
4c2428524c22
annotation display view
Anthony Ly <anthonyly.com@gmail.com>
parents:
35
diff
changeset
|
109 |
|
|
4c2428524c22
annotation display view
Anthony Ly <anthonyly.com@gmail.com>
parents:
35
diff
changeset
|
110 |
if(v.begin <= t && v.end >= t){ |
|
4c2428524c22
annotation display view
Anthony Ly <anthonyly.com@gmail.com>
parents:
35
diff
changeset
|
111 |
currentAnnotationsDisplay.push(v.id); |
|
4c2428524c22
annotation display view
Anthony Ly <anthonyly.com@gmail.com>
parents:
35
diff
changeset
|
112 |
if(!$('#item-current-annotation-'+v.id).length){ |
|
4c2428524c22
annotation display view
Anthony Ly <anthonyly.com@gmail.com>
parents:
35
diff
changeset
|
113 |
var itemAnnotation = |
|
4c2428524c22
annotation display view
Anthony Ly <anthonyly.com@gmail.com>
parents:
35
diff
changeset
|
114 |
$('<li>') |
|
4c2428524c22
annotation display view
Anthony Ly <anthonyly.com@gmail.com>
parents:
35
diff
changeset
|
115 |
.attr('id', 'item-current-annotation-'+v.id) |
|
4c2428524c22
annotation display view
Anthony Ly <anthonyly.com@gmail.com>
parents:
35
diff
changeset
|
116 |
.attr('data-id', v.id) |
|
4c2428524c22
annotation display view
Anthony Ly <anthonyly.com@gmail.com>
parents:
35
diff
changeset
|
117 |
.append( |
|
4c2428524c22
annotation display view
Anthony Ly <anthonyly.com@gmail.com>
parents:
35
diff
changeset
|
118 |
$('<a>') |
|
4c2428524c22
annotation display view
Anthony Ly <anthonyly.com@gmail.com>
parents:
35
diff
changeset
|
119 |
.css('backgroundColor', v.color) |
|
4c2428524c22
annotation display view
Anthony Ly <anthonyly.com@gmail.com>
parents:
35
diff
changeset
|
120 |
.attr('data-id', v.id) |
|
4c2428524c22
annotation display view
Anthony Ly <anthonyly.com@gmail.com>
parents:
35
diff
changeset
|
121 |
.attr('href', '#') |
|
4c2428524c22
annotation display view
Anthony Ly <anthonyly.com@gmail.com>
parents:
35
diff
changeset
|
122 |
.append( |
|
4c2428524c22
annotation display view
Anthony Ly <anthonyly.com@gmail.com>
parents:
35
diff
changeset
|
123 |
$('<i>').addClass('icon-'+getIcon(v.type)) |
|
4c2428524c22
annotation display view
Anthony Ly <anthonyly.com@gmail.com>
parents:
35
diff
changeset
|
124 |
) |
|
4c2428524c22
annotation display view
Anthony Ly <anthonyly.com@gmail.com>
parents:
35
diff
changeset
|
125 |
); |
|
4c2428524c22
annotation display view
Anthony Ly <anthonyly.com@gmail.com>
parents:
35
diff
changeset
|
126 |
$('.list-current-annotations').append(itemAnnotation) |
|
4c2428524c22
annotation display view
Anthony Ly <anthonyly.com@gmail.com>
parents:
35
diff
changeset
|
127 |
} |
|
4c2428524c22
annotation display view
Anthony Ly <anthonyly.com@gmail.com>
parents:
35
diff
changeset
|
128 |
} |
|
4c2428524c22
annotation display view
Anthony Ly <anthonyly.com@gmail.com>
parents:
35
diff
changeset
|
129 |
}); |
|
4c2428524c22
annotation display view
Anthony Ly <anthonyly.com@gmail.com>
parents:
35
diff
changeset
|
130 |
$.each($('.list-current-annotations li'), function(k, v){ |
|
4c2428524c22
annotation display view
Anthony Ly <anthonyly.com@gmail.com>
parents:
35
diff
changeset
|
131 |
var idAnnotation = $(this).attr('data-id'), |
|
4c2428524c22
annotation display view
Anthony Ly <anthonyly.com@gmail.com>
parents:
35
diff
changeset
|
132 |
annotationDisplayView = $('.annotation-display-view'); |
|
4c2428524c22
annotation display view
Anthony Ly <anthonyly.com@gmail.com>
parents:
35
diff
changeset
|
133 |
if($.inArray(idAnnotation, currentAnnotationsDisplay)<0){//il ne doit plus être affiché |
|
4c2428524c22
annotation display view
Anthony Ly <anthonyly.com@gmail.com>
parents:
35
diff
changeset
|
134 |
$('#item-current-annotation-'+idAnnotation).remove(); |
|
4c2428524c22
annotation display view
Anthony Ly <anthonyly.com@gmail.com>
parents:
35
diff
changeset
|
135 |
if(annotationDisplayView.attr('data-id') == idAnnotation && annotationDisplayView.is(":visible")){ |
|
4c2428524c22
annotation display view
Anthony Ly <anthonyly.com@gmail.com>
parents:
35
diff
changeset
|
136 |
annotationDisplayView.hide(); |
|
4c2428524c22
annotation display view
Anthony Ly <anthonyly.com@gmail.com>
parents:
35
diff
changeset
|
137 |
} |
|
4c2428524c22
annotation display view
Anthony Ly <anthonyly.com@gmail.com>
parents:
35
diff
changeset
|
138 |
} |
|
4c2428524c22
annotation display view
Anthony Ly <anthonyly.com@gmail.com>
parents:
35
diff
changeset
|
139 |
}); |
|
4c2428524c22
annotation display view
Anthony Ly <anthonyly.com@gmail.com>
parents:
35
diff
changeset
|
140 |
|
|
4c2428524c22
annotation display view
Anthony Ly <anthonyly.com@gmail.com>
parents:
35
diff
changeset
|
141 |
|
| 18 | 142 |
});//timeupdate |
| 16 | 143 |
|
144 |
});//myProject.onLoad |
|
145 |
||
|
36
4c2428524c22
annotation display view
Anthony Ly <anthonyly.com@gmail.com>
parents:
35
diff
changeset
|
146 |
//display annotation view |
|
4c2428524c22
annotation display view
Anthony Ly <anthonyly.com@gmail.com>
parents:
35
diff
changeset
|
147 |
$('.list-current-annotations').on('click', 'a', function(e){ |
|
4c2428524c22
annotation display view
Anthony Ly <anthonyly.com@gmail.com>
parents:
35
diff
changeset
|
148 |
e.preventDefault(); |
|
4c2428524c22
annotation display view
Anthony Ly <anthonyly.com@gmail.com>
parents:
35
diff
changeset
|
149 |
var annotationDisplayView = $('.annotation-display-view'), |
|
4c2428524c22
annotation display view
Anthony Ly <anthonyly.com@gmail.com>
parents:
35
diff
changeset
|
150 |
idAnnotation = $(this).attr('data-id'); |
|
4c2428524c22
annotation display view
Anthony Ly <anthonyly.com@gmail.com>
parents:
35
diff
changeset
|
151 |
var annotation = _.find(annotations, function(c){ return c.id == idAnnotation; }); |
| 6 | 152 |
|
|
36
4c2428524c22
annotation display view
Anthony Ly <anthonyly.com@gmail.com>
parents:
35
diff
changeset
|
153 |
if(annotationDisplayView.attr('data-id') == idAnnotation && annotationDisplayView.is(":visible")){ |
|
4c2428524c22
annotation display view
Anthony Ly <anthonyly.com@gmail.com>
parents:
35
diff
changeset
|
154 |
annotationDisplayView.hide(); |
|
4c2428524c22
annotation display view
Anthony Ly <anthonyly.com@gmail.com>
parents:
35
diff
changeset
|
155 |
}else{ |
|
4c2428524c22
annotation display view
Anthony Ly <anthonyly.com@gmail.com>
parents:
35
diff
changeset
|
156 |
annotationDisplayView |
|
4c2428524c22
annotation display view
Anthony Ly <anthonyly.com@gmail.com>
parents:
35
diff
changeset
|
157 |
.attr('data-id', idAnnotation) |
|
4c2428524c22
annotation display view
Anthony Ly <anthonyly.com@gmail.com>
parents:
35
diff
changeset
|
158 |
.css('backgroundColor', annotation.color) |
|
4c2428524c22
annotation display view
Anthony Ly <anthonyly.com@gmail.com>
parents:
35
diff
changeset
|
159 |
.text(annotation.type) |
|
4c2428524c22
annotation display view
Anthony Ly <anthonyly.com@gmail.com>
parents:
35
diff
changeset
|
160 |
.show(); |
|
4c2428524c22
annotation display view
Anthony Ly <anthonyly.com@gmail.com>
parents:
35
diff
changeset
|
161 |
} |
|
4c2428524c22
annotation display view
Anthony Ly <anthonyly.com@gmail.com>
parents:
35
diff
changeset
|
162 |
}); |
|
4c2428524c22
annotation display view
Anthony Ly <anthonyly.com@gmail.com>
parents:
35
diff
changeset
|
163 |
|
|
4c2428524c22
annotation display view
Anthony Ly <anthonyly.com@gmail.com>
parents:
35
diff
changeset
|
164 |
//########### modal |
|
4c2428524c22
annotation display view
Anthony Ly <anthonyly.com@gmail.com>
parents:
35
diff
changeset
|
165 |
|
| 9 | 166 |
$(document).on('click', 'a.open-modal', function(e){ |
167 |
||
| 22 | 168 |
}); |
169 |
||
| 6 | 170 |
//edition image |
171 |
$('.popup').on('change', '#media-type-select', function(e){ |
|
172 |
var typeImage = $(this).val(); |
|
173 |
$('.input-image-url, .input-image-upload').hide(); |
|
174 |
$('.input-image-'+typeImage).show(); |
|
175 |
}); |
|
| 22 | 176 |
|
| 51 | 177 |
//select on bibliotheque |
178 |
||
| 58 | 179 |
|
|
35
6eb0de10e9f8
delete / edit / new annotation head
Anthony Ly <anthonyly.com@gmail.com>
parents:
34
diff
changeset
|
180 |
|
| 6 | 181 |
|
182 |
//confirmation suppression |
|
183 |
$("#modal-confirm").on('click', '#btn-delete-modal', function(e){ |
|
| 9 | 184 |
|
| 6 | 185 |
}); |
186 |
||
|
34
e3a17ec94cd8
edition annotation first part
Anthony Ly <anthonyly.com@gmail.com>
parents:
28
diff
changeset
|
187 |
//--title-editor |
| 62 | 188 |
$(document).on('click', '.project-title-editor i, .project-title', function () { |
189 |
var html = $('.project-title').html(); |
|
190 |
var input = $('<input type="text" />'); |
|
191 |
input.val(html); |
|
192 |
$('.project-title').replaceWith(input); |
|
193 |
input.focus(); |
|
194 |
}); |
|
195 |
$(document).on('blur', '.project-title-editor input', function(){ |
|
196 |
var newTitle = $(this).val(); |
|
197 |
myProject.title = newTitle; |
|
198 |
$(this).replaceWith('<span class="project-title">'+newTitle+'</span></td>'); |
|
199 |
$('.project-title-nav').text(newTitle); |
|
| 6 | 200 |
}); |
201 |
||
| 9 | 202 |
|
|
34
e3a17ec94cd8
edition annotation first part
Anthony Ly <anthonyly.com@gmail.com>
parents:
28
diff
changeset
|
203 |
//######################## chapter |
| 22 | 204 |
|
205 |
//edit |
|
206 |
$('.list-chapter-wrap').on('click', '.btn-edit-chapter', function(e){ |
|
| 6 | 207 |
e.preventDefault(); |
| 22 | 208 |
var idChapter = $(this).attr('data-chapter-id'); |
209 |
loadFormChapter(idChapter); |
|
210 |
}); |
|
211 |
||
| 23 | 212 |
$('.chapter-segments').on('click', 'li', function(){ |
213 |
var idChapter = $(this).attr('id'); |
|
214 |
loadFormChapter(idChapter); |
|
215 |
}); |
|
| 22 | 216 |
|
217 |
$('.chapter-widget-info').on('keyup', 'input[name=title], textarea', function(e){ |
|
218 |
var name = $(this).attr('name'), |
|
219 |
value = $(this).val(); |
|
220 |
currentChapter[name] = value; |
|
221 |
if(name == 'title'){ |
|
222 |
var idChapter = $(this).parents('form').attr('data-chapter-id'); |
|
223 |
$('.chapter-segments').find('#'+idChapter).text(value); |
|
224 |
$('#row-list-chapter-'+idChapter).find('td:first').text(value); |
|
| 6 | 225 |
} |
| 22 | 226 |
}); |
227 |
||
228 |
||
229 |
||
230 |
function loadFormChapter(idChapter){ |
|
| 58 | 231 |
|
232 |
|
|
233 |
||
| 28 | 234 |
currentChapter = _.find(chapters, function(c){ return c.id == idChapter; }); |
235 |
var chapterWrap = $('.chapter-widget-info'), |
|
236 |
indexChapter = _.indexOf(chapters, currentChapter), |
|
237 |
beginTangle = (indexChapter>0) ? true : false, |
|
238 |
endTangle = (indexChapter<(chapters.length-1)) ? true : false; |
|
| 22 | 239 |
|
| 28 | 240 |
currentChapter.beginTangle = beginTangle; |
241 |
currentChapter.endTangle = endTangle; |
|
| 22 | 242 |
|
| 62 | 243 |
var tpl = getTemplate('#tpl-chapter-edit'); |
| 28 | 244 |
tpl = Mustache.render(tpl, currentChapter); |
| 22 | 245 |
chapterWrap.empty().append(tpl); |
246 |
chapterWrap.find('.tag-it').tagit(tagitParam); |
|
| 58 | 247 |
|
248 |
myMedia.setCurrentTime(currentChapter.begin); |
|
| 22 | 249 |
} |
250 |
||
| 62 | 251 |
function getTemplate(idTpl){ |
252 |
return $('#templates').find(idTpl).html(); |
|
253 |
} |
|
| 22 | 254 |
//supprimer |
255 |
$('.list-chapter-wrap').on('click', '.btn-delete-chapter', function(e){ |
|
256 |
e.preventDefault(); |
|
257 |
||
258 |
if(chapters.length == 1){alert('Le projet doit contenir au moins un chapitre.'); return;} |
|
| 28 | 259 |
|
| 22 | 260 |
var idChapter = $(this).attr('data-chapter-id'), |
261 |
chapter = _.find(chapters, function(c){ return c.id == idChapter; }), |
|
262 |
indexChapter = _.indexOf(chapters, chapter), |
|
263 |
chapterModify; |
|
264 |
if(indexChapter == 0){ |
|
265 |
chapterModify = chapters[1]; |
|
| 28 | 266 |
chapterModify.setBegin(0); |
| 22 | 267 |
}else{ |
268 |
chapterModify = chapters[indexChapter-1]; |
|
| 28 | 269 |
//var newEnd = new IriSP.Model.Time(chapter.end) |
270 |
chapterModify.setEnd(chapter.end); |
|
| 22 | 271 |
} |
272 |
chapters = _(chapters).reject(function(c) { return c.id == idChapter; }); |
|
273 |
renderChapter(); |
|
274 |
//si le formulaire est visible |
|
275 |
if($('#form-chapter-edit-'+idChapter).length){ |
|
276 |
$('#form-chapter-edit-'+idChapter).remove(); |
|
277 |
} |
|
278 |
}); |
|
279 |
||
| 58 | 280 |
function getRandomColor(){ |
281 |
return global.colors[(global.colorsIndex<global.colors.length) ? global.colorsIndex++ : (global.colorsIndex=0)]; |
|
282 |
} |
|
| 22 | 283 |
//nouveau chapitre |
|
55
cedadc7d039a
modal delete in html title update
Anthony Ly <anthonyly.com@gmail.com>
parents:
54
diff
changeset
|
284 |
function newChapter(dataChapter, render){ |
| 28 | 285 |
var chapter = new IriSP.Model.Annotation(false, myProject); |
286 |
chapter.setMedia(myMedia.id); |
|
287 |
chapter.setBegin(dataChapter.begin); |
|
288 |
chapter.setEnd(dataChapter.end); |
|
289 |
chapter.title = dataChapter.title; |
|
290 |
chapter.description = dataChapter.description; |
|
291 |
chapter.keywords = dataChapter.keywords; |
|
| 58 | 292 |
chapter.color = getRandomColor(); |
| 28 | 293 |
|
294 |
chapters.push(chapter); |
|
| 58 | 295 |
renderChapter(); |
| 28 | 296 |
loadFormChapter(chapter.id); |
297 |
} |
|
298 |
||
| 6 | 299 |
$('.chapter-widget').on('click', '.btn-cut-chapter', function(e){ |
300 |
e.preventDefault(); |
|
| 16 | 301 |
|
| 28 | 302 |
var dataChapter = { |
303 |
title : 'New', |
|
304 |
begin : myMedia.currentTime, |
|
305 |
end : organizeNewChapter(myMedia.currentTime), |
|
306 |
description : 'description', |
|
|
34
e3a17ec94cd8
edition annotation first part
Anthony Ly <anthonyly.com@gmail.com>
parents:
28
diff
changeset
|
307 |
keywords : ['tag1','tag2'] |
| 28 | 308 |
}; |
|
21
abd04f346dbe
delete row on enter key press in modal
Anthony Ly <anthonyly.com@gmail.com>
parents:
18
diff
changeset
|
309 |
|
|
55
cedadc7d039a
modal delete in html title update
Anthony Ly <anthonyly.com@gmail.com>
parents:
54
diff
changeset
|
310 |
newChapter(dataChapter, true); |
| 28 | 311 |
|
| 6 | 312 |
}); |
| 22 | 313 |
|
314 |
function organizeNewChapter(beginNew){ |
|
| 6 | 315 |
|
| 22 | 316 |
var returnEnd; |
317 |
$.each(chapters, function(k, v){ |
|
318 |
var begin = v.begin, |
|
319 |
end = v.end; |
|
320 |
if(beginNew>=begin && beginNew<=end){ |
|
| 28 | 321 |
returnEnd = new IriSP.Model.Time(end); |
322 |
v.setEnd(beginNew); |
|
| 22 | 323 |
} |
324 |
}); |
|
| 28 | 325 |
|
| 22 | 326 |
return returnEnd; |
327 |
} |
|
328 |
|
|
329 |
function renderChapter(){ |
|
330 |
var chapterSegmentWrap = $('.chapter-segments'), |
|
331 |
wChapterSegmentWrap = chapterSegmentWrap.width(), |
|
332 |
chapterList = $('.list-chapter-rows-wrap'); |
|
|
21
abd04f346dbe
delete row on enter key press in modal
Anthony Ly <anthonyly.com@gmail.com>
parents:
18
diff
changeset
|
333 |
|
| 22 | 334 |
chapters = _.sortBy(chapters, function(c){ |
335 |
return c.begin; |
|
|
21
abd04f346dbe
delete row on enter key press in modal
Anthony Ly <anthonyly.com@gmail.com>
parents:
18
diff
changeset
|
336 |
}); |
| 18 | 337 |
|
|
21
abd04f346dbe
delete row on enter key press in modal
Anthony Ly <anthonyly.com@gmail.com>
parents:
18
diff
changeset
|
338 |
chapterSegmentWrap.empty(); |
| 22 | 339 |
chapterList.empty(); |
| 62 | 340 |
|
| 58 | 341 |
$.each(chapters, function(k, v){ |
|
21
abd04f346dbe
delete row on enter key press in modal
Anthony Ly <anthonyly.com@gmail.com>
parents:
18
diff
changeset
|
342 |
|
| 58 | 343 |
//segments |
344 |
var width = Math.floor(v.getDuration() * wChapterSegmentWrap / myMedia.duration), |
|
345 |
segment = $('<li>'+v.title+'</li>').css({ |
|
346 |
width : width, |
|
347 |
backgroundColor : v.color |
|
348 |
}).attr('id', v.id); |
|
349 |
|
|
350 |
chapterSegmentWrap.append(segment); |
|
| 28 | 351 |
|
| 58 | 352 |
//liste |
| 62 | 353 |
var tplChapterRow = getTemplate('#tpl-chapter-row'); |
| 22 | 354 |
tplChapterRow = Mustache.render(tplChapterRow, v); |
355 |
chapterList.append(tplChapterRow); |
|
356 |
}); |
|
| 62 | 357 |
|
| 58 | 358 |
}//renderChapter() |
|
21
abd04f346dbe
delete row on enter key press in modal
Anthony Ly <anthonyly.com@gmail.com>
parents:
18
diff
changeset
|
359 |
|
|
abd04f346dbe
delete row on enter key press in modal
Anthony Ly <anthonyly.com@gmail.com>
parents:
18
diff
changeset
|
360 |
|
| 22 | 361 |
|
|
34
e3a17ec94cd8
edition annotation first part
Anthony Ly <anthonyly.com@gmail.com>
parents:
28
diff
changeset
|
362 |
//######################## annotation |
|
e3a17ec94cd8
edition annotation first part
Anthony Ly <anthonyly.com@gmail.com>
parents:
28
diff
changeset
|
363 |
|
|
e3a17ec94cd8
edition annotation first part
Anthony Ly <anthonyly.com@gmail.com>
parents:
28
diff
changeset
|
364 |
|
|
e3a17ec94cd8
edition annotation first part
Anthony Ly <anthonyly.com@gmail.com>
parents:
28
diff
changeset
|
365 |
function newAnnotation(dataAnnotation){ |
|
e3a17ec94cd8
edition annotation first part
Anthony Ly <anthonyly.com@gmail.com>
parents:
28
diff
changeset
|
366 |
var annotation = new IriSP.Model.Annotation(false, myProject); |
|
e3a17ec94cd8
edition annotation first part
Anthony Ly <anthonyly.com@gmail.com>
parents:
28
diff
changeset
|
367 |
annotation.setMedia(myMedia.id); |
|
e3a17ec94cd8
edition annotation first part
Anthony Ly <anthonyly.com@gmail.com>
parents:
28
diff
changeset
|
368 |
annotation.setBegin(dataAnnotation.begin); |
|
e3a17ec94cd8
edition annotation first part
Anthony Ly <anthonyly.com@gmail.com>
parents:
28
diff
changeset
|
369 |
annotation.setEnd(dataAnnotation.end); |
|
e3a17ec94cd8
edition annotation first part
Anthony Ly <anthonyly.com@gmail.com>
parents:
28
diff
changeset
|
370 |
annotation.title = dataAnnotation.title; |
|
e3a17ec94cd8
edition annotation first part
Anthony Ly <anthonyly.com@gmail.com>
parents:
28
diff
changeset
|
371 |
annotation.description = dataAnnotation.description; |
|
e3a17ec94cd8
edition annotation first part
Anthony Ly <anthonyly.com@gmail.com>
parents:
28
diff
changeset
|
372 |
annotation.type = dataAnnotation.type; |
|
e3a17ec94cd8
edition annotation first part
Anthony Ly <anthonyly.com@gmail.com>
parents:
28
diff
changeset
|
373 |
annotation.color = global.colors[(global.colorsIndex<global.colors.length) ? global.colorsIndex++ : (global.colorsIndex=0)]; |
|
e3a17ec94cd8
edition annotation first part
Anthony Ly <anthonyly.com@gmail.com>
parents:
28
diff
changeset
|
374 |
annotation.keywords = dataAnnotation.keywords; |
| 42 | 375 |
annotation.content = getContentAnnotationByType(dataAnnotation.type); |
|
34
e3a17ec94cd8
edition annotation first part
Anthony Ly <anthonyly.com@gmail.com>
parents:
28
diff
changeset
|
376 |
|
|
e3a17ec94cd8
edition annotation first part
Anthony Ly <anthonyly.com@gmail.com>
parents:
28
diff
changeset
|
377 |
annotations.push(annotation); |
|
35
6eb0de10e9f8
delete / edit / new annotation head
Anthony Ly <anthonyly.com@gmail.com>
parents:
34
diff
changeset
|
378 |
|
|
6eb0de10e9f8
delete / edit / new annotation head
Anthony Ly <anthonyly.com@gmail.com>
parents:
34
diff
changeset
|
379 |
return annotation; |
|
34
e3a17ec94cd8
edition annotation first part
Anthony Ly <anthonyly.com@gmail.com>
parents:
28
diff
changeset
|
380 |
} |
|
e3a17ec94cd8
edition annotation first part
Anthony Ly <anthonyly.com@gmail.com>
parents:
28
diff
changeset
|
381 |
|
|
e3a17ec94cd8
edition annotation first part
Anthony Ly <anthonyly.com@gmail.com>
parents:
28
diff
changeset
|
382 |
function renderAnnotation(){ |
|
e3a17ec94cd8
edition annotation first part
Anthony Ly <anthonyly.com@gmail.com>
parents:
28
diff
changeset
|
383 |
var timeline = $('.timeline-annotations'), |
|
e3a17ec94cd8
edition annotation first part
Anthony Ly <anthonyly.com@gmail.com>
parents:
28
diff
changeset
|
384 |
wTimeline = timeline.width(), |
|
e3a17ec94cd8
edition annotation first part
Anthony Ly <anthonyly.com@gmail.com>
parents:
28
diff
changeset
|
385 |
annotationList = $('#list-annotations-rows'); |
|
e3a17ec94cd8
edition annotation first part
Anthony Ly <anthonyly.com@gmail.com>
parents:
28
diff
changeset
|
386 |
|
|
e3a17ec94cd8
edition annotation first part
Anthony Ly <anthonyly.com@gmail.com>
parents:
28
diff
changeset
|
387 |
annotations = _.sortBy(annotations, function(c){ |
|
e3a17ec94cd8
edition annotation first part
Anthony Ly <anthonyly.com@gmail.com>
parents:
28
diff
changeset
|
388 |
return c.begin; |
|
e3a17ec94cd8
edition annotation first part
Anthony Ly <anthonyly.com@gmail.com>
parents:
28
diff
changeset
|
389 |
}); |
|
e3a17ec94cd8
edition annotation first part
Anthony Ly <anthonyly.com@gmail.com>
parents:
28
diff
changeset
|
390 |
|
| 62 | 391 |
timeline.empty().append('<li>'); |
|
34
e3a17ec94cd8
edition annotation first part
Anthony Ly <anthonyly.com@gmail.com>
parents:
28
diff
changeset
|
392 |
annotationList.empty(); |
|
e3a17ec94cd8
edition annotation first part
Anthony Ly <anthonyly.com@gmail.com>
parents:
28
diff
changeset
|
393 |
|
|
e3a17ec94cd8
edition annotation first part
Anthony Ly <anthonyly.com@gmail.com>
parents:
28
diff
changeset
|
394 |
$.each(annotations, function(k, v){ |
|
e3a17ec94cd8
edition annotation first part
Anthony Ly <anthonyly.com@gmail.com>
parents:
28
diff
changeset
|
395 |
|
|
e3a17ec94cd8
edition annotation first part
Anthony Ly <anthonyly.com@gmail.com>
parents:
28
diff
changeset
|
396 |
//timeline |
|
e3a17ec94cd8
edition annotation first part
Anthony Ly <anthonyly.com@gmail.com>
parents:
28
diff
changeset
|
397 |
var width = Math.floor(v.getDuration() * wTimeline / myMedia.duration), |
|
e3a17ec94cd8
edition annotation first part
Anthony Ly <anthonyly.com@gmail.com>
parents:
28
diff
changeset
|
398 |
left = Math.floor(v.begin * wTimeline / myMedia.duration), |
|
e3a17ec94cd8
edition annotation first part
Anthony Ly <anthonyly.com@gmail.com>
parents:
28
diff
changeset
|
399 |
segment = $('<div>').css({ |
|
e3a17ec94cd8
edition annotation first part
Anthony Ly <anthonyly.com@gmail.com>
parents:
28
diff
changeset
|
400 |
left : left, |
|
e3a17ec94cd8
edition annotation first part
Anthony Ly <anthonyly.com@gmail.com>
parents:
28
diff
changeset
|
401 |
width : width, |
|
e3a17ec94cd8
edition annotation first part
Anthony Ly <anthonyly.com@gmail.com>
parents:
28
diff
changeset
|
402 |
backgroundColor : v.color |
|
e3a17ec94cd8
edition annotation first part
Anthony Ly <anthonyly.com@gmail.com>
parents:
28
diff
changeset
|
403 |
}).addClass('annotation').attr('id', 'annotation-timeline-'+v.id); |
| 62 | 404 |
|
405 |
var isInTimeline = false; |
|
406 |
$.each(timeline.find('li'), function(a, b){ |
|
407 |
if(isInTimeline) return; |
|
408 |
var row = $(this); |
|
409 |
if(row.children().length){ |
|
410 |
var canBeInRow = true; |
|
411 |
$.each(row.find('.annotation'), function(c, d){ |
|
412 |
var oAL = parseInt($(d).css('left')), |
|
413 |
oAR = oAL + $(d).width(), |
|
414 |
segmentR = left + width; |
|
415 |
if(oAL<=left && oAR>=left || oAL<=segmentR && oAR>= segmentR){ |
|
416 |
canBeInRow = false; |
|
417 |
} |
|
418 |
}); |
|
419 |
if(canBeInRow){ |
|
420 |
row.append(segment); |
|
421 |
isInTimeline = true; |
|
422 |
} |
|
423 |
}else{ |
|
424 |
row.append(segment); |
|
425 |
isInTimeline = true; |
|
426 |
} |
|
427 |
}); |
|
428 |
||
429 |
if(!isInTimeline){ |
|
430 |
timeline.append('<li>'); |
|
431 |
timeline.find('li:last-child').append(segment); |
|
432 |
} |
|
433 |
|
|
|
34
e3a17ec94cd8
edition annotation first part
Anthony Ly <anthonyly.com@gmail.com>
parents:
28
diff
changeset
|
434 |
|
|
e3a17ec94cd8
edition annotation first part
Anthony Ly <anthonyly.com@gmail.com>
parents:
28
diff
changeset
|
435 |
//liste |
| 62 | 436 |
var tplAnnotationRow = getTemplate('#tpl-list-annotation-row'); |
|
34
e3a17ec94cd8
edition annotation first part
Anthony Ly <anthonyly.com@gmail.com>
parents:
28
diff
changeset
|
437 |
tplAnnotationRow = Mustache.render(tplAnnotationRow, v); |
|
e3a17ec94cd8
edition annotation first part
Anthony Ly <anthonyly.com@gmail.com>
parents:
28
diff
changeset
|
438 |
annotationList.append(tplAnnotationRow); |
|
e3a17ec94cd8
edition annotation first part
Anthony Ly <anthonyly.com@gmail.com>
parents:
28
diff
changeset
|
439 |
|
| 62 | 440 |
}); |
|
34
e3a17ec94cd8
edition annotation first part
Anthony Ly <anthonyly.com@gmail.com>
parents:
28
diff
changeset
|
441 |
|
| 62 | 442 |
|
443 |
}//renderAnnotation |
|
| 22 | 444 |
|
| 6 | 445 |
//edit annotation |
446 |
$('#list-annotations').on('click', 'a.btn-edit-annotation', function(e){ |
|
447 |
e.preventDefault(); |
|
448 |
||
449 |
var idAnnotation = $(this).attr('data-id'); |
|
450 |
//si il est déjà ouvert |
|
|
34
e3a17ec94cd8
edition annotation first part
Anthony Ly <anthonyly.com@gmail.com>
parents:
28
diff
changeset
|
451 |
if($('#tab-annotation-'+idAnnotation).length){ |
|
e3a17ec94cd8
edition annotation first part
Anthony Ly <anthonyly.com@gmail.com>
parents:
28
diff
changeset
|
452 |
$('a[href=#tab-annotation-'+idAnnotation+']').tab('show'); |
| 6 | 453 |
}else{ |
|
34
e3a17ec94cd8
edition annotation first part
Anthony Ly <anthonyly.com@gmail.com>
parents:
28
diff
changeset
|
454 |
var data = _.find(annotations, function(c){ return c.id == idAnnotation; }); |
|
e3a17ec94cd8
edition annotation first part
Anthony Ly <anthonyly.com@gmail.com>
parents:
28
diff
changeset
|
455 |
openTab(data.type, data); |
| 6 | 456 |
} |
457 |
}); |
|
458 |
||
|
34
e3a17ec94cd8
edition annotation first part
Anthony Ly <anthonyly.com@gmail.com>
parents:
28
diff
changeset
|
459 |
$('.tab-content').on('keyup', 'input[name=title], textarea', function(e){ |
|
e3a17ec94cd8
edition annotation first part
Anthony Ly <anthonyly.com@gmail.com>
parents:
28
diff
changeset
|
460 |
var name = $(this).attr('name'), |
|
e3a17ec94cd8
edition annotation first part
Anthony Ly <anthonyly.com@gmail.com>
parents:
28
diff
changeset
|
461 |
value = $(this).val(); |
|
e3a17ec94cd8
edition annotation first part
Anthony Ly <anthonyly.com@gmail.com>
parents:
28
diff
changeset
|
462 |
currentAnnotation[name] = value; |
|
e3a17ec94cd8
edition annotation first part
Anthony Ly <anthonyly.com@gmail.com>
parents:
28
diff
changeset
|
463 |
if(name == 'title'){ |
|
e3a17ec94cd8
edition annotation first part
Anthony Ly <anthonyly.com@gmail.com>
parents:
28
diff
changeset
|
464 |
var idAnnotation = $(this).parents('form').attr('data-id'); |
|
e3a17ec94cd8
edition annotation first part
Anthony Ly <anthonyly.com@gmail.com>
parents:
28
diff
changeset
|
465 |
$('#onglet-title-'+idAnnotation).text(value); |
|
e3a17ec94cd8
edition annotation first part
Anthony Ly <anthonyly.com@gmail.com>
parents:
28
diff
changeset
|
466 |
} |
|
e3a17ec94cd8
edition annotation first part
Anthony Ly <anthonyly.com@gmail.com>
parents:
28
diff
changeset
|
467 |
}); |
|
e3a17ec94cd8
edition annotation first part
Anthony Ly <anthonyly.com@gmail.com>
parents:
28
diff
changeset
|
468 |
|
|
35
6eb0de10e9f8
delete / edit / new annotation head
Anthony Ly <anthonyly.com@gmail.com>
parents:
34
diff
changeset
|
469 |
//delete annotation |
|
6eb0de10e9f8
delete / edit / new annotation head
Anthony Ly <anthonyly.com@gmail.com>
parents:
34
diff
changeset
|
470 |
$(document).on('click','.btn-delete-annotation', function(e){ |
|
6eb0de10e9f8
delete / edit / new annotation head
Anthony Ly <anthonyly.com@gmail.com>
parents:
34
diff
changeset
|
471 |
e.preventDefault(); |
|
6eb0de10e9f8
delete / edit / new annotation head
Anthony Ly <anthonyly.com@gmail.com>
parents:
34
diff
changeset
|
472 |
|
|
6eb0de10e9f8
delete / edit / new annotation head
Anthony Ly <anthonyly.com@gmail.com>
parents:
34
diff
changeset
|
473 |
var idAnnotation = $(this).attr('data-id'); |
|
6eb0de10e9f8
delete / edit / new annotation head
Anthony Ly <anthonyly.com@gmail.com>
parents:
34
diff
changeset
|
474 |
annotations = _(annotations).reject(function(c) { return c.id == idAnnotation; }); |
|
6eb0de10e9f8
delete / edit / new annotation head
Anthony Ly <anthonyly.com@gmail.com>
parents:
34
diff
changeset
|
475 |
closeTab(idAnnotation); |
|
6eb0de10e9f8
delete / edit / new annotation head
Anthony Ly <anthonyly.com@gmail.com>
parents:
34
diff
changeset
|
476 |
if(!$(this).hasAttr('data-no-render'))//si on ferme à partir de la tab renderAnnotation sera appelé 2 fois |
|
6eb0de10e9f8
delete / edit / new annotation head
Anthony Ly <anthonyly.com@gmail.com>
parents:
34
diff
changeset
|
477 |
renderAnnotation(); |
|
6eb0de10e9f8
delete / edit / new annotation head
Anthony Ly <anthonyly.com@gmail.com>
parents:
34
diff
changeset
|
478 |
|
|
6eb0de10e9f8
delete / edit / new annotation head
Anthony Ly <anthonyly.com@gmail.com>
parents:
34
diff
changeset
|
479 |
}); |
|
6eb0de10e9f8
delete / edit / new annotation head
Anthony Ly <anthonyly.com@gmail.com>
parents:
34
diff
changeset
|
480 |
|
| 9 | 481 |
//tab |
|
34
e3a17ec94cd8
edition annotation first part
Anthony Ly <anthonyly.com@gmail.com>
parents:
28
diff
changeset
|
482 |
$('#onglet-annotations').on('click', 'a', function(e){ |
| 9 | 483 |
e.preventDefault(); |
484 |
$(this).tab('show'); |
|
485 |
}); |
|
486 |
||
487 |
//ouvrir tab |
|
488 |
$(document).on('click', '.open-tab', function(e){ |
|
489 |
e.preventDefault(); |
|
490 |
var type = $(this).attr('data-type'); |
|
|
34
e3a17ec94cd8
edition annotation first part
Anthony Ly <anthonyly.com@gmail.com>
parents:
28
diff
changeset
|
491 |
openTab(type); |
| 9 | 492 |
}); |
493 |
||
|
34
e3a17ec94cd8
edition annotation first part
Anthony Ly <anthonyly.com@gmail.com>
parents:
28
diff
changeset
|
494 |
function openTab(type, data){ |
|
e3a17ec94cd8
edition annotation first part
Anthony Ly <anthonyly.com@gmail.com>
parents:
28
diff
changeset
|
495 |
|
|
35
6eb0de10e9f8
delete / edit / new annotation head
Anthony Ly <anthonyly.com@gmail.com>
parents:
34
diff
changeset
|
496 |
var dataView; |
|
34
e3a17ec94cd8
edition annotation first part
Anthony Ly <anthonyly.com@gmail.com>
parents:
28
diff
changeset
|
497 |
if(_.isUndefined(data)){//nouveau |
|
36
4c2428524c22
annotation display view
Anthony Ly <anthonyly.com@gmail.com>
parents:
35
diff
changeset
|
498 |
var currentTimePlusUnMin = 60 * 1000 + myMedia.currentTime, |
|
4c2428524c22
annotation display view
Anthony Ly <anthonyly.com@gmail.com>
parents:
35
diff
changeset
|
499 |
endAnnotation = (currentTimePlusUnMin<myMedia.duration) ? currentTimePlusUnMin : myMedia.duration; |
|
35
6eb0de10e9f8
delete / edit / new annotation head
Anthony Ly <anthonyly.com@gmail.com>
parents:
34
diff
changeset
|
500 |
var dataAnnotation = { |
|
6eb0de10e9f8
delete / edit / new annotation head
Anthony Ly <anthonyly.com@gmail.com>
parents:
34
diff
changeset
|
501 |
title : 'Nouveau', |
|
36
4c2428524c22
annotation display view
Anthony Ly <anthonyly.com@gmail.com>
parents:
35
diff
changeset
|
502 |
begin : myMedia.currentTime, |
|
4c2428524c22
annotation display view
Anthony Ly <anthonyly.com@gmail.com>
parents:
35
diff
changeset
|
503 |
end : endAnnotation, |
|
35
6eb0de10e9f8
delete / edit / new annotation head
Anthony Ly <anthonyly.com@gmail.com>
parents:
34
diff
changeset
|
504 |
description : 'description', |
|
6eb0de10e9f8
delete / edit / new annotation head
Anthony Ly <anthonyly.com@gmail.com>
parents:
34
diff
changeset
|
505 |
type : type, |
|
6eb0de10e9f8
delete / edit / new annotation head
Anthony Ly <anthonyly.com@gmail.com>
parents:
34
diff
changeset
|
506 |
keywords : [] |
|
6eb0de10e9f8
delete / edit / new annotation head
Anthony Ly <anthonyly.com@gmail.com>
parents:
34
diff
changeset
|
507 |
}; |
|
6eb0de10e9f8
delete / edit / new annotation head
Anthony Ly <anthonyly.com@gmail.com>
parents:
34
diff
changeset
|
508 |
dataView = newAnnotation(dataAnnotation); |
|
6eb0de10e9f8
delete / edit / new annotation head
Anthony Ly <anthonyly.com@gmail.com>
parents:
34
diff
changeset
|
509 |
renderAnnotation(); |
|
34
e3a17ec94cd8
edition annotation first part
Anthony Ly <anthonyly.com@gmail.com>
parents:
28
diff
changeset
|
510 |
}else{//édition |
|
e3a17ec94cd8
edition annotation first part
Anthony Ly <anthonyly.com@gmail.com>
parents:
28
diff
changeset
|
511 |
dataView = data; |
|
e3a17ec94cd8
edition annotation first part
Anthony Ly <anthonyly.com@gmail.com>
parents:
28
diff
changeset
|
512 |
} |
| 6 | 513 |
|
|
34
e3a17ec94cd8
edition annotation first part
Anthony Ly <anthonyly.com@gmail.com>
parents:
28
diff
changeset
|
514 |
var idAnnotation = dataView.id, |
|
e3a17ec94cd8
edition annotation first part
Anthony Ly <anthonyly.com@gmail.com>
parents:
28
diff
changeset
|
515 |
tabContent = $('<div class="tab-pane" id="tab-annotation-'+idAnnotation+'"></div>'), |
| 6 | 516 |
iconTab; |
517 |
||
|
34
e3a17ec94cd8
edition annotation first part
Anthony Ly <anthonyly.com@gmail.com>
parents:
28
diff
changeset
|
518 |
currentAnnotation = _.find(annotations, function(c){ return c.id == idAnnotation; }); |
| 6 | 519 |
|
| 62 | 520 |
|
|
49
06627f23df42
show data annotations on tab open
Anthony Ly <anthonyly.com@gmail.com>
parents:
48
diff
changeset
|
521 |
|
| 6 | 522 |
//head commun à tous |
| 62 | 523 |
var tplHead = getTemplate('#tpl-head'); |
|
34
e3a17ec94cd8
edition annotation first part
Anthony Ly <anthonyly.com@gmail.com>
parents:
28
diff
changeset
|
524 |
var output = Mustache.render(tplHead, dataView); |
| 6 | 525 |
$(tabContent).append(output); |
|
34
e3a17ec94cd8
edition annotation first part
Anthony Ly <anthonyly.com@gmail.com>
parents:
28
diff
changeset
|
526 |
$(tabContent).find(".slider-duration").slider(configSlider(dataView)); |
|
e3a17ec94cd8
edition annotation first part
Anthony Ly <anthonyly.com@gmail.com>
parents:
28
diff
changeset
|
527 |
$(tabContent).find('.tag-it').tagit(tagitParam); |
| 6 | 528 |
//type |
|
49
06627f23df42
show data annotations on tab open
Anthony Ly <anthonyly.com@gmail.com>
parents:
48
diff
changeset
|
529 |
var viewType = { |
|
06627f23df42
show data annotations on tab open
Anthony Ly <anthonyly.com@gmail.com>
parents:
48
diff
changeset
|
530 |
id : idAnnotation, |
|
06627f23df42
show data annotations on tab open
Anthony Ly <anthonyly.com@gmail.com>
parents:
48
diff
changeset
|
531 |
content : dataView.content |
|
06627f23df42
show data annotations on tab open
Anthony Ly <anthonyly.com@gmail.com>
parents:
48
diff
changeset
|
532 |
}; |
| 62 | 533 |
var tpl = getTemplate('#tpl-'+type); |
|
49
06627f23df42
show data annotations on tab open
Anthony Ly <anthonyly.com@gmail.com>
parents:
48
diff
changeset
|
534 |
|
| 6 | 535 |
tpl = Mustache.render(tpl, viewType); |
536 |
$(tabContent).append(tpl); |
|
537 |
$('.tab-content').append(tabContent); |
|
538 |
||
539 |
//particularité selon type |
|
540 |
switch(type){ |
|
| 48 | 541 |
case 'audio': |
|
35
6eb0de10e9f8
delete / edit / new annotation head
Anthony Ly <anthonyly.com@gmail.com>
parents:
34
diff
changeset
|
542 |
break; |
|
36
4c2428524c22
annotation display view
Anthony Ly <anthonyly.com@gmail.com>
parents:
35
diff
changeset
|
543 |
case 'video': |
|
49
06627f23df42
show data annotations on tab open
Anthony Ly <anthonyly.com@gmail.com>
parents:
48
diff
changeset
|
544 |
|
|
06627f23df42
show data annotations on tab open
Anthony Ly <anthonyly.com@gmail.com>
parents:
48
diff
changeset
|
545 |
if(viewType.content.url != ""){ |
| 58 | 546 |
|
| 62 | 547 |
var videoWrap = $(tabContent).find('.annotation-video-content'); |
| 58 | 548 |
renderVideoInfo(videoWrap, viewType.content); |
549 |
|
|
|
49
06627f23df42
show data annotations on tab open
Anthony Ly <anthonyly.com@gmail.com>
parents:
48
diff
changeset
|
550 |
} |
|
06627f23df42
show data annotations on tab open
Anthony Ly <anthonyly.com@gmail.com>
parents:
48
diff
changeset
|
551 |
|
| 58 | 552 |
|
553 |
||
| 6 | 554 |
break; |
555 |
case 'text': |
|
| 38 | 556 |
var cledit = $(tabContent).find('.wysiwyg').cleditor(wysiwygConfig)[0]; |
| 6 | 557 |
break; |
| 42 | 558 |
case 'links': |
|
49
06627f23df42
show data annotations on tab open
Anthony Ly <anthonyly.com@gmail.com>
parents:
48
diff
changeset
|
559 |
var tbody = $(tabContent).find('tbody.links-rows'), |
|
06627f23df42
show data annotations on tab open
Anthony Ly <anthonyly.com@gmail.com>
parents:
48
diff
changeset
|
560 |
links = viewType.content.links; |
|
06627f23df42
show data annotations on tab open
Anthony Ly <anthonyly.com@gmail.com>
parents:
48
diff
changeset
|
561 |
if(links.length){ |
|
06627f23df42
show data annotations on tab open
Anthony Ly <anthonyly.com@gmail.com>
parents:
48
diff
changeset
|
562 |
$.each(links, function(k,v){ |
|
06627f23df42
show data annotations on tab open
Anthony Ly <anthonyly.com@gmail.com>
parents:
48
diff
changeset
|
563 |
addLinkRow(tbody, v); |
|
06627f23df42
show data annotations on tab open
Anthony Ly <anthonyly.com@gmail.com>
parents:
48
diff
changeset
|
564 |
}); |
|
06627f23df42
show data annotations on tab open
Anthony Ly <anthonyly.com@gmail.com>
parents:
48
diff
changeset
|
565 |
}else{//il n'y a pas de lien on en ajoute 1 |
|
06627f23df42
show data annotations on tab open
Anthony Ly <anthonyly.com@gmail.com>
parents:
48
diff
changeset
|
566 |
addLinkRow(tbody); |
|
06627f23df42
show data annotations on tab open
Anthony Ly <anthonyly.com@gmail.com>
parents:
48
diff
changeset
|
567 |
} |
| 38 | 568 |
break; |
|
49
06627f23df42
show data annotations on tab open
Anthony Ly <anthonyly.com@gmail.com>
parents:
48
diff
changeset
|
569 |
|
| 42 | 570 |
case 'slideshow': |
| 51 | 571 |
|
| 6 | 572 |
$(tabContent).find('.number-spin').spin(spinParam); |
573 |
$(tabContent).find('.ui-sortable').sortable({ |
|
| 58 | 574 |
start: function (event, ui) { |
575 |
$(ui.item).data("startindex", ui.item.index()); |
|
576 |
}, |
|
| 6 | 577 |
stop : function(event, ui){ |
578 |
disabledBtnSortable($(this)); |
|
| 58 | 579 |
}, |
580 |
update : function(event, ui){ |
|
581 |
var oldIndex = ui.item.data("startindex"), |
|
582 |
newIndex = ui.item.index(); |
|
583 |
currentAnnotation.content.images.move(oldIndex, newIndex); |
|
584 |
}, |
|
| 6 | 585 |
}); |
| 51 | 586 |
var diaporama = $(tabContent).find('#diaporama-'+idAnnotation), |
587 |
images = viewType.content.images; |
|
588 |
if(images.length){ |
|
589 |
$.each(images, function(k,v){ |
|
590 |
addImageToDiaporama(diaporama, v); |
|
591 |
}); |
|
592 |
} |
|
| 6 | 593 |
break; |
594 |
} |
|
|
34
e3a17ec94cd8
edition annotation first part
Anthony Ly <anthonyly.com@gmail.com>
parents:
28
diff
changeset
|
595 |
|
|
36
4c2428524c22
annotation display view
Anthony Ly <anthonyly.com@gmail.com>
parents:
35
diff
changeset
|
596 |
dataView.iconTab = getIcon(type); |
| 62 | 597 |
var tplOnglet = getTemplate('#tpl-onglet'); |
|
34
e3a17ec94cd8
edition annotation first part
Anthony Ly <anthonyly.com@gmail.com>
parents:
28
diff
changeset
|
598 |
var onglet = Mustache.render(tplOnglet, dataView); |
|
e3a17ec94cd8
edition annotation first part
Anthony Ly <anthonyly.com@gmail.com>
parents:
28
diff
changeset
|
599 |
|
|
e3a17ec94cd8
edition annotation first part
Anthony Ly <anthonyly.com@gmail.com>
parents:
28
diff
changeset
|
600 |
$(".nav-tabs li:last-child").after(onglet); |
|
e3a17ec94cd8
edition annotation first part
Anthony Ly <anthonyly.com@gmail.com>
parents:
28
diff
changeset
|
601 |
$('a[href=#tab-annotation-'+idAnnotation+']').tab('show'); |
| 62 | 602 |
|
|
34
e3a17ec94cd8
edition annotation first part
Anthony Ly <anthonyly.com@gmail.com>
parents:
28
diff
changeset
|
603 |
}//openTab() |
|
e3a17ec94cd8
edition annotation first part
Anthony Ly <anthonyly.com@gmail.com>
parents:
28
diff
changeset
|
604 |
|
|
36
4c2428524c22
annotation display view
Anthony Ly <anthonyly.com@gmail.com>
parents:
35
diff
changeset
|
605 |
function getIcon(type){ |
|
4c2428524c22
annotation display view
Anthony Ly <anthonyly.com@gmail.com>
parents:
35
diff
changeset
|
606 |
var icon; |
|
4c2428524c22
annotation display view
Anthony Ly <anthonyly.com@gmail.com>
parents:
35
diff
changeset
|
607 |
switch(type){ |
| 48 | 608 |
case 'audio': icon = 'volume-up'; |
|
36
4c2428524c22
annotation display view
Anthony Ly <anthonyly.com@gmail.com>
parents:
35
diff
changeset
|
609 |
break; |
|
4c2428524c22
annotation display view
Anthony Ly <anthonyly.com@gmail.com>
parents:
35
diff
changeset
|
610 |
case 'video': icon = 'film'; |
|
4c2428524c22
annotation display view
Anthony Ly <anthonyly.com@gmail.com>
parents:
35
diff
changeset
|
611 |
break; |
| 62 | 612 |
case 'text': icon = 'align-left'; |
|
36
4c2428524c22
annotation display view
Anthony Ly <anthonyly.com@gmail.com>
parents:
35
diff
changeset
|
613 |
break; |
| 38 | 614 |
case 'html': icon = 'code'; |
615 |
break; |
|
| 42 | 616 |
case 'links': icon = 'link'; |
|
36
4c2428524c22
annotation display view
Anthony Ly <anthonyly.com@gmail.com>
parents:
35
diff
changeset
|
617 |
break; |
| 42 | 618 |
case 'slideshow': icon = 'picture'; |
|
36
4c2428524c22
annotation display view
Anthony Ly <anthonyly.com@gmail.com>
parents:
35
diff
changeset
|
619 |
break; |
|
4c2428524c22
annotation display view
Anthony Ly <anthonyly.com@gmail.com>
parents:
35
diff
changeset
|
620 |
} |
|
4c2428524c22
annotation display view
Anthony Ly <anthonyly.com@gmail.com>
parents:
35
diff
changeset
|
621 |
return icon; |
|
4c2428524c22
annotation display view
Anthony Ly <anthonyly.com@gmail.com>
parents:
35
diff
changeset
|
622 |
} |
|
4c2428524c22
annotation display view
Anthony Ly <anthonyly.com@gmail.com>
parents:
35
diff
changeset
|
623 |
|
|
34
e3a17ec94cd8
edition annotation first part
Anthony Ly <anthonyly.com@gmail.com>
parents:
28
diff
changeset
|
624 |
//définit currentAnnotation quand la tab s'ouvre |
|
e3a17ec94cd8
edition annotation first part
Anthony Ly <anthonyly.com@gmail.com>
parents:
28
diff
changeset
|
625 |
$('#onglet-annotations').on('show', 'a[data-toggle="annotation"]', function (e) { |
|
e3a17ec94cd8
edition annotation first part
Anthony Ly <anthonyly.com@gmail.com>
parents:
28
diff
changeset
|
626 |
var idAnnotation = $(e.target).attr('data-id'); |
|
e3a17ec94cd8
edition annotation first part
Anthony Ly <anthonyly.com@gmail.com>
parents:
28
diff
changeset
|
627 |
currentAnnotation = _.find(annotations, function(c){ return c.id == idAnnotation; }); |
|
e3a17ec94cd8
edition annotation first part
Anthony Ly <anthonyly.com@gmail.com>
parents:
28
diff
changeset
|
628 |
}); |
|
e3a17ec94cd8
edition annotation first part
Anthony Ly <anthonyly.com@gmail.com>
parents:
28
diff
changeset
|
629 |
|
|
e3a17ec94cd8
edition annotation first part
Anthony Ly <anthonyly.com@gmail.com>
parents:
28
diff
changeset
|
630 |
//rafraichit annotations au retour sur la liste |
|
e3a17ec94cd8
edition annotation first part
Anthony Ly <anthonyly.com@gmail.com>
parents:
28
diff
changeset
|
631 |
$('#onglet-annotations').on('show', 'a[data-toggle="list-annotations"]', function (e) { |
|
e3a17ec94cd8
edition annotation first part
Anthony Ly <anthonyly.com@gmail.com>
parents:
28
diff
changeset
|
632 |
renderAnnotation(); |
|
e3a17ec94cd8
edition annotation first part
Anthony Ly <anthonyly.com@gmail.com>
parents:
28
diff
changeset
|
633 |
}); |
| 6 | 634 |
|
| 9 | 635 |
//fermer tab |
|
34
e3a17ec94cd8
edition annotation first part
Anthony Ly <anthonyly.com@gmail.com>
parents:
28
diff
changeset
|
636 |
$('#onglet-annotations').on('click', 'span.close-tab', function(e){ |
| 9 | 637 |
e.preventDefault();e.stopPropagation(); |
|
34
e3a17ec94cd8
edition annotation first part
Anthony Ly <anthonyly.com@gmail.com>
parents:
28
diff
changeset
|
638 |
var idAnnotation = $(this).parents('a').attr('data-id'); |
|
e3a17ec94cd8
edition annotation first part
Anthony Ly <anthonyly.com@gmail.com>
parents:
28
diff
changeset
|
639 |
closeTab(idAnnotation); |
| 9 | 640 |
}); |
641 |
||
|
34
e3a17ec94cd8
edition annotation first part
Anthony Ly <anthonyly.com@gmail.com>
parents:
28
diff
changeset
|
642 |
$('.tab-content').on('click', '.btn-save-annotation', function(e){ |
|
e3a17ec94cd8
edition annotation first part
Anthony Ly <anthonyly.com@gmail.com>
parents:
28
diff
changeset
|
643 |
e.preventDefault(); |
|
e3a17ec94cd8
edition annotation first part
Anthony Ly <anthonyly.com@gmail.com>
parents:
28
diff
changeset
|
644 |
var idAnnotation = $(this).attr('data-id'); |
|
e3a17ec94cd8
edition annotation first part
Anthony Ly <anthonyly.com@gmail.com>
parents:
28
diff
changeset
|
645 |
closeTab(idAnnotation); |
|
e3a17ec94cd8
edition annotation first part
Anthony Ly <anthonyly.com@gmail.com>
parents:
28
diff
changeset
|
646 |
}); |
|
e3a17ec94cd8
edition annotation first part
Anthony Ly <anthonyly.com@gmail.com>
parents:
28
diff
changeset
|
647 |
|
|
e3a17ec94cd8
edition annotation first part
Anthony Ly <anthonyly.com@gmail.com>
parents:
28
diff
changeset
|
648 |
function closeTab(idAnnotation){ |
|
e3a17ec94cd8
edition annotation first part
Anthony Ly <anthonyly.com@gmail.com>
parents:
28
diff
changeset
|
649 |
$('#onglet-'+idAnnotation).remove(); |
|
e3a17ec94cd8
edition annotation first part
Anthony Ly <anthonyly.com@gmail.com>
parents:
28
diff
changeset
|
650 |
$('.tab-content #tab-annotation-'+idAnnotation).remove(); |
|
e3a17ec94cd8
edition annotation first part
Anthony Ly <anthonyly.com@gmail.com>
parents:
28
diff
changeset
|
651 |
$('#tab-list-annotation').tab('show'); |
|
e3a17ec94cd8
edition annotation first part
Anthony Ly <anthonyly.com@gmail.com>
parents:
28
diff
changeset
|
652 |
} |
| 9 | 653 |
|
| 58 | 654 |
//video |
655 |
function renderVideoInfo(videoWrap, dataVideo){ |
|
| 62 | 656 |
|
657 |
var tplVideo = getTemplate('#tpl-video-row'); |
|
658 |
tplVideo = Mustache.render(tplVideo, dataVideo); |
|
659 |
|
|
660 |
videoWrap.empty().append(tplVideo); |
|
| 58 | 661 |
|
| 62 | 662 |
videoWrap = videoWrap.find(".video-container"); |
663 |
getVideoPlayer(dataVideo.url, videoWrap); |
|
664 |
|
|
| 58 | 665 |
} |
666 |
$('.popup').on('click', '.bibliotheque-video a', function(e){ |
|
667 |
e.preventDefault(); |
|
668 |
||
669 |
var url = $(this).attr('data-url'), |
|
670 |
title = $(this).attr('data-title'), |
|
671 |
description = $(this).attr('data-description'); |
|
672 |
||
673 |
currentAnnotation.content.url = url; |
|
674 |
currentAnnotation.content.title = title; |
|
675 |
currentAnnotation.content.description = description; |
|
676 |
||
677 |
$('.popup').modal('hide'); |
|
678 |
||
679 |
var videoWrap = $('#tab-annotation-'+currentAnnotation.id).find('.annotation-video-content'); |
|
680 |
renderVideoInfo(videoWrap, currentAnnotation.content); |
|
681 |
||
682 |
|
|
683 |
}); |
|
684 |
||
| 6 | 685 |
//diaporama |
| 51 | 686 |
|
687 |
//bibliotheque |
|
688 |
$('.popup').on('click', '.bibliotheque-image a', function(e){ |
|
689 |
e.preventDefault(); |
|
690 |
||
| 58 | 691 |
var url = $(this).attr('data-url'), |
692 |
title = $(this).attr('data-title'), |
|
693 |
description = $(this).attr('data-description'), |
|
| 51 | 694 |
image = { |
695 |
id : currentAnnotation.id, |
|
696 |
url : url, |
|
| 58 | 697 |
title : title, |
698 |
description : description |
|
| 51 | 699 |
}; |
700 |
currentAnnotation.content.images.push(image); |
|
701 |
||
702 |
var listDiaporama = $('#diaporama-'+currentAnnotation.id); |
|
703 |
addImageToDiaporama(listDiaporama, image); |
|
704 |
$('.popup').modal('hide'); |
|
705 |
}); |
|
706 |
||
707 |
function addImageToDiaporama(diaporama, dataView){ |
|
| 62 | 708 |
|
709 |
var tplDiapo = getTemplate('#tpl-diaporama-row'); |
|
710 |
tplDiapo = Mustache.render(tplDiapo, dataView); |
|
711 |
diaporama.append(tplDiapo); |
|
712 |
disabledBtnSortable(diaporama); |
|
713 |
|
|
| 6 | 714 |
}; |
715 |
||
| 9 | 716 |
//bouton up / down |
| 6 | 717 |
$(document).on('click', '.ui-sortable .btn-sort', function(e){ |
718 |
e.preventDefault(); |
|
719 |
var row = $(this).parents('tr.row-image-diaporama'), |
|
| 58 | 720 |
oldIndex = row.index(), |
| 6 | 721 |
listDiaporama = $(this).parents('.list-image-diaporama'); |
722 |
||
723 |
if($(this).hasClass('down')) |
|
724 |
row.insertAfter(row.next()); |
|
725 |
else if($(this).hasClass('up')) |
|
726 |
row.insertBefore(row.prev()); |
|
727 |
||
| 58 | 728 |
var newIndex = row.index(); |
729 |
currentAnnotation.content.images.move(oldIndex, newIndex); |
|
730 |
||
| 6 | 731 |
disabledBtnSortable(listDiaporama); |
732 |
}); |
|
733 |
||
| 58 | 734 |
$('.tab-content').on('click','.btn-delete-image', function(e){ |
735 |
e.preventDefault(); |
|
736 |
var rowImage = $(this).parents('tr.row-image-diaporama'), |
|
737 |
index = rowImage.index(); |
|
738 |
||
739 |
rowImage.remove(); |
|
740 |
currentAnnotation.content.images.splice(index, 1); |
|
741 |
}); |
|
742 |
||
| 6 | 743 |
function disabledBtnSortable(listDiaporama){ |
744 |
listDiaporama.find('.btn-sort.disabled').removeClass('disabled'); |
|
745 |
listDiaporama.find('tr.row-image-diaporama:first-child').find('.btn-sort.up').addClass('disabled'); |
|
746 |
listDiaporama.find('tr.row-image-diaporama:last-child').find('.btn-sort.down').addClass('disabled'); |
|
747 |
} |
|
748 |
||
| 9 | 749 |
|
| 48 | 750 |
//links |
751 |
$('.tab-content').on('click', '.add-link', function(e){ |
|
752 |
e.preventDefault(); |
|
753 |
var tbody = $(this).parents('tfoot').siblings('tbody'); |
|
754 |
addLinkRow(tbody); |
|
755 |
}); |
|
756 |
$('.tab-content').on('click', '.delete-link', function(e){ |
|
757 |
e.preventDefault(); |
|
758 |
var row = $(this).parents('tr'), |
|
| 62 | 759 |
tbody = $(this).parents('tbody'); |
760 |
||
| 48 | 761 |
row.remove(); |
762 |
updateLinks(tbody); |
|
763 |
}); |
|
764 |
function addLinkRow(tbody, dataView){ |
|
| 62 | 765 |
|
| 48 | 766 |
//head commun à tous |
| 62 | 767 |
var tplLinkRow = getTemplate('#tpl-links-row'); |
| 48 | 768 |
var output = Mustache.render(tplLinkRow, dataView); |
769 |
tbody.append(output); |
|
| 62 | 770 |
|
| 48 | 771 |
} |
772 |
$('.tab-content').on('keyup', '.links-rows input', function(e){ |
|
773 |
var tbody = $(this).parents('.links-rows'); |
|
774 |
updateLinks(tbody); |
|
775 |
}); |
|
776 |
function updateLinks(tbody){ |
|
777 |
links = new Array(); |
|
| 62 | 778 |
|
| 48 | 779 |
$.each(tbody.find('tr'), function(k, v){ |
780 |
var urlLink = $(v).find('.url-link').val(), |
|
781 |
titleLink = $(v).find('.title-link').val(), |
|
782 |
link = { |
|
| 58 | 783 |
url : urlLink, |
| 48 | 784 |
title : titleLink |
785 |
}; |
|
786 |
links.push(link); |
|
| 62 | 787 |
|
| 48 | 788 |
}); |
789 |
currentAnnotation.content.links = links; |
|
790 |
} |
|
|
34
e3a17ec94cd8
edition annotation first part
Anthony Ly <anthonyly.com@gmail.com>
parents:
28
diff
changeset
|
791 |
|
|
49
06627f23df42
show data annotations on tab open
Anthony Ly <anthonyly.com@gmail.com>
parents:
48
diff
changeset
|
792 |
//annotation audio |
|
06627f23df42
show data annotations on tab open
Anthony Ly <anthonyly.com@gmail.com>
parents:
48
diff
changeset
|
793 |
$('.tab-content').on('keyup', '.annotation-audio-content input, .annotation-audio-content textarea', function(){ |
|
06627f23df42
show data annotations on tab open
Anthony Ly <anthonyly.com@gmail.com>
parents:
48
diff
changeset
|
794 |
var name = $(this).attr('name'), |
|
06627f23df42
show data annotations on tab open
Anthony Ly <anthonyly.com@gmail.com>
parents:
48
diff
changeset
|
795 |
value = $(this).val(); |
|
06627f23df42
show data annotations on tab open
Anthony Ly <anthonyly.com@gmail.com>
parents:
48
diff
changeset
|
796 |
|
|
06627f23df42
show data annotations on tab open
Anthony Ly <anthonyly.com@gmail.com>
parents:
48
diff
changeset
|
797 |
currentAnnotation.content[name] = value; |
| 38 | 798 |
}); |
| 6 | 799 |
|
| 51 | 800 |
//annotation slideshow |
801 |
$('.tab-content').on('click', '.btn-autostart', function(){ |
|
802 |
var autostart = $(this).attr('data-autostart'); |
|
803 |
if(autostart == "true"){ autostart = true;} |
|
804 |
else {autostart = false;} |
|
805 |
currentAnnotation.content.autostart = autostart; |
|
806 |
}); |
|
807 |
||
808 |
$('.tab-content').on('change keyup', '.config-diaporama input[name=duration]', function(){ |
|
809 |
var value = $(this).val(); |
|
810 |
if(!isNaN(value)){ |
|
811 |
currentAnnotation.content.duration = value; |
|
812 |
} |
|
813 |
}); |
|
814 |
||
|
34
e3a17ec94cd8
edition annotation first part
Anthony Ly <anthonyly.com@gmail.com>
parents:
28
diff
changeset
|
815 |
//################ config |
|
e3a17ec94cd8
edition annotation first part
Anthony Ly <anthonyly.com@gmail.com>
parents:
28
diff
changeset
|
816 |
//tagit |
|
e3a17ec94cd8
edition annotation first part
Anthony Ly <anthonyly.com@gmail.com>
parents:
28
diff
changeset
|
817 |
function onTagItChange(e, ui) { |
|
e3a17ec94cd8
edition annotation first part
Anthony Ly <anthonyly.com@gmail.com>
parents:
28
diff
changeset
|
818 |
var tagitType = $(this).attr('data-type'), |
|
e3a17ec94cd8
edition annotation first part
Anthony Ly <anthonyly.com@gmail.com>
parents:
28
diff
changeset
|
819 |
value = $(this).val(); |
|
e3a17ec94cd8
edition annotation first part
Anthony Ly <anthonyly.com@gmail.com>
parents:
28
diff
changeset
|
820 |
|
|
e3a17ec94cd8
edition annotation first part
Anthony Ly <anthonyly.com@gmail.com>
parents:
28
diff
changeset
|
821 |
if(tagitType == 'chapter'){ |
|
e3a17ec94cd8
edition annotation first part
Anthony Ly <anthonyly.com@gmail.com>
parents:
28
diff
changeset
|
822 |
var idChapter = $(this).parents('form').attr('data-chapter-id'); |
|
e3a17ec94cd8
edition annotation first part
Anthony Ly <anthonyly.com@gmail.com>
parents:
28
diff
changeset
|
823 |
currentChapter.keywords = value.split(','); |
|
e3a17ec94cd8
edition annotation first part
Anthony Ly <anthonyly.com@gmail.com>
parents:
28
diff
changeset
|
824 |
$('#row-list-chapter-'+idChapter).find('.list-chapter-tags').text(value); |
|
e3a17ec94cd8
edition annotation first part
Anthony Ly <anthonyly.com@gmail.com>
parents:
28
diff
changeset
|
825 |
}else{ |
|
e3a17ec94cd8
edition annotation first part
Anthony Ly <anthonyly.com@gmail.com>
parents:
28
diff
changeset
|
826 |
currentAnnotation.keywords = value.split(','); |
|
e3a17ec94cd8
edition annotation first part
Anthony Ly <anthonyly.com@gmail.com>
parents:
28
diff
changeset
|
827 |
} |
|
e3a17ec94cd8
edition annotation first part
Anthony Ly <anthonyly.com@gmail.com>
parents:
28
diff
changeset
|
828 |
|
|
e3a17ec94cd8
edition annotation first part
Anthony Ly <anthonyly.com@gmail.com>
parents:
28
diff
changeset
|
829 |
} |
|
e3a17ec94cd8
edition annotation first part
Anthony Ly <anthonyly.com@gmail.com>
parents:
28
diff
changeset
|
830 |
|
|
e3a17ec94cd8
edition annotation first part
Anthony Ly <anthonyly.com@gmail.com>
parents:
28
diff
changeset
|
831 |
var tagitParam = { |
|
e3a17ec94cd8
edition annotation first part
Anthony Ly <anthonyly.com@gmail.com>
parents:
28
diff
changeset
|
832 |
afterTagRemoved : onTagItChange, |
|
e3a17ec94cd8
edition annotation first part
Anthony Ly <anthonyly.com@gmail.com>
parents:
28
diff
changeset
|
833 |
afterTagAdded : onTagItChange |
|
e3a17ec94cd8
edition annotation first part
Anthony Ly <anthonyly.com@gmail.com>
parents:
28
diff
changeset
|
834 |
} |
|
e3a17ec94cd8
edition annotation first part
Anthony Ly <anthonyly.com@gmail.com>
parents:
28
diff
changeset
|
835 |
|
| 6 | 836 |
//CLEditor annotation > text (wysiwyg) |
837 |
//http://premiumsoftware.net/cleditor/docs/GettingStarted.html#optionalParameters |
|
838 |
var wysiwygConfig = { |
|
839 |
width: 456, |
|
840 |
height: 250, |
|
841 |
controls: "bold italic underline strikethrough | font size " + |
|
| 38 | 842 |
"style | color highlight removeformat | bullets numbering | source", |
| 6 | 843 |
fonts: "Arial,Arial Black,Comic Sans MS,Courier New,Narrow,Garamond," + |
844 |
"Georgia,Impact,Sans Serif,Serif,Tahoma,Trebuchet MS,Verdana", |
|
845 |
sizes: "1,2,3,4,5,6,7", |
|
846 |
styles: [["Paragraph", "<p>"], ["Header 1", "<h1>"], ["Header 2", "<h2>"], |
|
847 |
["Header 3", "<h3>"], ["Header 4","<h4>"], ["Header 5","<h5>"], |
|
848 |
["Header 6","<h6>"]], |
|
849 |
docType: '<!DOCTYPE HTML>', |
|
| 38 | 850 |
bodyStyle: "margin:0; font-family: 'Helvetica Neue',​Helvetica,​Arial,​sans-serif;", |
851 |
updateTextArea : function(text){ |
|
|
49
06627f23df42
show data annotations on tab open
Anthony Ly <anthonyly.com@gmail.com>
parents:
48
diff
changeset
|
852 |
currentAnnotation.content.text = text; |
| 38 | 853 |
return text; |
854 |
}, |
|
855 |
updateFrame: function(text){ |
|
|
49
06627f23df42
show data annotations on tab open
Anthony Ly <anthonyly.com@gmail.com>
parents:
48
diff
changeset
|
856 |
currentAnnotation.content.text = text; |
| 38 | 857 |
return text; |
858 |
} |
|
| 6 | 859 |
}; |
860 |
||
861 |
//slider |
|
|
34
e3a17ec94cd8
edition annotation first part
Anthony Ly <anthonyly.com@gmail.com>
parents:
28
diff
changeset
|
862 |
function configSlider(data){ |
|
e3a17ec94cd8
edition annotation first part
Anthony Ly <anthonyly.com@gmail.com>
parents:
28
diff
changeset
|
863 |
return { |
|
e3a17ec94cd8
edition annotation first part
Anthony Ly <anthonyly.com@gmail.com>
parents:
28
diff
changeset
|
864 |
range: true, |
|
e3a17ec94cd8
edition annotation first part
Anthony Ly <anthonyly.com@gmail.com>
parents:
28
diff
changeset
|
865 |
values: [ data.begin.milliseconds, data.end.milliseconds ], |
|
e3a17ec94cd8
edition annotation first part
Anthony Ly <anthonyly.com@gmail.com>
parents:
28
diff
changeset
|
866 |
min: 0, |
|
e3a17ec94cd8
edition annotation first part
Anthony Ly <anthonyly.com@gmail.com>
parents:
28
diff
changeset
|
867 |
max: myMedia.duration.milliseconds, |
|
e3a17ec94cd8
edition annotation first part
Anthony Ly <anthonyly.com@gmail.com>
parents:
28
diff
changeset
|
868 |
slide: function( event, ui ) { |
|
e3a17ec94cd8
edition annotation first part
Anthony Ly <anthonyly.com@gmail.com>
parents:
28
diff
changeset
|
869 |
|
|
e3a17ec94cd8
edition annotation first part
Anthony Ly <anthonyly.com@gmail.com>
parents:
28
diff
changeset
|
870 |
data.setBegin(ui.values[0]); |
|
e3a17ec94cd8
edition annotation first part
Anthony Ly <anthonyly.com@gmail.com>
parents:
28
diff
changeset
|
871 |
data.setEnd(ui.values[1]); |
| 6 | 872 |
|
|
34
e3a17ec94cd8
edition annotation first part
Anthony Ly <anthonyly.com@gmail.com>
parents:
28
diff
changeset
|
873 |
var idSlider = $(this).attr('data-id'), |
|
e3a17ec94cd8
edition annotation first part
Anthony Ly <anthonyly.com@gmail.com>
parents:
28
diff
changeset
|
874 |
wTimeline = $('.timeline-annotations').width(), |
|
e3a17ec94cd8
edition annotation first part
Anthony Ly <anthonyly.com@gmail.com>
parents:
28
diff
changeset
|
875 |
annotationTimeline = $('#annotation-timeline-'+ data.id), |
|
e3a17ec94cd8
edition annotation first part
Anthony Ly <anthonyly.com@gmail.com>
parents:
28
diff
changeset
|
876 |
width = Math.floor(data.getDuration() * wTimeline / myMedia.duration), |
|
e3a17ec94cd8
edition annotation first part
Anthony Ly <anthonyly.com@gmail.com>
parents:
28
diff
changeset
|
877 |
left = Math.floor(data.begin * wTimeline / myMedia.duration); |
|
e3a17ec94cd8
edition annotation first part
Anthony Ly <anthonyly.com@gmail.com>
parents:
28
diff
changeset
|
878 |
|
|
e3a17ec94cd8
edition annotation first part
Anthony Ly <anthonyly.com@gmail.com>
parents:
28
diff
changeset
|
879 |
$( '#'+ idSlider +'-begin' ).html(data.begin.toString()); |
|
e3a17ec94cd8
edition annotation first part
Anthony Ly <anthonyly.com@gmail.com>
parents:
28
diff
changeset
|
880 |
$( '#'+ idSlider +'-duration' ).html(data.getDuration().toString()); |
|
e3a17ec94cd8
edition annotation first part
Anthony Ly <anthonyly.com@gmail.com>
parents:
28
diff
changeset
|
881 |
$( '#'+ idSlider +'-end' ).html(data.end.toString()); |
| 6 | 882 |
|
|
34
e3a17ec94cd8
edition annotation first part
Anthony Ly <anthonyly.com@gmail.com>
parents:
28
diff
changeset
|
883 |
annotationTimeline.css({ |
|
e3a17ec94cd8
edition annotation first part
Anthony Ly <anthonyly.com@gmail.com>
parents:
28
diff
changeset
|
884 |
left : left, |
|
e3a17ec94cd8
edition annotation first part
Anthony Ly <anthonyly.com@gmail.com>
parents:
28
diff
changeset
|
885 |
width :width |
|
e3a17ec94cd8
edition annotation first part
Anthony Ly <anthonyly.com@gmail.com>
parents:
28
diff
changeset
|
886 |
}); |
|
e3a17ec94cd8
edition annotation first part
Anthony Ly <anthonyly.com@gmail.com>
parents:
28
diff
changeset
|
887 |
|
| 62 | 888 |
|
889 |
||
890 |
}, |
|
891 |
stop : function(){ |
|
892 |
renderAnnotation() |
|
|
34
e3a17ec94cd8
edition annotation first part
Anthony Ly <anthonyly.com@gmail.com>
parents:
28
diff
changeset
|
893 |
} |
|
e3a17ec94cd8
edition annotation first part
Anthony Ly <anthonyly.com@gmail.com>
parents:
28
diff
changeset
|
894 |
}; |
|
e3a17ec94cd8
edition annotation first part
Anthony Ly <anthonyly.com@gmail.com>
parents:
28
diff
changeset
|
895 |
} |
| 9 | 896 |
|
| 62 | 897 |
//init annotation content data |
| 42 | 898 |
function getContentAnnotationByType(type){ |
899 |
var content; |
|
900 |
switch(type){ |
|
| 48 | 901 |
case 'audio': |
| 42 | 902 |
content = { |
| 48 | 903 |
mimetype : "application/x-ldt-audio", |
| 42 | 904 |
url : "", |
905 |
embedcode : "" |
|
906 |
}; |
|
907 |
break; |
|
908 |
case 'video': |
|
909 |
content = { |
|
910 |
mimetype : "application/x-ldt-video", |
|
911 |
url : "", |
|
912 |
embedcode : "" |
|
913 |
}; |
|
914 |
break; |
|
915 |
case 'text': |
|
916 |
content = { |
|
917 |
mimetype : "application/x-ldt-text", |
|
918 |
markup : "html", |
|
|
49
06627f23df42
show data annotations on tab open
Anthony Ly <anthonyly.com@gmail.com>
parents:
48
diff
changeset
|
919 |
text : "azerty" |
| 42 | 920 |
}; |
921 |
break; |
|
922 |
case 'links': |
|
923 |
content = { |
|
924 |
mimetype : "application/x-ldt-links", |
|
925 |
links : [] |
|
926 |
}; |
|
927 |
break; |
|
928 |
case 'slideshow': |
|
929 |
content = { |
|
930 |
mimetype : "application/x-ldt-slideshow", |
|
931 |
duration : 1, |
|
932 |
autostart : false, |
|
933 |
images : [] |
|
934 |
}; |
|
935 |
break; |
|
936 |
} |
|
937 |
return content; |
|
938 |
}//getContentAnnotationByType |
|
| 38 | 939 |
|
940 |
||
| 58 | 941 |
|
942 |
||
| 9 | 943 |
//test |
|
21
abd04f346dbe
delete row on enter key press in modal
Anthony Ly <anthonyly.com@gmail.com>
parents:
18
diff
changeset
|
944 |
|
| 48 | 945 |
$('.log-annotations').bind('click', function(e){ |
946 |
e.preventDefault(); |
|
|
49
06627f23df42
show data annotations on tab open
Anthony Ly <anthonyly.com@gmail.com>
parents:
48
diff
changeset
|
947 |
console.log(annotations.length + ' annotations', annotations); |
| 48 | 948 |
}); |
949 |
||
950 |
$('.log-chapters').bind('click', function(e){ |
|
951 |
e.preventDefault(); |
|
|
49
06627f23df42
show data annotations on tab open
Anthony Ly <anthonyly.com@gmail.com>
parents:
48
diff
changeset
|
952 |
console.log(chapters.length + ' chapitres',chapters); |
| 48 | 953 |
}); |
| 62 | 954 |
|
| 58 | 955 |
});//ready |
956 |
||
| 62 | 957 |
//Utilitaires |
| 58 | 958 |
Array.prototype.move = function (old_index, new_index) { |
959 |
if (new_index >= this.length) { |
|
960 |
var k = new_index - this.length; |
|
961 |
while ((k--) + 1) { |
|
962 |
this.push(undefined); |
|
963 |
} |
|
964 |
} |
|
965 |
this.splice(new_index, 0, this.splice(old_index, 1)[0]); |
|
| 62 | 966 |
return this; |
| 58 | 967 |
}; |
968 |
||
969 |
||
970 |
function getVideoPlayer(src, videoWrap){ |
|
971 |
||
972 |
var youtubeTemplate = _.template( |
|
973 |
'<iframe width="<%- width %>" height="<%- height %>" src="http://www.youtube.com/embed/<%- ytid %>?rel=0&autoplay=<%- autoplay %>" frameborder="0"></iframe>' |
|
974 |
); |
|
975 |
|
|
976 |
var htmlTemplate = _.template( |
|
977 |
'<<%- type %> width="<%- width %>" controls="true" autoplay="<%- autoplay %>" src="<%- src %>"/>' |
|
978 |
); |
|
979 |
|
|
980 |
var mediaW = 460, |
|
981 |
mediaH = 345, |
|
982 |
autoplay = false; |
|
983 |
||
984 |
|
|
985 |
if (/^(https?:\/\/)?(www\.)?youtu\.?be/.test(src)) { |
|
986 |
var urlparts = src.split(/[?&]/g), |
|
987 |
ytid = "", |
|
988 |
vtest = /^v=/; |
|
989 |
urlparts.slice(1).forEach(function(p) { |
|
990 |
if (/^v=/.test(p)) { |
|
991 |
ytid = p.replace(vtest,""); |
|
992 |
} |
|
993 |
}); |
|
994 |
if (!ytid) { |
|
995 |
ytid = (urlparts[0].match(/[^\/]+$/) || [""])[0]; |
|
996 |
} |
|
997 |
videoWrap.html(youtubeTemplate({ |
|
998 |
ytid: ytid, |
|
999 |
width: mediaW, |
|
1000 |
height: mediaH, |
|
1001 |
autoplay: autoplay |
|
1002 |
})); |
|
1003 |
return; |
|
1004 |
} |
|
1005 |
|
|
1006 |
if (/^(https?:\/\/)?(www\.)?vimeo/.test(src)) { |
|
1007 |
$.ajax({ |
|
1008 |
url: "http://vimeo.com/api/oembed.json", |
|
1009 |
dataType: "jsonp", |
|
1010 |
data: { |
|
1011 |
width: mediaW, |
|
1012 |
height: mediaH, |
|
1013 |
url: src, |
|
1014 |
autoplay: autoplay, |
|
1015 |
color: "be4477", |
|
1016 |
portrait: false, |
|
1017 |
title: false, |
|
1018 |
byline: false |
|
1019 |
}, |
|
1020 |
success: function(data) { |
|
1021 |
videoWrap.html(data.html); |
|
1022 |
} |
|
1023 |
}); |
|
1024 |
return; |
|
1025 |
} |
|
1026 |
|
|
1027 |
if (/^(https?:\/\/)?(www\.)?dailymotion/.test(src)) { |
|
1028 |
$.ajax({ |
|
1029 |
url: "http://www.dailymotion.com/services/oembed", |
|
1030 |
dataType: "jsonp", |
|
1031 |
data: { |
|
1032 |
format: "json", |
|
1033 |
maxwidth: mediaW, |
|
1034 |
maxheight: mediaH, |
|
1035 |
url: src |
|
1036 |
}, |
|
1037 |
success: function(data) { |
|
1038 |
videoWrap.html(data.html); |
|
1039 |
} |
|
1040 |
}); |
|
1041 |
return; |
|
1042 |
} |
|
1043 |
|
|
1044 |
if (/^(https?:\/\/)?(www\.)?soundcloud\.com/.test(src)) { |
|
1045 |
$.ajax({ |
|
1046 |
url: "http://soundcloud.com/oembed", |
|
1047 |
dataType: "jsonp", |
|
1048 |
data: { |
|
1049 |
format: "js", |
|
1050 |
show_comments: false, |
|
1051 |
auto_play: autoplay, |
|
1052 |
show_artwork: false, |
|
1053 |
url: src, |
|
1054 |
color: "63be6c" |
|
1055 |
}, |
|
1056 |
success: function(data) { |
|
1057 |
videoWrap.html(data.html); |
|
1058 |
} |
|
1059 |
}); |
|
1060 |
return; |
|
1061 |
} |
|
1062 |
|
|
1063 |
var extension = (src.match(/\.([\d\w]+)$/) || ["",""])[1], |
|
1064 |
mimetype = 'video' + "/" + extension, |
|
1065 |
fallbacks = { "video/webm": "mp4", "video/mp4": "webm" }, |
|
1066 |
canPlay = document.createElement("video").canPlayType(mimetype); |
|
1067 |
|
|
1068 |
if (!canPlay) { |
|
1069 |
src = src.replace(/\.[\d\w]+$/,"." + fallbacks[mimetype]); |
|
1070 |
} |
|
1071 |
|
|
1072 |
console.log(mimetype, canPlay, src); |
|
1073 |
|
|
1074 |
videoWrap.html(htmlTemplate({ |
|
1075 |
type: 'video', |
|
1076 |
src: src, |
|
1077 |
width: mediaW, |
|
1078 |
height: mediaH, |
|
1079 |
autoplay: "" + autoplay |
|
1080 |
})); |
|
1081 |
|
|
| 62 | 1082 |
}//getVideoPlayer |