| author | Anthony Ly <anthonyly.com@gmail.com> |
| Fri, 24 May 2013 11:02:32 +0200 | |
| changeset 35 | 6eb0de10e9f8 |
| parent 34 | e3a17ec94cd8 |
| child 36 | 4c2428524c22 |
| 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 = { |
|
10 |
diaporama : null, |
|
|
21
abd04f346dbe
delete row on enter key press in modal
Anthony Ly <anthonyly.com@gmail.com>
parents:
18
diff
changeset
|
11 |
idAnnotation : null, |
| 28 | 12 |
colorsIndex : 0, |
13 |
colors : |
|
14 |
['#f39c12', '#2ecc71', '#3498db', '#9b59b6', |
|
15 |
'#f1c40f', '#e67e22', '#e74c3c', '#ecf0f1', |
|
16 |
'#16a085', '#27ae60', '#2980b9', '#8e44ad', |
|
17 |
'#f39c12', '#d35400', '#c0392b', '#bdc3c7'] |
|
18 |
}; |
|
19 |
||
20 |
||
| 16 | 21 |
myProject.onLoad(function() { |
22 |
||
23 |
$(".project-title").text(myProject.title); |
|
24 |
|
|
25 |
myMedia = myProject.getCurrentMedia(); |
|
26 |
|
|
|
34
e3a17ec94cd8
edition annotation first part
Anthony Ly <anthonyly.com@gmail.com>
parents:
28
diff
changeset
|
27 |
//chargement des chapitres et annotations existants |
| 28 | 28 |
loadInitChapters(); |
|
34
e3a17ec94cd8
edition annotation first part
Anthony Ly <anthonyly.com@gmail.com>
parents:
28
diff
changeset
|
29 |
loadInitAnnotation() |
|
21
abd04f346dbe
delete row on enter key press in modal
Anthony Ly <anthonyly.com@gmail.com>
parents:
18
diff
changeset
|
30 |
|
| 16 | 31 |
IriSP.htmlPlayer( |
32 |
myMedia, |
|
33 |
$(".main-video"), |
|
34 |
{ |
|
35 |
width: 460, |
|
36 |
height: 345, |
|
37 |
controls: true, |
|
38 |
autostart: true |
|
39 |
} |
|
40 |
); |
|
41 |
||
42 |
myMedia.on("timeupdate", function(t) { |
|
43 |
||
44 |
//curseur chapitre |
|
|
21
abd04f346dbe
delete row on enter key press in modal
Anthony Ly <anthonyly.com@gmail.com>
parents:
18
diff
changeset
|
45 |
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
|
46 |
pos = wContainer * t / myMedia.duration, |
| 16 | 47 |
btnCutChapter = $('.btn-cut-chapter'), |
48 |
wBtnCutChapter = btnCutChapter.outerWidth(); |
|
|
34
e3a17ec94cd8
edition annotation first part
Anthony Ly <anthonyly.com@gmail.com>
parents:
28
diff
changeset
|
49 |
|
|
e3a17ec94cd8
edition annotation first part
Anthony Ly <anthonyly.com@gmail.com>
parents:
28
diff
changeset
|
50 |
$(".indicateur-chapter, .indicateur-annotation").css("left",pos); |
| 16 | 51 |
if(pos+wBtnCutChapter>wContainer){ |
52 |
btnCutChapter.css("left",(pos - wBtnCutChapter)); |
|
53 |
}else{ |
|
54 |
btnCutChapter.css("left",pos); |
|
55 |
} |
|
| 18 | 56 |
});//timeupdate |
| 16 | 57 |
|
58 |
});//myProject.onLoad |
|
59 |
||
| 6 | 60 |
|
|
34
e3a17ec94cd8
edition annotation first part
Anthony Ly <anthonyly.com@gmail.com>
parents:
28
diff
changeset
|
61 |
//--modal |
| 9 | 62 |
$(document).on('click', 'a.open-modal', function(e){ |
63 |
var diaporama = $(this).attr('data-diaporama'), |
|
64 |
idAnnotation = $(this).attr('data-id'); |
|
65 |
||
66 |
if(diaporama !== undefined){ |
|
67 |
global.diaporama = diaporama; |
|
68 |
} |
|
69 |
if(idAnnotation !== undefined){ |
|
70 |
global.idAnnotation = idAnnotation; |
|
71 |
} |
|
| 22 | 72 |
}); |
73 |
||
| 6 | 74 |
//edition image |
75 |
$('.popup').on('change', '#media-type-select', function(e){ |
|
76 |
var typeImage = $(this).val(); |
|
77 |
$('.input-image-url, .input-image-upload').hide(); |
|
78 |
$('.input-image-'+typeImage).show(); |
|
79 |
}); |
|
| 22 | 80 |
|
| 6 | 81 |
//bibliotheque |
82 |
//video |
|
83 |
$('.popup').on('click', '.bibliotheque-video a', function(e){ |
|
84 |
e.preventDefault(); |
|
85 |
$('.popup').modal('hide'); |
|
86 |
$.get('template.html', function(templates){ |
|
87 |
var videoWrap = $('#'+global.idAnnotation).find('.annotation-video-content'), |
|
88 |
tplVideo = $(templates).filter('#tpl-video-row').html(); |
|
89 |
videoWrap.empty().append(tplVideo); |
|
90 |
}); |
|
91 |
|
|
92 |
}); |
|
93 |
//image |
|
94 |
$('.popup').on('click', '.bibliotheque-image a', function(e){ |
|
95 |
e.preventDefault(); |
|
96 |
var listDiaporama = $('#'+global.diaporama); |
|
97 |
addImageToDiaporama(listDiaporama); |
|
98 |
$('.popup').modal('hide'); |
|
99 |
}); |
|
100 |
||
|
35
6eb0de10e9f8
delete / edit / new annotation head
Anthony Ly <anthonyly.com@gmail.com>
parents:
34
diff
changeset
|
101 |
|
| 6 | 102 |
|
103 |
//confirmation suppression |
|
104 |
$("#modal-confirm").on('click', '#btn-delete-modal', function(e){ |
|
| 9 | 105 |
|
| 6 | 106 |
}); |
107 |
||
|
34
e3a17ec94cd8
edition annotation first part
Anthony Ly <anthonyly.com@gmail.com>
parents:
28
diff
changeset
|
108 |
//--title-editor |
| 6 | 109 |
$('.project-title-editor ._popover').bind('click',function(e){e.preventDefault()}); |
110 |
$('.project-title-editor ._popover').popover({ |
|
111 |
html : true, |
|
112 |
content : function(){ |
|
113 |
var previousValue = $('.project-title').text(), |
|
114 |
formInput = |
|
115 |
'<form action="#" class="project-title-editor-form">'+ |
|
116 |
'<input type="text" class="project-title-editor-input" value="'+previousValue+'">'+ |
|
117 |
'</form>'; |
|
118 |
return formInput; |
|
119 |
} |
|
120 |
}); |
|
121 |
||
122 |
$('body').on('click', function (e) { |
|
123 |
$('._popover').each(function () { |
|
124 |
if (!$(this).is(e.target) && $(this).has(e.target).length === 0 && $('.popover').has(e.target).length === 0) { |
|
125 |
$(this).popover('hide'); |
|
126 |
} |
|
127 |
}); |
|
128 |
}); |
|
129 |
||
130 |
$('body').on('submit', '.project-title-editor-form', function(e){ |
|
131 |
e.preventDefault(); |
|
132 |
$('._popover').popover('hide'); |
|
133 |
}); |
|
134 |
||
135 |
$(document).on('keyup', '.project-title-editor-input', function() { |
|
136 |
$('.project-title').html($(this).val()); |
|
137 |
}); |
|
| 9 | 138 |
|
|
34
e3a17ec94cd8
edition annotation first part
Anthony Ly <anthonyly.com@gmail.com>
parents:
28
diff
changeset
|
139 |
//######################## chapter |
| 22 | 140 |
|
141 |
//edit |
|
142 |
$('.list-chapter-wrap').on('click', '.btn-edit-chapter', function(e){ |
|
| 6 | 143 |
e.preventDefault(); |
| 22 | 144 |
var idChapter = $(this).attr('data-chapter-id'); |
145 |
loadFormChapter(idChapter); |
|
146 |
}); |
|
147 |
||
| 23 | 148 |
$('.chapter-segments').on('click', 'li', function(){ |
149 |
var idChapter = $(this).attr('id'); |
|
150 |
loadFormChapter(idChapter); |
|
151 |
}); |
|
| 22 | 152 |
|
153 |
$('.chapter-widget-info').on('keyup', 'input[name=title], textarea', function(e){ |
|
154 |
var name = $(this).attr('name'), |
|
155 |
value = $(this).val(); |
|
156 |
currentChapter[name] = value; |
|
157 |
if(name == 'title'){ |
|
158 |
var idChapter = $(this).parents('form').attr('data-chapter-id'); |
|
159 |
$('.chapter-segments').find('#'+idChapter).text(value); |
|
160 |
$('#row-list-chapter-'+idChapter).find('td:first').text(value); |
|
| 6 | 161 |
} |
| 22 | 162 |
}); |
163 |
||
164 |
||
165 |
||
166 |
function loadFormChapter(idChapter){ |
|
| 28 | 167 |
currentChapter = _.find(chapters, function(c){ return c.id == idChapter; }); |
168 |
var chapterWrap = $('.chapter-widget-info'), |
|
169 |
indexChapter = _.indexOf(chapters, currentChapter), |
|
170 |
beginTangle = (indexChapter>0) ? true : false, |
|
171 |
endTangle = (indexChapter<(chapters.length-1)) ? true : false; |
|
| 22 | 172 |
|
| 28 | 173 |
currentChapter.beginTangle = beginTangle; |
174 |
currentChapter.endTangle = endTangle; |
|
| 22 | 175 |
|
| 6 | 176 |
$.get('template.html', function(templates){ |
177 |
var tpl = $(templates).filter('#tpl-chapter-edit').html(); |
|
| 28 | 178 |
tpl = Mustache.render(tpl, currentChapter); |
| 22 | 179 |
chapterWrap.empty().append(tpl); |
180 |
chapterWrap.find('.tag-it').tagit(tagitParam); |
|
| 6 | 181 |
}); |
| 22 | 182 |
} |
183 |
||
184 |
||
185 |
//supprimer |
|
186 |
$('.list-chapter-wrap').on('click', '.btn-delete-chapter', function(e){ |
|
187 |
e.preventDefault(); |
|
188 |
||
189 |
if(chapters.length == 1){alert('Le projet doit contenir au moins un chapitre.'); return;} |
|
| 28 | 190 |
|
| 22 | 191 |
var idChapter = $(this).attr('data-chapter-id'), |
192 |
chapter = _.find(chapters, function(c){ return c.id == idChapter; }), |
|
193 |
indexChapter = _.indexOf(chapters, chapter), |
|
194 |
chapterModify; |
|
195 |
if(indexChapter == 0){ |
|
196 |
chapterModify = chapters[1]; |
|
| 28 | 197 |
chapterModify.setBegin(0); |
| 22 | 198 |
}else{ |
199 |
chapterModify = chapters[indexChapter-1]; |
|
| 28 | 200 |
//var newEnd = new IriSP.Model.Time(chapter.end) |
201 |
chapterModify.setEnd(chapter.end); |
|
| 22 | 202 |
} |
203 |
chapters = _(chapters).reject(function(c) { return c.id == idChapter; }); |
|
204 |
renderChapter(); |
|
205 |
//si le formulaire est visible |
|
206 |
if($('#form-chapter-edit-'+idChapter).length){ |
|
207 |
$('#form-chapter-edit-'+idChapter).remove(); |
|
208 |
} |
|
209 |
}); |
|
210 |
||
211 |
//nouveau chapitre |
|
| 28 | 212 |
function newChapter(dataChapter){ |
213 |
var chapter = new IriSP.Model.Annotation(false, myProject); |
|
214 |
chapter.setMedia(myMedia.id); |
|
215 |
chapter.setBegin(dataChapter.begin); |
|
216 |
chapter.setEnd(dataChapter.end); |
|
217 |
chapter.title = dataChapter.title; |
|
218 |
chapter.description = dataChapter.description; |
|
219 |
chapter.keywords = dataChapter.keywords; |
|
220 |
chapter.color = global.colors[(global.colorsIndex<global.colors.length) ? global.colorsIndex++ : (global.colorsIndex=0)]; |
|
221 |
|
|
222 |
chapters.push(chapter); |
|
223 |
renderChapter(); |
|
224 |
loadFormChapter(chapter.id); |
|
225 |
} |
|
226 |
||
| 6 | 227 |
$('.chapter-widget').on('click', '.btn-cut-chapter', function(e){ |
228 |
e.preventDefault(); |
|
| 16 | 229 |
|
| 28 | 230 |
var dataChapter = { |
231 |
title : 'New', |
|
232 |
begin : myMedia.currentTime, |
|
233 |
end : organizeNewChapter(myMedia.currentTime), |
|
234 |
description : 'description', |
|
|
34
e3a17ec94cd8
edition annotation first part
Anthony Ly <anthonyly.com@gmail.com>
parents:
28
diff
changeset
|
235 |
keywords : ['tag1','tag2'] |
| 28 | 236 |
}; |
|
21
abd04f346dbe
delete row on enter key press in modal
Anthony Ly <anthonyly.com@gmail.com>
parents:
18
diff
changeset
|
237 |
|
| 28 | 238 |
newChapter(dataChapter); |
239 |
||
| 6 | 240 |
}); |
| 22 | 241 |
|
242 |
function organizeNewChapter(beginNew){ |
|
| 6 | 243 |
|
| 22 | 244 |
var returnEnd; |
245 |
$.each(chapters, function(k, v){ |
|
246 |
var begin = v.begin, |
|
247 |
end = v.end; |
|
248 |
if(beginNew>=begin && beginNew<=end){ |
|
| 28 | 249 |
returnEnd = new IriSP.Model.Time(end); |
250 |
v.setEnd(beginNew); |
|
| 22 | 251 |
} |
252 |
}); |
|
| 28 | 253 |
|
| 22 | 254 |
return returnEnd; |
255 |
} |
|
256 |
|
|
257 |
function renderChapter(){ |
|
258 |
var chapterSegmentWrap = $('.chapter-segments'), |
|
259 |
wChapterSegmentWrap = chapterSegmentWrap.width(), |
|
260 |
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
|
261 |
|
| 22 | 262 |
chapters = _.sortBy(chapters, function(c){ |
263 |
return c.begin; |
|
|
21
abd04f346dbe
delete row on enter key press in modal
Anthony Ly <anthonyly.com@gmail.com>
parents:
18
diff
changeset
|
264 |
}); |
| 18 | 265 |
|
|
21
abd04f346dbe
delete row on enter key press in modal
Anthony Ly <anthonyly.com@gmail.com>
parents:
18
diff
changeset
|
266 |
chapterSegmentWrap.empty(); |
| 22 | 267 |
chapterList.empty(); |
|
21
abd04f346dbe
delete row on enter key press in modal
Anthony Ly <anthonyly.com@gmail.com>
parents:
18
diff
changeset
|
268 |
|
|
abd04f346dbe
delete row on enter key press in modal
Anthony Ly <anthonyly.com@gmail.com>
parents:
18
diff
changeset
|
269 |
$.each(chapters, function(k, v){ |
| 28 | 270 |
//form |
271 |
if($('#form-chapter-edit-'+v.id).length){ |
|
272 |
loadFormChapter(v.id); |
|
273 |
} |
|
| 22 | 274 |
//segments |
| 28 | 275 |
var width = Math.floor(v.getDuration() * wChapterSegmentWrap / myMedia.duration), |
| 22 | 276 |
segment = $('<li>'+v.title+'</li>').css({ |
|
21
abd04f346dbe
delete row on enter key press in modal
Anthony Ly <anthonyly.com@gmail.com>
parents:
18
diff
changeset
|
277 |
width : width, |
| 22 | 278 |
backgroundColor : v.color |
279 |
}).attr('id', v.id); |
|
280 |
|
|
281 |
chapterSegmentWrap.append(segment); |
|
| 28 | 282 |
|
| 22 | 283 |
//liste |
284 |
$.get('template.html', function(templates){ |
|
285 |
var tplChapterRow = $(templates).filter('#tpl-chapter-row').html(); |
|
286 |
tplChapterRow = Mustache.render(tplChapterRow, v); |
|
287 |
chapterList.append(tplChapterRow); |
|
288 |
||
289 |
}); |
|
|
21
abd04f346dbe
delete row on enter key press in modal
Anthony Ly <anthonyly.com@gmail.com>
parents:
18
diff
changeset
|
290 |
}); |
|
abd04f346dbe
delete row on enter key press in modal
Anthony Ly <anthonyly.com@gmail.com>
parents:
18
diff
changeset
|
291 |
} |
|
abd04f346dbe
delete row on enter key press in modal
Anthony Ly <anthonyly.com@gmail.com>
parents:
18
diff
changeset
|
292 |
|
| 22 | 293 |
//init |
| 28 | 294 |
function loadInitChapters(){//nouveau projet, 1 chapitre |
|
21
abd04f346dbe
delete row on enter key press in modal
Anthony Ly <anthonyly.com@gmail.com>
parents:
18
diff
changeset
|
295 |
var dataChapter = { |
| 28 | 296 |
title : 'New', |
297 |
begin : 0, |
|
298 |
end : myMedia.duration, |
|
299 |
description : 'description', |
|
|
34
e3a17ec94cd8
edition annotation first part
Anthony Ly <anthonyly.com@gmail.com>
parents:
28
diff
changeset
|
300 |
keywords : ['tag1','tag2'] |
| 28 | 301 |
}; |
|
21
abd04f346dbe
delete row on enter key press in modal
Anthony Ly <anthonyly.com@gmail.com>
parents:
18
diff
changeset
|
302 |
|
| 28 | 303 |
newChapter(dataChapter); |
|
21
abd04f346dbe
delete row on enter key press in modal
Anthony Ly <anthonyly.com@gmail.com>
parents:
18
diff
changeset
|
304 |
} |
|
abd04f346dbe
delete row on enter key press in modal
Anthony Ly <anthonyly.com@gmail.com>
parents:
18
diff
changeset
|
305 |
|
| 22 | 306 |
|
|
34
e3a17ec94cd8
edition annotation first part
Anthony Ly <anthonyly.com@gmail.com>
parents:
28
diff
changeset
|
307 |
//######################## annotation |
|
e3a17ec94cd8
edition annotation first part
Anthony Ly <anthonyly.com@gmail.com>
parents:
28
diff
changeset
|
308 |
|
|
e3a17ec94cd8
edition annotation first part
Anthony Ly <anthonyly.com@gmail.com>
parents:
28
diff
changeset
|
309 |
function loadInitAnnotation(){//nouveau projet, 1 chapitre |
|
e3a17ec94cd8
edition annotation first part
Anthony Ly <anthonyly.com@gmail.com>
parents:
28
diff
changeset
|
310 |
var dataAnnotation = { |
|
e3a17ec94cd8
edition annotation first part
Anthony Ly <anthonyly.com@gmail.com>
parents:
28
diff
changeset
|
311 |
title : 'Titre azerty', |
|
e3a17ec94cd8
edition annotation first part
Anthony Ly <anthonyly.com@gmail.com>
parents:
28
diff
changeset
|
312 |
begin : myMedia.duration/5, |
|
e3a17ec94cd8
edition annotation first part
Anthony Ly <anthonyly.com@gmail.com>
parents:
28
diff
changeset
|
313 |
end : myMedia.duration/3, |
|
e3a17ec94cd8
edition annotation first part
Anthony Ly <anthonyly.com@gmail.com>
parents:
28
diff
changeset
|
314 |
description : 'description', |
|
e3a17ec94cd8
edition annotation first part
Anthony Ly <anthonyly.com@gmail.com>
parents:
28
diff
changeset
|
315 |
type : 'video', |
|
e3a17ec94cd8
edition annotation first part
Anthony Ly <anthonyly.com@gmail.com>
parents:
28
diff
changeset
|
316 |
keywords : ['ideal', 'tag'] |
|
e3a17ec94cd8
edition annotation first part
Anthony Ly <anthonyly.com@gmail.com>
parents:
28
diff
changeset
|
317 |
}; |
| 22 | 318 |
|
|
34
e3a17ec94cd8
edition annotation first part
Anthony Ly <anthonyly.com@gmail.com>
parents:
28
diff
changeset
|
319 |
newAnnotation(dataAnnotation); |
|
35
6eb0de10e9f8
delete / edit / new annotation head
Anthony Ly <anthonyly.com@gmail.com>
parents:
34
diff
changeset
|
320 |
renderAnnotation(); |
|
34
e3a17ec94cd8
edition annotation first part
Anthony Ly <anthonyly.com@gmail.com>
parents:
28
diff
changeset
|
321 |
} |
|
e3a17ec94cd8
edition annotation first part
Anthony Ly <anthonyly.com@gmail.com>
parents:
28
diff
changeset
|
322 |
|
|
e3a17ec94cd8
edition annotation first part
Anthony Ly <anthonyly.com@gmail.com>
parents:
28
diff
changeset
|
323 |
function newAnnotation(dataAnnotation){ |
|
e3a17ec94cd8
edition annotation first part
Anthony Ly <anthonyly.com@gmail.com>
parents:
28
diff
changeset
|
324 |
var annotation = new IriSP.Model.Annotation(false, myProject); |
|
e3a17ec94cd8
edition annotation first part
Anthony Ly <anthonyly.com@gmail.com>
parents:
28
diff
changeset
|
325 |
annotation.setMedia(myMedia.id); |
|
e3a17ec94cd8
edition annotation first part
Anthony Ly <anthonyly.com@gmail.com>
parents:
28
diff
changeset
|
326 |
annotation.setBegin(dataAnnotation.begin); |
|
e3a17ec94cd8
edition annotation first part
Anthony Ly <anthonyly.com@gmail.com>
parents:
28
diff
changeset
|
327 |
annotation.setEnd(dataAnnotation.end); |
|
e3a17ec94cd8
edition annotation first part
Anthony Ly <anthonyly.com@gmail.com>
parents:
28
diff
changeset
|
328 |
annotation.title = dataAnnotation.title; |
|
e3a17ec94cd8
edition annotation first part
Anthony Ly <anthonyly.com@gmail.com>
parents:
28
diff
changeset
|
329 |
annotation.description = dataAnnotation.description; |
|
e3a17ec94cd8
edition annotation first part
Anthony Ly <anthonyly.com@gmail.com>
parents:
28
diff
changeset
|
330 |
annotation.type = dataAnnotation.type; |
|
e3a17ec94cd8
edition annotation first part
Anthony Ly <anthonyly.com@gmail.com>
parents:
28
diff
changeset
|
331 |
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
|
332 |
annotation.keywords = dataAnnotation.keywords; |
|
e3a17ec94cd8
edition annotation first part
Anthony Ly <anthonyly.com@gmail.com>
parents:
28
diff
changeset
|
333 |
|
|
e3a17ec94cd8
edition annotation first part
Anthony Ly <anthonyly.com@gmail.com>
parents:
28
diff
changeset
|
334 |
annotations.push(annotation); |
|
35
6eb0de10e9f8
delete / edit / new annotation head
Anthony Ly <anthonyly.com@gmail.com>
parents:
34
diff
changeset
|
335 |
|
|
6eb0de10e9f8
delete / edit / new annotation head
Anthony Ly <anthonyly.com@gmail.com>
parents:
34
diff
changeset
|
336 |
return annotation; |
|
34
e3a17ec94cd8
edition annotation first part
Anthony Ly <anthonyly.com@gmail.com>
parents:
28
diff
changeset
|
337 |
} |
|
e3a17ec94cd8
edition annotation first part
Anthony Ly <anthonyly.com@gmail.com>
parents:
28
diff
changeset
|
338 |
|
|
e3a17ec94cd8
edition annotation first part
Anthony Ly <anthonyly.com@gmail.com>
parents:
28
diff
changeset
|
339 |
function renderAnnotation(){ |
|
e3a17ec94cd8
edition annotation first part
Anthony Ly <anthonyly.com@gmail.com>
parents:
28
diff
changeset
|
340 |
var timeline = $('.timeline-annotations'), |
|
e3a17ec94cd8
edition annotation first part
Anthony Ly <anthonyly.com@gmail.com>
parents:
28
diff
changeset
|
341 |
wTimeline = timeline.width(), |
|
e3a17ec94cd8
edition annotation first part
Anthony Ly <anthonyly.com@gmail.com>
parents:
28
diff
changeset
|
342 |
annotationList = $('#list-annotations-rows'); |
|
e3a17ec94cd8
edition annotation first part
Anthony Ly <anthonyly.com@gmail.com>
parents:
28
diff
changeset
|
343 |
|
|
e3a17ec94cd8
edition annotation first part
Anthony Ly <anthonyly.com@gmail.com>
parents:
28
diff
changeset
|
344 |
annotations = _.sortBy(annotations, function(c){ |
|
e3a17ec94cd8
edition annotation first part
Anthony Ly <anthonyly.com@gmail.com>
parents:
28
diff
changeset
|
345 |
return c.begin; |
|
e3a17ec94cd8
edition annotation first part
Anthony Ly <anthonyly.com@gmail.com>
parents:
28
diff
changeset
|
346 |
}); |
|
e3a17ec94cd8
edition annotation first part
Anthony Ly <anthonyly.com@gmail.com>
parents:
28
diff
changeset
|
347 |
|
|
e3a17ec94cd8
edition annotation first part
Anthony Ly <anthonyly.com@gmail.com>
parents:
28
diff
changeset
|
348 |
timeline.empty(); |
|
e3a17ec94cd8
edition annotation first part
Anthony Ly <anthonyly.com@gmail.com>
parents:
28
diff
changeset
|
349 |
annotationList.empty(); |
|
e3a17ec94cd8
edition annotation first part
Anthony Ly <anthonyly.com@gmail.com>
parents:
28
diff
changeset
|
350 |
|
|
e3a17ec94cd8
edition annotation first part
Anthony Ly <anthonyly.com@gmail.com>
parents:
28
diff
changeset
|
351 |
$.each(annotations, function(k, v){ |
|
e3a17ec94cd8
edition annotation first part
Anthony Ly <anthonyly.com@gmail.com>
parents:
28
diff
changeset
|
352 |
|
|
e3a17ec94cd8
edition annotation first part
Anthony Ly <anthonyly.com@gmail.com>
parents:
28
diff
changeset
|
353 |
//timeline |
|
e3a17ec94cd8
edition annotation first part
Anthony Ly <anthonyly.com@gmail.com>
parents:
28
diff
changeset
|
354 |
var width = Math.floor(v.getDuration() * wTimeline / myMedia.duration), |
|
e3a17ec94cd8
edition annotation first part
Anthony Ly <anthonyly.com@gmail.com>
parents:
28
diff
changeset
|
355 |
left = Math.floor(v.begin * wTimeline / myMedia.duration), |
|
e3a17ec94cd8
edition annotation first part
Anthony Ly <anthonyly.com@gmail.com>
parents:
28
diff
changeset
|
356 |
segment = $('<div>').css({ |
|
e3a17ec94cd8
edition annotation first part
Anthony Ly <anthonyly.com@gmail.com>
parents:
28
diff
changeset
|
357 |
left : left, |
|
e3a17ec94cd8
edition annotation first part
Anthony Ly <anthonyly.com@gmail.com>
parents:
28
diff
changeset
|
358 |
width : width, |
|
e3a17ec94cd8
edition annotation first part
Anthony Ly <anthonyly.com@gmail.com>
parents:
28
diff
changeset
|
359 |
backgroundColor : v.color |
|
e3a17ec94cd8
edition annotation first part
Anthony Ly <anthonyly.com@gmail.com>
parents:
28
diff
changeset
|
360 |
}).addClass('annotation').attr('id', 'annotation-timeline-'+v.id); |
|
e3a17ec94cd8
edition annotation first part
Anthony Ly <anthonyly.com@gmail.com>
parents:
28
diff
changeset
|
361 |
|
|
e3a17ec94cd8
edition annotation first part
Anthony Ly <anthonyly.com@gmail.com>
parents:
28
diff
changeset
|
362 |
timeline.append(segment); |
|
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 |
//liste |
|
e3a17ec94cd8
edition annotation first part
Anthony Ly <anthonyly.com@gmail.com>
parents:
28
diff
changeset
|
365 |
$.get('template.html', function(templates){ |
|
e3a17ec94cd8
edition annotation first part
Anthony Ly <anthonyly.com@gmail.com>
parents:
28
diff
changeset
|
366 |
var tplAnnotationRow = $(templates).filter('#tpl-list-annotation-row').html(); |
|
e3a17ec94cd8
edition annotation first part
Anthony Ly <anthonyly.com@gmail.com>
parents:
28
diff
changeset
|
367 |
tplAnnotationRow = Mustache.render(tplAnnotationRow, v); |
|
e3a17ec94cd8
edition annotation first part
Anthony Ly <anthonyly.com@gmail.com>
parents:
28
diff
changeset
|
368 |
annotationList.append(tplAnnotationRow); |
|
e3a17ec94cd8
edition annotation first part
Anthony Ly <anthonyly.com@gmail.com>
parents:
28
diff
changeset
|
369 |
|
|
e3a17ec94cd8
edition annotation first part
Anthony Ly <anthonyly.com@gmail.com>
parents:
28
diff
changeset
|
370 |
}); |
|
e3a17ec94cd8
edition annotation first part
Anthony Ly <anthonyly.com@gmail.com>
parents:
28
diff
changeset
|
371 |
|
|
e3a17ec94cd8
edition annotation first part
Anthony Ly <anthonyly.com@gmail.com>
parents:
28
diff
changeset
|
372 |
}); |
|
e3a17ec94cd8
edition annotation first part
Anthony Ly <anthonyly.com@gmail.com>
parents:
28
diff
changeset
|
373 |
} |
| 22 | 374 |
|
| 6 | 375 |
//edit annotation |
376 |
$('#list-annotations').on('click', 'a.btn-edit-annotation', function(e){ |
|
377 |
e.preventDefault(); |
|
378 |
||
379 |
var idAnnotation = $(this).attr('data-id'); |
|
380 |
//si il est déjà ouvert |
|
|
34
e3a17ec94cd8
edition annotation first part
Anthony Ly <anthonyly.com@gmail.com>
parents:
28
diff
changeset
|
381 |
if($('#tab-annotation-'+idAnnotation).length){ |
|
e3a17ec94cd8
edition annotation first part
Anthony Ly <anthonyly.com@gmail.com>
parents:
28
diff
changeset
|
382 |
$('a[href=#tab-annotation-'+idAnnotation+']').tab('show'); |
| 6 | 383 |
}else{ |
|
34
e3a17ec94cd8
edition annotation first part
Anthony Ly <anthonyly.com@gmail.com>
parents:
28
diff
changeset
|
384 |
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
|
385 |
openTab(data.type, data); |
| 6 | 386 |
} |
387 |
}); |
|
388 |
||
|
34
e3a17ec94cd8
edition annotation first part
Anthony Ly <anthonyly.com@gmail.com>
parents:
28
diff
changeset
|
389 |
$('.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
|
390 |
var name = $(this).attr('name'), |
|
e3a17ec94cd8
edition annotation first part
Anthony Ly <anthonyly.com@gmail.com>
parents:
28
diff
changeset
|
391 |
value = $(this).val(); |
|
e3a17ec94cd8
edition annotation first part
Anthony Ly <anthonyly.com@gmail.com>
parents:
28
diff
changeset
|
392 |
currentAnnotation[name] = value; |
|
e3a17ec94cd8
edition annotation first part
Anthony Ly <anthonyly.com@gmail.com>
parents:
28
diff
changeset
|
393 |
if(name == 'title'){ |
|
e3a17ec94cd8
edition annotation first part
Anthony Ly <anthonyly.com@gmail.com>
parents:
28
diff
changeset
|
394 |
var idAnnotation = $(this).parents('form').attr('data-id'); |
|
e3a17ec94cd8
edition annotation first part
Anthony Ly <anthonyly.com@gmail.com>
parents:
28
diff
changeset
|
395 |
$('#onglet-title-'+idAnnotation).text(value); |
|
e3a17ec94cd8
edition annotation first part
Anthony Ly <anthonyly.com@gmail.com>
parents:
28
diff
changeset
|
396 |
} |
|
e3a17ec94cd8
edition annotation first part
Anthony Ly <anthonyly.com@gmail.com>
parents:
28
diff
changeset
|
397 |
}); |
|
e3a17ec94cd8
edition annotation first part
Anthony Ly <anthonyly.com@gmail.com>
parents:
28
diff
changeset
|
398 |
|
|
35
6eb0de10e9f8
delete / edit / new annotation head
Anthony Ly <anthonyly.com@gmail.com>
parents:
34
diff
changeset
|
399 |
//delete annotation |
|
6eb0de10e9f8
delete / edit / new annotation head
Anthony Ly <anthonyly.com@gmail.com>
parents:
34
diff
changeset
|
400 |
$(document).on('click','.btn-delete-annotation', function(e){ |
|
6eb0de10e9f8
delete / edit / new annotation head
Anthony Ly <anthonyly.com@gmail.com>
parents:
34
diff
changeset
|
401 |
e.preventDefault(); |
|
6eb0de10e9f8
delete / edit / new annotation head
Anthony Ly <anthonyly.com@gmail.com>
parents:
34
diff
changeset
|
402 |
|
|
6eb0de10e9f8
delete / edit / new annotation head
Anthony Ly <anthonyly.com@gmail.com>
parents:
34
diff
changeset
|
403 |
var idAnnotation = $(this).attr('data-id'); |
|
6eb0de10e9f8
delete / edit / new annotation head
Anthony Ly <anthonyly.com@gmail.com>
parents:
34
diff
changeset
|
404 |
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
|
405 |
closeTab(idAnnotation); |
|
6eb0de10e9f8
delete / edit / new annotation head
Anthony Ly <anthonyly.com@gmail.com>
parents:
34
diff
changeset
|
406 |
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
|
407 |
renderAnnotation(); |
|
6eb0de10e9f8
delete / edit / new annotation head
Anthony Ly <anthonyly.com@gmail.com>
parents:
34
diff
changeset
|
408 |
|
|
6eb0de10e9f8
delete / edit / new annotation head
Anthony Ly <anthonyly.com@gmail.com>
parents:
34
diff
changeset
|
409 |
}); |
|
6eb0de10e9f8
delete / edit / new annotation head
Anthony Ly <anthonyly.com@gmail.com>
parents:
34
diff
changeset
|
410 |
|
| 9 | 411 |
//tab |
|
34
e3a17ec94cd8
edition annotation first part
Anthony Ly <anthonyly.com@gmail.com>
parents:
28
diff
changeset
|
412 |
$('#onglet-annotations').on('click', 'a', function(e){ |
| 9 | 413 |
e.preventDefault(); |
414 |
$(this).tab('show'); |
|
415 |
}); |
|
416 |
||
417 |
//ouvrir tab |
|
418 |
$(document).on('click', '.open-tab', function(e){ |
|
419 |
e.preventDefault(); |
|
420 |
var type = $(this).attr('data-type'); |
|
|
34
e3a17ec94cd8
edition annotation first part
Anthony Ly <anthonyly.com@gmail.com>
parents:
28
diff
changeset
|
421 |
openTab(type); |
| 9 | 422 |
}); |
423 |
||
|
34
e3a17ec94cd8
edition annotation first part
Anthony Ly <anthonyly.com@gmail.com>
parents:
28
diff
changeset
|
424 |
function openTab(type, data){ |
|
e3a17ec94cd8
edition annotation first part
Anthony Ly <anthonyly.com@gmail.com>
parents:
28
diff
changeset
|
425 |
|
|
35
6eb0de10e9f8
delete / edit / new annotation head
Anthony Ly <anthonyly.com@gmail.com>
parents:
34
diff
changeset
|
426 |
var dataView; |
|
34
e3a17ec94cd8
edition annotation first part
Anthony Ly <anthonyly.com@gmail.com>
parents:
28
diff
changeset
|
427 |
if(_.isUndefined(data)){//nouveau |
|
35
6eb0de10e9f8
delete / edit / new annotation head
Anthony Ly <anthonyly.com@gmail.com>
parents:
34
diff
changeset
|
428 |
var dataAnnotation = { |
|
6eb0de10e9f8
delete / edit / new annotation head
Anthony Ly <anthonyly.com@gmail.com>
parents:
34
diff
changeset
|
429 |
title : 'Nouveau', |
|
6eb0de10e9f8
delete / edit / new annotation head
Anthony Ly <anthonyly.com@gmail.com>
parents:
34
diff
changeset
|
430 |
begin : 60 * 1000, |
|
6eb0de10e9f8
delete / edit / new annotation head
Anthony Ly <anthonyly.com@gmail.com>
parents:
34
diff
changeset
|
431 |
end : 60 * 1000 * 2, |
|
6eb0de10e9f8
delete / edit / new annotation head
Anthony Ly <anthonyly.com@gmail.com>
parents:
34
diff
changeset
|
432 |
description : 'description', |
|
6eb0de10e9f8
delete / edit / new annotation head
Anthony Ly <anthonyly.com@gmail.com>
parents:
34
diff
changeset
|
433 |
type : type, |
|
6eb0de10e9f8
delete / edit / new annotation head
Anthony Ly <anthonyly.com@gmail.com>
parents:
34
diff
changeset
|
434 |
keywords : [] |
|
6eb0de10e9f8
delete / edit / new annotation head
Anthony Ly <anthonyly.com@gmail.com>
parents:
34
diff
changeset
|
435 |
}; |
|
6eb0de10e9f8
delete / edit / new annotation head
Anthony Ly <anthonyly.com@gmail.com>
parents:
34
diff
changeset
|
436 |
dataView = newAnnotation(dataAnnotation); |
|
6eb0de10e9f8
delete / edit / new annotation head
Anthony Ly <anthonyly.com@gmail.com>
parents:
34
diff
changeset
|
437 |
renderAnnotation(); |
|
34
e3a17ec94cd8
edition annotation first part
Anthony Ly <anthonyly.com@gmail.com>
parents:
28
diff
changeset
|
438 |
}else{//édition |
|
e3a17ec94cd8
edition annotation first part
Anthony Ly <anthonyly.com@gmail.com>
parents:
28
diff
changeset
|
439 |
dataView = data; |
|
e3a17ec94cd8
edition annotation first part
Anthony Ly <anthonyly.com@gmail.com>
parents:
28
diff
changeset
|
440 |
} |
| 6 | 441 |
|
|
34
e3a17ec94cd8
edition annotation first part
Anthony Ly <anthonyly.com@gmail.com>
parents:
28
diff
changeset
|
442 |
var idAnnotation = dataView.id, |
|
e3a17ec94cd8
edition annotation first part
Anthony Ly <anthonyly.com@gmail.com>
parents:
28
diff
changeset
|
443 |
tabContent = $('<div class="tab-pane" id="tab-annotation-'+idAnnotation+'"></div>'), |
| 6 | 444 |
iconTab; |
445 |
||
|
34
e3a17ec94cd8
edition annotation first part
Anthony Ly <anthonyly.com@gmail.com>
parents:
28
diff
changeset
|
446 |
currentAnnotation = _.find(annotations, function(c){ return c.id == idAnnotation; }); |
| 6 | 447 |
|
448 |
$.get('template.html', function(templates){ |
|
449 |
//head commun à tous |
|
450 |
var tplHead = $(templates).filter('#tpl-head').html(); |
|
|
34
e3a17ec94cd8
edition annotation first part
Anthony Ly <anthonyly.com@gmail.com>
parents:
28
diff
changeset
|
451 |
var output = Mustache.render(tplHead, dataView); |
| 6 | 452 |
$(tabContent).append(output); |
|
34
e3a17ec94cd8
edition annotation first part
Anthony Ly <anthonyly.com@gmail.com>
parents:
28
diff
changeset
|
453 |
$(tabContent).find(".slider-duration").slider(configSlider(dataView)); |
|
e3a17ec94cd8
edition annotation first part
Anthony Ly <anthonyly.com@gmail.com>
parents:
28
diff
changeset
|
454 |
$(tabContent).find('.tag-it').tagit(tagitParam); |
| 6 | 455 |
//type |
|
34
e3a17ec94cd8
edition annotation first part
Anthony Ly <anthonyly.com@gmail.com>
parents:
28
diff
changeset
|
456 |
var viewType = {id : idAnnotation}; |
| 6 | 457 |
var tpl = $(templates).filter('#tpl-'+type).html(); |
458 |
tpl = Mustache.render(tpl, viewType); |
|
459 |
$(tabContent).append(tpl); |
|
460 |
$('.tab-content').append(tabContent); |
|
461 |
||
462 |
//particularité selon type |
|
463 |
switch(type){ |
|
|
35
6eb0de10e9f8
delete / edit / new annotation head
Anthony Ly <anthonyly.com@gmail.com>
parents:
34
diff
changeset
|
464 |
case 'son': iconTab = 'volume-up'; |
|
6eb0de10e9f8
delete / edit / new annotation head
Anthony Ly <anthonyly.com@gmail.com>
parents:
34
diff
changeset
|
465 |
break; |
| 6 | 466 |
case 'video': iconTab = 'film'; |
467 |
break; |
|
468 |
case 'text': |
|
469 |
iconTab = 'align-left'; |
|
470 |
$(tabContent).find('.wysiwyg').cleditor(wysiwygConfig); |
|
471 |
break; |
|
472 |
case 'html': iconTab = 'link'; |
|
473 |
break; |
|
474 |
case 'diaporama': iconTab = 'picture'; |
|
475 |
$(tabContent).find('.number-spin').spin(spinParam); |
|
476 |
$(tabContent).find('.ui-sortable').sortable({ |
|
477 |
stop : function(event, ui){ |
|
478 |
disabledBtnSortable($(this)); |
|
479 |
} |
|
480 |
}); |
|
481 |
break; |
|
482 |
} |
|
|
34
e3a17ec94cd8
edition annotation first part
Anthony Ly <anthonyly.com@gmail.com>
parents:
28
diff
changeset
|
483 |
|
|
e3a17ec94cd8
edition annotation first part
Anthony Ly <anthonyly.com@gmail.com>
parents:
28
diff
changeset
|
484 |
dataView.iconTab = iconTab; |
|
e3a17ec94cd8
edition annotation first part
Anthony Ly <anthonyly.com@gmail.com>
parents:
28
diff
changeset
|
485 |
var tplOnglet = $(templates).filter('#tpl-onglet').html(); |
|
e3a17ec94cd8
edition annotation first part
Anthony Ly <anthonyly.com@gmail.com>
parents:
28
diff
changeset
|
486 |
var onglet = Mustache.render(tplOnglet, dataView); |
|
e3a17ec94cd8
edition annotation first part
Anthony Ly <anthonyly.com@gmail.com>
parents:
28
diff
changeset
|
487 |
|
|
e3a17ec94cd8
edition annotation first part
Anthony Ly <anthonyly.com@gmail.com>
parents:
28
diff
changeset
|
488 |
$(".nav-tabs li:last-child").after(onglet); |
|
e3a17ec94cd8
edition annotation first part
Anthony Ly <anthonyly.com@gmail.com>
parents:
28
diff
changeset
|
489 |
$('a[href=#tab-annotation-'+idAnnotation+']').tab('show'); |
| 6 | 490 |
}); |
|
34
e3a17ec94cd8
edition annotation first part
Anthony Ly <anthonyly.com@gmail.com>
parents:
28
diff
changeset
|
491 |
}//openTab() |
|
e3a17ec94cd8
edition annotation first part
Anthony Ly <anthonyly.com@gmail.com>
parents:
28
diff
changeset
|
492 |
|
|
e3a17ec94cd8
edition annotation first part
Anthony Ly <anthonyly.com@gmail.com>
parents:
28
diff
changeset
|
493 |
//définit currentAnnotation quand la tab s'ouvre |
|
e3a17ec94cd8
edition annotation first part
Anthony Ly <anthonyly.com@gmail.com>
parents:
28
diff
changeset
|
494 |
$('#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
|
495 |
var idAnnotation = $(e.target).attr('data-id'); |
|
e3a17ec94cd8
edition annotation first part
Anthony Ly <anthonyly.com@gmail.com>
parents:
28
diff
changeset
|
496 |
currentAnnotation = _.find(annotations, function(c){ return c.id == idAnnotation; }); |
|
e3a17ec94cd8
edition annotation first part
Anthony Ly <anthonyly.com@gmail.com>
parents:
28
diff
changeset
|
497 |
}); |
|
e3a17ec94cd8
edition annotation first part
Anthony Ly <anthonyly.com@gmail.com>
parents:
28
diff
changeset
|
498 |
|
|
e3a17ec94cd8
edition annotation first part
Anthony Ly <anthonyly.com@gmail.com>
parents:
28
diff
changeset
|
499 |
//rafraichit annotations au retour sur la liste |
|
e3a17ec94cd8
edition annotation first part
Anthony Ly <anthonyly.com@gmail.com>
parents:
28
diff
changeset
|
500 |
$('#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
|
501 |
renderAnnotation(); |
|
e3a17ec94cd8
edition annotation first part
Anthony Ly <anthonyly.com@gmail.com>
parents:
28
diff
changeset
|
502 |
}); |
| 6 | 503 |
|
| 9 | 504 |
//fermer tab |
|
34
e3a17ec94cd8
edition annotation first part
Anthony Ly <anthonyly.com@gmail.com>
parents:
28
diff
changeset
|
505 |
$('#onglet-annotations').on('click', 'span.close-tab', function(e){ |
| 9 | 506 |
e.preventDefault();e.stopPropagation(); |
|
34
e3a17ec94cd8
edition annotation first part
Anthony Ly <anthonyly.com@gmail.com>
parents:
28
diff
changeset
|
507 |
var idAnnotation = $(this).parents('a').attr('data-id'); |
|
e3a17ec94cd8
edition annotation first part
Anthony Ly <anthonyly.com@gmail.com>
parents:
28
diff
changeset
|
508 |
closeTab(idAnnotation); |
| 9 | 509 |
}); |
510 |
||
|
34
e3a17ec94cd8
edition annotation first part
Anthony Ly <anthonyly.com@gmail.com>
parents:
28
diff
changeset
|
511 |
$('.tab-content').on('click', '.btn-save-annotation', function(e){ |
|
e3a17ec94cd8
edition annotation first part
Anthony Ly <anthonyly.com@gmail.com>
parents:
28
diff
changeset
|
512 |
e.preventDefault(); |
|
e3a17ec94cd8
edition annotation first part
Anthony Ly <anthonyly.com@gmail.com>
parents:
28
diff
changeset
|
513 |
var idAnnotation = $(this).attr('data-id'); |
|
e3a17ec94cd8
edition annotation first part
Anthony Ly <anthonyly.com@gmail.com>
parents:
28
diff
changeset
|
514 |
closeTab(idAnnotation); |
|
e3a17ec94cd8
edition annotation first part
Anthony Ly <anthonyly.com@gmail.com>
parents:
28
diff
changeset
|
515 |
}); |
|
e3a17ec94cd8
edition annotation first part
Anthony Ly <anthonyly.com@gmail.com>
parents:
28
diff
changeset
|
516 |
|
|
e3a17ec94cd8
edition annotation first part
Anthony Ly <anthonyly.com@gmail.com>
parents:
28
diff
changeset
|
517 |
function closeTab(idAnnotation){ |
|
e3a17ec94cd8
edition annotation first part
Anthony Ly <anthonyly.com@gmail.com>
parents:
28
diff
changeset
|
518 |
$('#onglet-'+idAnnotation).remove(); |
|
e3a17ec94cd8
edition annotation first part
Anthony Ly <anthonyly.com@gmail.com>
parents:
28
diff
changeset
|
519 |
$('.tab-content #tab-annotation-'+idAnnotation).remove(); |
|
e3a17ec94cd8
edition annotation first part
Anthony Ly <anthonyly.com@gmail.com>
parents:
28
diff
changeset
|
520 |
$('#tab-list-annotation').tab('show'); |
|
e3a17ec94cd8
edition annotation first part
Anthony Ly <anthonyly.com@gmail.com>
parents:
28
diff
changeset
|
521 |
} |
| 9 | 522 |
|
| 6 | 523 |
//diaporama |
| 9 | 524 |
function addImageToDiaporama(diaporama){ |
| 6 | 525 |
$.get('template.html', function(templates){ |
526 |
var tplDiapo = $(templates).filter('#tpl-diaporama-row').html(), |
|
527 |
uniqId = 'id' + (new Date()).getTime(), |
|
528 |
viewDiapo = { ridid : uniqId}; |
|
529 |
tplDiapo = Mustache.render(tplDiapo, viewDiapo); |
|
530 |
diaporama.append(tplDiapo); |
|
531 |
disabledBtnSortable(diaporama); |
|
532 |
}); |
|
533 |
}; |
|
534 |
||
| 9 | 535 |
//bouton up / down |
| 6 | 536 |
$(document).on('click', '.ui-sortable .btn-sort', function(e){ |
537 |
e.preventDefault(); |
|
538 |
var row = $(this).parents('tr.row-image-diaporama'), |
|
539 |
listDiaporama = $(this).parents('.list-image-diaporama'); |
|
540 |
||
541 |
if($(this).hasClass('down')) |
|
542 |
row.insertAfter(row.next()); |
|
543 |
else if($(this).hasClass('up')) |
|
544 |
row.insertBefore(row.prev()); |
|
545 |
||
546 |
disabledBtnSortable(listDiaporama); |
|
547 |
}); |
|
548 |
||
549 |
function disabledBtnSortable(listDiaporama){ |
|
550 |
listDiaporama.find('.btn-sort.disabled').removeClass('disabled'); |
|
551 |
listDiaporama.find('tr.row-image-diaporama:first-child').find('.btn-sort.up').addClass('disabled'); |
|
552 |
listDiaporama.find('tr.row-image-diaporama:last-child').find('.btn-sort.down').addClass('disabled'); |
|
553 |
} |
|
554 |
||
| 9 | 555 |
|
| 6 | 556 |
|
|
34
e3a17ec94cd8
edition annotation first part
Anthony Ly <anthonyly.com@gmail.com>
parents:
28
diff
changeset
|
557 |
|
| 6 | 558 |
|
559 |
//annotation html |
|
560 |
$('.tab-content').on('click', '.btn-html-apercu', function(e){ |
|
561 |
e.preventDefault(); |
|
562 |
||
563 |
var apercuWrap = $(this).parents('.edit-annotation-html').find('.html-apercu'), |
|
564 |
htmlTextarea = $(this).parents('.edit-annotation-html').find('textarea'); |
|
565 |
||
566 |
apercuWrap.empty().html(htmlTextarea.val()); |
|
567 |
}); |
|
568 |
||
569 |
//annotation > diaporama (spin) |
|
| 16 | 570 |
|
| 6 | 571 |
|
|
34
e3a17ec94cd8
edition annotation first part
Anthony Ly <anthonyly.com@gmail.com>
parents:
28
diff
changeset
|
572 |
//################ config |
|
e3a17ec94cd8
edition annotation first part
Anthony Ly <anthonyly.com@gmail.com>
parents:
28
diff
changeset
|
573 |
|
|
e3a17ec94cd8
edition annotation first part
Anthony Ly <anthonyly.com@gmail.com>
parents:
28
diff
changeset
|
574 |
//tagit |
|
e3a17ec94cd8
edition annotation first part
Anthony Ly <anthonyly.com@gmail.com>
parents:
28
diff
changeset
|
575 |
function onTagItChange(e, ui) { |
|
e3a17ec94cd8
edition annotation first part
Anthony Ly <anthonyly.com@gmail.com>
parents:
28
diff
changeset
|
576 |
var tagitType = $(this).attr('data-type'), |
|
e3a17ec94cd8
edition annotation first part
Anthony Ly <anthonyly.com@gmail.com>
parents:
28
diff
changeset
|
577 |
value = $(this).val(); |
|
e3a17ec94cd8
edition annotation first part
Anthony Ly <anthonyly.com@gmail.com>
parents:
28
diff
changeset
|
578 |
|
|
e3a17ec94cd8
edition annotation first part
Anthony Ly <anthonyly.com@gmail.com>
parents:
28
diff
changeset
|
579 |
if(tagitType == 'chapter'){ |
|
e3a17ec94cd8
edition annotation first part
Anthony Ly <anthonyly.com@gmail.com>
parents:
28
diff
changeset
|
580 |
var idChapter = $(this).parents('form').attr('data-chapter-id'); |
|
e3a17ec94cd8
edition annotation first part
Anthony Ly <anthonyly.com@gmail.com>
parents:
28
diff
changeset
|
581 |
currentChapter.keywords = value.split(','); |
|
e3a17ec94cd8
edition annotation first part
Anthony Ly <anthonyly.com@gmail.com>
parents:
28
diff
changeset
|
582 |
$('#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
|
583 |
}else{ |
|
e3a17ec94cd8
edition annotation first part
Anthony Ly <anthonyly.com@gmail.com>
parents:
28
diff
changeset
|
584 |
currentAnnotation.keywords = value.split(','); |
|
e3a17ec94cd8
edition annotation first part
Anthony Ly <anthonyly.com@gmail.com>
parents:
28
diff
changeset
|
585 |
} |
|
e3a17ec94cd8
edition annotation first part
Anthony Ly <anthonyly.com@gmail.com>
parents:
28
diff
changeset
|
586 |
|
|
e3a17ec94cd8
edition annotation first part
Anthony Ly <anthonyly.com@gmail.com>
parents:
28
diff
changeset
|
587 |
} |
|
e3a17ec94cd8
edition annotation first part
Anthony Ly <anthonyly.com@gmail.com>
parents:
28
diff
changeset
|
588 |
|
|
e3a17ec94cd8
edition annotation first part
Anthony Ly <anthonyly.com@gmail.com>
parents:
28
diff
changeset
|
589 |
var tagitParam = { |
|
e3a17ec94cd8
edition annotation first part
Anthony Ly <anthonyly.com@gmail.com>
parents:
28
diff
changeset
|
590 |
afterTagRemoved : onTagItChange, |
|
e3a17ec94cd8
edition annotation first part
Anthony Ly <anthonyly.com@gmail.com>
parents:
28
diff
changeset
|
591 |
afterTagAdded : onTagItChange |
|
e3a17ec94cd8
edition annotation first part
Anthony Ly <anthonyly.com@gmail.com>
parents:
28
diff
changeset
|
592 |
} |
|
e3a17ec94cd8
edition annotation first part
Anthony Ly <anthonyly.com@gmail.com>
parents:
28
diff
changeset
|
593 |
|
| 6 | 594 |
//CLEditor annotation > text (wysiwyg) |
595 |
//http://premiumsoftware.net/cleditor/docs/GettingStarted.html#optionalParameters |
|
596 |
var wysiwygConfig = { |
|
597 |
width: 456, |
|
598 |
height: 250, |
|
599 |
controls: "bold italic underline strikethrough | font size " + |
|
600 |
"style | color highlight removeformat | bullets numbering | outdent ", |
|
601 |
fonts: "Arial,Arial Black,Comic Sans MS,Courier New,Narrow,Garamond," + |
|
602 |
"Georgia,Impact,Sans Serif,Serif,Tahoma,Trebuchet MS,Verdana", |
|
603 |
sizes: "1,2,3,4,5,6,7", |
|
604 |
styles: [["Paragraph", "<p>"], ["Header 1", "<h1>"], ["Header 2", "<h2>"], |
|
605 |
["Header 3", "<h3>"], ["Header 4","<h4>"], ["Header 5","<h5>"], |
|
606 |
["Header 6","<h6>"]], |
|
607 |
docType: '<!DOCTYPE HTML>', |
|
608 |
bodyStyle: "margin:0; font-family: 'Helvetica Neue',​Helvetica,​Arial,​sans-serif;" |
|
609 |
}; |
|
610 |
||
611 |
//slider |
|
|
34
e3a17ec94cd8
edition annotation first part
Anthony Ly <anthonyly.com@gmail.com>
parents:
28
diff
changeset
|
612 |
function configSlider(data){ |
|
e3a17ec94cd8
edition annotation first part
Anthony Ly <anthonyly.com@gmail.com>
parents:
28
diff
changeset
|
613 |
|
|
e3a17ec94cd8
edition annotation first part
Anthony Ly <anthonyly.com@gmail.com>
parents:
28
diff
changeset
|
614 |
return { |
|
e3a17ec94cd8
edition annotation first part
Anthony Ly <anthonyly.com@gmail.com>
parents:
28
diff
changeset
|
615 |
range: true, |
|
e3a17ec94cd8
edition annotation first part
Anthony Ly <anthonyly.com@gmail.com>
parents:
28
diff
changeset
|
616 |
values: [ data.begin.milliseconds, data.end.milliseconds ], |
|
e3a17ec94cd8
edition annotation first part
Anthony Ly <anthonyly.com@gmail.com>
parents:
28
diff
changeset
|
617 |
min: 0, |
|
e3a17ec94cd8
edition annotation first part
Anthony Ly <anthonyly.com@gmail.com>
parents:
28
diff
changeset
|
618 |
max: myMedia.duration.milliseconds, |
|
e3a17ec94cd8
edition annotation first part
Anthony Ly <anthonyly.com@gmail.com>
parents:
28
diff
changeset
|
619 |
slide: function( event, ui ) { |
|
e3a17ec94cd8
edition annotation first part
Anthony Ly <anthonyly.com@gmail.com>
parents:
28
diff
changeset
|
620 |
|
|
e3a17ec94cd8
edition annotation first part
Anthony Ly <anthonyly.com@gmail.com>
parents:
28
diff
changeset
|
621 |
data.setBegin(ui.values[0]); |
|
e3a17ec94cd8
edition annotation first part
Anthony Ly <anthonyly.com@gmail.com>
parents:
28
diff
changeset
|
622 |
data.setEnd(ui.values[1]); |
| 6 | 623 |
|
|
34
e3a17ec94cd8
edition annotation first part
Anthony Ly <anthonyly.com@gmail.com>
parents:
28
diff
changeset
|
624 |
var idSlider = $(this).attr('data-id'), |
|
e3a17ec94cd8
edition annotation first part
Anthony Ly <anthonyly.com@gmail.com>
parents:
28
diff
changeset
|
625 |
wTimeline = $('.timeline-annotations').width(), |
|
e3a17ec94cd8
edition annotation first part
Anthony Ly <anthonyly.com@gmail.com>
parents:
28
diff
changeset
|
626 |
annotationTimeline = $('#annotation-timeline-'+ data.id), |
|
e3a17ec94cd8
edition annotation first part
Anthony Ly <anthonyly.com@gmail.com>
parents:
28
diff
changeset
|
627 |
width = Math.floor(data.getDuration() * wTimeline / myMedia.duration), |
|
e3a17ec94cd8
edition annotation first part
Anthony Ly <anthonyly.com@gmail.com>
parents:
28
diff
changeset
|
628 |
left = Math.floor(data.begin * wTimeline / myMedia.duration); |
|
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 |
$( '#'+ idSlider +'-begin' ).html(data.begin.toString()); |
|
e3a17ec94cd8
edition annotation first part
Anthony Ly <anthonyly.com@gmail.com>
parents:
28
diff
changeset
|
631 |
$( '#'+ idSlider +'-duration' ).html(data.getDuration().toString()); |
|
e3a17ec94cd8
edition annotation first part
Anthony Ly <anthonyly.com@gmail.com>
parents:
28
diff
changeset
|
632 |
$( '#'+ idSlider +'-end' ).html(data.end.toString()); |
| 6 | 633 |
|
|
34
e3a17ec94cd8
edition annotation first part
Anthony Ly <anthonyly.com@gmail.com>
parents:
28
diff
changeset
|
634 |
annotationTimeline.css({ |
|
e3a17ec94cd8
edition annotation first part
Anthony Ly <anthonyly.com@gmail.com>
parents:
28
diff
changeset
|
635 |
left : left, |
|
e3a17ec94cd8
edition annotation first part
Anthony Ly <anthonyly.com@gmail.com>
parents:
28
diff
changeset
|
636 |
width :width |
|
e3a17ec94cd8
edition annotation first part
Anthony Ly <anthonyly.com@gmail.com>
parents:
28
diff
changeset
|
637 |
}); |
|
e3a17ec94cd8
edition annotation first part
Anthony Ly <anthonyly.com@gmail.com>
parents:
28
diff
changeset
|
638 |
|
|
e3a17ec94cd8
edition annotation first part
Anthony Ly <anthonyly.com@gmail.com>
parents:
28
diff
changeset
|
639 |
} |
|
e3a17ec94cd8
edition annotation first part
Anthony Ly <anthonyly.com@gmail.com>
parents:
28
diff
changeset
|
640 |
}; |
|
e3a17ec94cd8
edition annotation first part
Anthony Ly <anthonyly.com@gmail.com>
parents:
28
diff
changeset
|
641 |
|
|
e3a17ec94cd8
edition annotation first part
Anthony Ly <anthonyly.com@gmail.com>
parents:
28
diff
changeset
|
642 |
} |
| 9 | 643 |
//milliseconds To 12h12m12s |
| 6 | 644 |
function millisecondsToString(milliseconds) { |
645 |
var oneHour = 3600000; |
|
646 |
var oneMinute = 60000; |
|
647 |
var oneSecond = 1000; |
|
648 |
var seconds = 0; |
|
649 |
var minutes = 0; |
|
650 |
var hours = 0; |
|
651 |
var result; |
|
652 |
||
653 |
if (milliseconds >= oneHour) { |
|
654 |
hours = Math.floor(milliseconds / oneHour); |
|
655 |
} |
|
656 |
||
657 |
milliseconds = hours > 0 ? (milliseconds - hours * oneHour) : milliseconds; |
|
658 |
||
659 |
if (milliseconds >= oneMinute) { |
|
660 |
minutes = Math.floor(milliseconds / oneMinute); |
|
661 |
} |
|
662 |
||
663 |
milliseconds = minutes > 0 ? (milliseconds - minutes * oneMinute) : milliseconds; |
|
664 |
||
665 |
if (milliseconds >= oneSecond) { |
|
666 |
seconds = Math.floor(milliseconds / oneSecond); |
|
667 |
} |
|
668 |
||
669 |
milliseconds = seconds > 0 ? (milliseconds - seconds * oneSecond) : milliseconds; |
|
670 |
||
671 |
if (hours > 0) { |
|
672 |
result = (hours > 9 ? hours : "0" + hours) + "h"; |
|
673 |
} else { |
|
674 |
result = ""; |
|
675 |
} |
|
676 |
||
677 |
if (minutes > 0) { |
|
678 |
result += (minutes > 9 ? minutes : "0" + minutes) + "m"; |
|
679 |
} else { |
|
680 |
result += "00m"; |
|
681 |
} |
|
682 |
||
683 |
if (seconds > 0) { |
|
684 |
result += (seconds > 9 ? seconds : "0" + seconds) + "s"; |
|
685 |
} else { |
|
686 |
result += "00s"; |
|
687 |
} |
|
688 |
||
689 |
return result; |
|
690 |
} |
|
| 9 | 691 |
|
692 |
//test |
|
693 |
$(".wysiwyg").cleditor(wysiwygConfig); |
|
694 |
||
695 |
$('.number-spin').spin(spinParam); |
|
696 |
||
697 |
disabledBtnSortable($('.ui-sortable')) |
|
698 |
$('.ui-sortable').sortable({ |
|
699 |
stop : function(event, ui){ |
|
700 |
disabledBtnSortable($(this)); |
|
701 |
} |
|
702 |
}); |
|
703 |
||
704 |
$('.slider-duration').slider(configSlider); |
|
705 |
||
|
34
e3a17ec94cd8
edition annotation first part
Anthony Ly <anthonyly.com@gmail.com>
parents:
28
diff
changeset
|
706 |
|
|
e3a17ec94cd8
edition annotation first part
Anthony Ly <anthonyly.com@gmail.com>
parents:
28
diff
changeset
|
707 |
|
|
e3a17ec94cd8
edition annotation first part
Anthony Ly <anthonyly.com@gmail.com>
parents:
28
diff
changeset
|
708 |
|
| 9 | 709 |
|
|
21
abd04f346dbe
delete row on enter key press in modal
Anthony Ly <anthonyly.com@gmail.com>
parents:
18
diff
changeset
|
710 |
$(".tag-it").tagit(); |
|
abd04f346dbe
delete row on enter key press in modal
Anthony Ly <anthonyly.com@gmail.com>
parents:
18
diff
changeset
|
711 |
|
| 16 | 712 |
});//ready |