|
9
|
1 |
$(function(){ |
|
6
|
2 |
|
|
|
3 |
var global = { |
|
|
4 |
diaporama : null, |
|
|
5 |
idAnnotation : null |
|
16
|
6 |
}, |
|
|
7 |
chapitres = {}, |
|
|
8 |
annotations = {}; |
|
|
9 |
|
|
|
10 |
//onLoad |
|
|
11 |
myProject.onLoad(function() { |
|
|
12 |
|
|
|
13 |
$(".project-title").text(myProject.title); |
|
|
14 |
|
|
|
15 |
myMedia = myProject.getCurrentMedia(); |
|
|
16 |
|
|
|
17 |
IriSP.htmlPlayer( |
|
|
18 |
myMedia, |
|
|
19 |
$(".main-video"), |
|
|
20 |
{ |
|
|
21 |
width: 460, |
|
|
22 |
height: 345, |
|
|
23 |
controls: true, |
|
|
24 |
autostart: true |
|
|
25 |
} |
|
|
26 |
); |
|
|
27 |
|
|
|
28 |
myMedia.on("timeupdate", function(t) { |
|
|
29 |
|
|
|
30 |
//curseur chapitre |
|
|
31 |
var pos = $(".chapitre-cut-wrap").width() * t / myMedia.duration, |
|
|
32 |
wContainer = $('.chapitre-cut-wrap').width(), |
|
|
33 |
btnCutChapter = $('.btn-cut-chapter'), |
|
|
34 |
wBtnCutChapter = btnCutChapter.outerWidth(); |
|
|
35 |
|
|
|
36 |
$(".indicateur-chapter").css("left",pos); |
|
|
37 |
if(pos+wBtnCutChapter>wContainer){ |
|
|
38 |
btnCutChapter.css("left",(pos - wBtnCutChapter)); |
|
|
39 |
}else{ |
|
|
40 |
btnCutChapter.css("left",pos); |
|
|
41 |
} |
|
|
42 |
|
|
|
43 |
}); |
|
|
44 |
|
|
|
45 |
});//myProject.onLoad |
|
|
46 |
|
|
6
|
47 |
|
|
|
48 |
//modal |
|
9
|
49 |
$(document).on('click', 'a.open-modal', function(e){ |
|
|
50 |
var diaporama = $(this).attr('data-diaporama'), |
|
|
51 |
idAnnotation = $(this).attr('data-id'); |
|
|
52 |
|
|
|
53 |
if(diaporama !== undefined){ |
|
|
54 |
global.diaporama = diaporama; |
|
|
55 |
} |
|
|
56 |
if(idAnnotation !== undefined){ |
|
|
57 |
global.idAnnotation = idAnnotation; |
|
|
58 |
} |
|
|
59 |
}) |
|
6
|
60 |
//edition image |
|
|
61 |
$('.popup').on('change', '#media-type-select', function(e){ |
|
|
62 |
var typeImage = $(this).val(); |
|
|
63 |
$('.input-image-url, .input-image-upload').hide(); |
|
|
64 |
$('.input-image-'+typeImage).show(); |
|
|
65 |
}); |
|
|
66 |
//bibliotheque |
|
|
67 |
//video |
|
|
68 |
$('.popup').on('click', '.bibliotheque-video a', function(e){ |
|
|
69 |
e.preventDefault(); |
|
|
70 |
$('.popup').modal('hide'); |
|
|
71 |
$.get('template.html', function(templates){ |
|
|
72 |
var videoWrap = $('#'+global.idAnnotation).find('.annotation-video-content'), |
|
|
73 |
tplVideo = $(templates).filter('#tpl-video-row').html(); |
|
|
74 |
videoWrap.empty().append(tplVideo); |
|
|
75 |
}); |
|
|
76 |
|
|
|
77 |
}); |
|
|
78 |
//image |
|
|
79 |
$('.popup').on('click', '.bibliotheque-image a', function(e){ |
|
|
80 |
e.preventDefault(); |
|
|
81 |
var listDiaporama = $('#'+global.diaporama); |
|
|
82 |
addImageToDiaporama(listDiaporama); |
|
|
83 |
$('.popup').modal('hide'); |
|
|
84 |
}); |
|
|
85 |
|
|
|
86 |
$(document).on('click','.btn-delete', function(e){ |
|
|
87 |
e.preventDefault(); |
|
|
88 |
//si c'est une annotation et que la tab est ouverte, on la ferme |
|
|
89 |
var type = $(this).attr('data-type'); |
|
|
90 |
if(type == 'annotation'){ |
|
|
91 |
var idAnnotation = $(this).attr('data-id'); |
|
|
92 |
$('a[href=#annotation-'+idAnnotation+']').closest('li').remove(); |
|
|
93 |
$('.tab-content #annotation'+idAnnotation).remove(); |
|
|
94 |
$('#tab-list-annotation').tab('show'); |
|
|
95 |
} |
|
|
96 |
}); |
|
|
97 |
|
|
|
98 |
//confirmation suppression |
|
|
99 |
$("#modal-confirm").on('click', '#btn-delete-modal', function(e){ |
|
9
|
100 |
|
|
6
|
101 |
}); |
|
|
102 |
|
|
|
103 |
//title-editor |
|
|
104 |
$('.project-title-editor ._popover').bind('click',function(e){e.preventDefault()}); |
|
|
105 |
$('.project-title-editor ._popover').popover({ |
|
|
106 |
html : true, |
|
|
107 |
content : function(){ |
|
|
108 |
var previousValue = $('.project-title').text(), |
|
|
109 |
formInput = |
|
|
110 |
'<form action="#" class="project-title-editor-form">'+ |
|
|
111 |
'<input type="text" class="project-title-editor-input" value="'+previousValue+'">'+ |
|
|
112 |
'</form>'; |
|
|
113 |
return formInput; |
|
|
114 |
} |
|
|
115 |
}); |
|
|
116 |
|
|
|
117 |
$('body').on('click', function (e) { |
|
|
118 |
$('._popover').each(function () { |
|
|
119 |
if (!$(this).is(e.target) && $(this).has(e.target).length === 0 && $('.popover').has(e.target).length === 0) { |
|
|
120 |
$(this).popover('hide'); |
|
|
121 |
} |
|
|
122 |
}); |
|
|
123 |
}); |
|
|
124 |
|
|
|
125 |
$('body').on('submit', '.project-title-editor-form', function(e){ |
|
|
126 |
e.preventDefault(); |
|
|
127 |
$('._popover').popover('hide'); |
|
|
128 |
}); |
|
|
129 |
|
|
|
130 |
$(document).on('keyup', '.project-title-editor-input', function() { |
|
|
131 |
$('.project-title').html($(this).val()); |
|
|
132 |
}); |
|
9
|
133 |
|
|
6
|
134 |
//chapter |
|
|
135 |
$('.list-chapter-wrap').on('click', '.edit-chapter', function(e){ |
|
|
136 |
e.preventDefault(); |
|
|
137 |
var viewChapter = { |
|
|
138 |
titre : 'titre du chapitre', |
|
|
139 |
tags : 'tag 1, tag 2, tag 3', |
|
|
140 |
description : 'lorem ipsum' |
|
|
141 |
} |
|
|
142 |
|
|
|
143 |
$.get('template.html', function(templates){ |
|
|
144 |
var tpl = $(templates).filter('#tpl-chapter-edit').html(); |
|
|
145 |
var tpl = Mustache.render(tpl, viewChapter); |
|
|
146 |
$('.form-chapter-edit').empty().append(tpl); |
|
|
147 |
}); |
|
|
148 |
}); |
|
|
149 |
//nouveau chapitre |
|
|
150 |
$('.chapter-widget').on('click', '.btn-cut-chapter', function(e){ |
|
|
151 |
e.preventDefault(); |
|
16
|
152 |
|
|
6
|
153 |
var uniqId = 'id' + (new Date()).getTime(); |
|
|
154 |
$.get('template.html', function(templates){ |
|
|
155 |
var viewChapterRow = { |
|
|
156 |
id : uniqId |
|
|
157 |
}; |
|
|
158 |
var tpl = $(templates).filter('#tpl-chapter-row').html(); |
|
|
159 |
var tpl = Mustache.render(tpl, viewChapterRow); |
|
|
160 |
$('.list-chapter-rows-wrap').append(tpl); |
|
|
161 |
}); |
|
|
162 |
}); |
|
|
163 |
|
|
|
164 |
|
|
|
165 |
//edit annotation |
|
|
166 |
$('#list-annotations').on('click', 'a.btn-edit-annotation', function(e){ |
|
|
167 |
e.preventDefault(); |
|
|
168 |
|
|
|
169 |
var idAnnotation = $(this).attr('data-id'); |
|
|
170 |
//si il est déjà ouvert |
|
|
171 |
if($('#annotation-'+idAnnotation).length){ |
|
|
172 |
$('a[href=#annotation-'+idAnnotation+']').tab('show'); |
|
|
173 |
}else{ |
|
|
174 |
var typeAnnotation = $(this).attr('data-type'), |
|
|
175 |
data = {id:idAnnotation}; |
|
|
176 |
openNewTab(typeAnnotation, data); |
|
|
177 |
} |
|
|
178 |
}); |
|
|
179 |
|
|
9
|
180 |
//tab |
|
|
181 |
$('#annotation-tab').on('click', 'a', function(e){ |
|
|
182 |
e.preventDefault(); |
|
|
183 |
$(this).tab('show'); |
|
|
184 |
}); |
|
|
185 |
|
|
|
186 |
//ouvrir tab |
|
|
187 |
$(document).on('click', '.open-tab', function(e){ |
|
|
188 |
e.preventDefault(); |
|
|
189 |
var type = $(this).attr('data-type'); |
|
|
190 |
var data = $(this).attr('data-data'); // à définir |
|
|
191 |
openNewTab(type); |
|
|
192 |
}); |
|
|
193 |
|
|
6
|
194 |
function openNewTab(type, data){ |
|
|
195 |
|
|
|
196 |
var uniqId = 'id' + (new Date()).getTime(), |
|
|
197 |
idAnnotation = (data !== undefined) ? data.id : uniqId, |
|
|
198 |
tabContent = $('<div class="tab-pane" id="annotation-'+idAnnotation+'"></div>'), |
|
|
199 |
iconTab; |
|
|
200 |
|
|
|
201 |
|
|
|
202 |
$.get('template.html', function(templates){ |
|
|
203 |
//head commun à tous |
|
|
204 |
var view = { |
|
|
205 |
titre : "un titre mustache", |
|
|
206 |
id : uniqId |
|
|
207 |
}; |
|
|
208 |
var tplHead = $(templates).filter('#tpl-head').html(); |
|
|
209 |
var output = Mustache.render(tplHead, view); |
|
|
210 |
$(tabContent).append(output); |
|
|
211 |
$(tabContent).find(".slider-duration").slider(configSlider); |
|
|
212 |
|
|
|
213 |
//type |
|
|
214 |
var viewType = {id : uniqId}; |
|
|
215 |
var tpl = $(templates).filter('#tpl-'+type).html(); |
|
|
216 |
tpl = Mustache.render(tpl, viewType); |
|
|
217 |
$(tabContent).append(tpl); |
|
|
218 |
$('.tab-content').append(tabContent); |
|
|
219 |
|
|
|
220 |
//particularité selon type |
|
|
221 |
switch(type){ |
|
|
222 |
case 'video': iconTab = 'film'; |
|
|
223 |
break; |
|
|
224 |
case 'text': |
|
|
225 |
iconTab = 'align-left'; |
|
|
226 |
$(tabContent).find('.wysiwyg').cleditor(wysiwygConfig); |
|
|
227 |
break; |
|
|
228 |
case 'html': iconTab = 'link'; |
|
|
229 |
break; |
|
|
230 |
case 'diaporama': iconTab = 'picture'; |
|
|
231 |
$(tabContent).find('.number-spin').spin(spinParam); |
|
|
232 |
$(tabContent).find('.ui-sortable').sortable({ |
|
|
233 |
stop : function(event, ui){ |
|
|
234 |
disabledBtnSortable($(this)); |
|
|
235 |
} |
|
|
236 |
}); |
|
|
237 |
break; |
|
|
238 |
} |
|
|
239 |
$(".nav-tabs li:last-child").after('<li><a href="#annotation-'+idAnnotation+'"><i class="icon-'+iconTab+'"></i> New <span class="close-tab">×</span></a></li>'); |
|
|
240 |
$('a[href=#annotation-'+idAnnotation+']').tab('show'); |
|
|
241 |
}); |
|
|
242 |
}//openNewTab() |
|
|
243 |
|
|
9
|
244 |
//fermer tab |
|
|
245 |
$('#annotation-tab').on('click', 'span.close-tab', function(e){ |
|
|
246 |
e.preventDefault();e.stopPropagation(); |
|
|
247 |
var idTab = $(this).parents('a').attr('href'); |
|
|
248 |
$(this).closest('li').remove(); |
|
|
249 |
$('.tab-content '+idTab).remove(); |
|
|
250 |
$('#tab-list-annotation').tab('show'); |
|
|
251 |
}); |
|
|
252 |
|
|
|
253 |
|
|
6
|
254 |
//diaporama |
|
9
|
255 |
function addImageToDiaporama(diaporama){ |
|
6
|
256 |
$.get('template.html', function(templates){ |
|
|
257 |
var tplDiapo = $(templates).filter('#tpl-diaporama-row').html(), |
|
|
258 |
uniqId = 'id' + (new Date()).getTime(), |
|
|
259 |
viewDiapo = { ridid : uniqId}; |
|
|
260 |
tplDiapo = Mustache.render(tplDiapo, viewDiapo); |
|
|
261 |
diaporama.append(tplDiapo); |
|
|
262 |
disabledBtnSortable(diaporama); |
|
|
263 |
}); |
|
|
264 |
}; |
|
|
265 |
|
|
9
|
266 |
//bouton up / down |
|
6
|
267 |
$(document).on('click', '.ui-sortable .btn-sort', function(e){ |
|
|
268 |
e.preventDefault(); |
|
|
269 |
var row = $(this).parents('tr.row-image-diaporama'), |
|
|
270 |
listDiaporama = $(this).parents('.list-image-diaporama'); |
|
|
271 |
|
|
|
272 |
if($(this).hasClass('down')) |
|
|
273 |
row.insertAfter(row.next()); |
|
|
274 |
else if($(this).hasClass('up')) |
|
|
275 |
row.insertBefore(row.prev()); |
|
|
276 |
|
|
|
277 |
disabledBtnSortable(listDiaporama); |
|
|
278 |
}); |
|
|
279 |
|
|
|
280 |
function disabledBtnSortable(listDiaporama){ |
|
|
281 |
listDiaporama.find('.btn-sort.disabled').removeClass('disabled'); |
|
|
282 |
listDiaporama.find('tr.row-image-diaporama:first-child').find('.btn-sort.up').addClass('disabled'); |
|
|
283 |
listDiaporama.find('tr.row-image-diaporama:last-child').find('.btn-sort.down').addClass('disabled'); |
|
|
284 |
} |
|
|
285 |
|
|
9
|
286 |
|
|
6
|
287 |
|
|
|
288 |
//sauvegarder annotation |
|
|
289 |
$('.tab-content').on('click', '.btn-save-annotation', function(e){ |
|
|
290 |
e.preventDefault(); |
|
|
291 |
var idAnnotation = $(this).attr('data-id'); |
|
|
292 |
}); |
|
|
293 |
|
|
|
294 |
//annotation html |
|
|
295 |
$('.tab-content').on('click', '.btn-html-apercu', function(e){ |
|
|
296 |
e.preventDefault(); |
|
|
297 |
|
|
|
298 |
var apercuWrap = $(this).parents('.edit-annotation-html').find('.html-apercu'), |
|
|
299 |
htmlTextarea = $(this).parents('.edit-annotation-html').find('textarea'); |
|
|
300 |
|
|
|
301 |
apercuWrap.empty().html(htmlTextarea.val()); |
|
|
302 |
}); |
|
|
303 |
|
|
|
304 |
//annotation > diaporama (spin) |
|
16
|
305 |
|
|
6
|
306 |
|
|
|
307 |
//config |
|
|
308 |
//CLEditor annotation > text (wysiwyg) |
|
|
309 |
//http://premiumsoftware.net/cleditor/docs/GettingStarted.html#optionalParameters |
|
|
310 |
var wysiwygConfig = { |
|
|
311 |
width: 456, |
|
|
312 |
height: 250, |
|
|
313 |
controls: "bold italic underline strikethrough | font size " + |
|
|
314 |
"style | color highlight removeformat | bullets numbering | outdent ", |
|
|
315 |
fonts: "Arial,Arial Black,Comic Sans MS,Courier New,Narrow,Garamond," + |
|
|
316 |
"Georgia,Impact,Sans Serif,Serif,Tahoma,Trebuchet MS,Verdana", |
|
|
317 |
sizes: "1,2,3,4,5,6,7", |
|
|
318 |
styles: [["Paragraph", "<p>"], ["Header 1", "<h1>"], ["Header 2", "<h2>"], |
|
|
319 |
["Header 3", "<h3>"], ["Header 4","<h4>"], ["Header 5","<h5>"], |
|
|
320 |
["Header 6","<h6>"]], |
|
|
321 |
docType: '<!DOCTYPE HTML>', |
|
|
322 |
bodyStyle: "margin:0; font-family: 'Helvetica Neue',​Helvetica,​Arial,​sans-serif;" |
|
|
323 |
}; |
|
|
324 |
|
|
|
325 |
//slider |
|
|
326 |
var configSlider = { |
|
|
327 |
range: true, |
|
|
328 |
values: [ 0, 1*60*1000 ], |
|
|
329 |
min: 0, |
|
|
330 |
max: 10*60*1000, |
|
|
331 |
slide: function( event, ui ) { |
|
|
332 |
|
|
|
333 |
var debutString = millisecondsToString(ui.values[0]); |
|
|
334 |
var endString = millisecondsToString(ui.values[1]); |
|
|
335 |
var durationString = millisecondsToString(ui.values[1] - ui.values[0]); |
|
|
336 |
|
|
|
337 |
var idSlider = $(this).attr('data-id'); |
|
|
338 |
|
|
|
339 |
$( '#'+ idSlider +'-begin' ).html(debutString); |
|
|
340 |
$( '#'+ idSlider +'-duration' ).html(durationString); |
|
|
341 |
$( '#'+ idSlider +'-end' ).html(endString); |
|
|
342 |
|
|
|
343 |
} |
|
|
344 |
}; |
|
|
345 |
|
|
9
|
346 |
//milliseconds To 12h12m12s |
|
6
|
347 |
function millisecondsToString(milliseconds) { |
|
|
348 |
var oneHour = 3600000; |
|
|
349 |
var oneMinute = 60000; |
|
|
350 |
var oneSecond = 1000; |
|
|
351 |
var seconds = 0; |
|
|
352 |
var minutes = 0; |
|
|
353 |
var hours = 0; |
|
|
354 |
var result; |
|
|
355 |
|
|
|
356 |
if (milliseconds >= oneHour) { |
|
|
357 |
hours = Math.floor(milliseconds / oneHour); |
|
|
358 |
} |
|
|
359 |
|
|
|
360 |
milliseconds = hours > 0 ? (milliseconds - hours * oneHour) : milliseconds; |
|
|
361 |
|
|
|
362 |
if (milliseconds >= oneMinute) { |
|
|
363 |
minutes = Math.floor(milliseconds / oneMinute); |
|
|
364 |
} |
|
|
365 |
|
|
|
366 |
milliseconds = minutes > 0 ? (milliseconds - minutes * oneMinute) : milliseconds; |
|
|
367 |
|
|
|
368 |
if (milliseconds >= oneSecond) { |
|
|
369 |
seconds = Math.floor(milliseconds / oneSecond); |
|
|
370 |
} |
|
|
371 |
|
|
|
372 |
milliseconds = seconds > 0 ? (milliseconds - seconds * oneSecond) : milliseconds; |
|
|
373 |
|
|
|
374 |
if (hours > 0) { |
|
|
375 |
result = (hours > 9 ? hours : "0" + hours) + "h"; |
|
|
376 |
} else { |
|
|
377 |
result = ""; |
|
|
378 |
} |
|
|
379 |
|
|
|
380 |
if (minutes > 0) { |
|
|
381 |
result += (minutes > 9 ? minutes : "0" + minutes) + "m"; |
|
|
382 |
} else { |
|
|
383 |
result += "00m"; |
|
|
384 |
} |
|
|
385 |
|
|
|
386 |
if (seconds > 0) { |
|
|
387 |
result += (seconds > 9 ? seconds : "0" + seconds) + "s"; |
|
|
388 |
} else { |
|
|
389 |
result += "00s"; |
|
|
390 |
} |
|
|
391 |
|
|
|
392 |
return result; |
|
|
393 |
} |
|
9
|
394 |
|
|
|
395 |
//test |
|
|
396 |
$(".wysiwyg").cleditor(wysiwygConfig); |
|
|
397 |
|
|
|
398 |
$('.number-spin').spin(spinParam); |
|
|
399 |
|
|
|
400 |
disabledBtnSortable($('.ui-sortable')) |
|
|
401 |
$('.ui-sortable').sortable({ |
|
|
402 |
stop : function(event, ui){ |
|
|
403 |
disabledBtnSortable($(this)); |
|
|
404 |
} |
|
|
405 |
}); |
|
|
406 |
|
|
|
407 |
$('.slider-duration').slider(configSlider); |
|
|
408 |
|
|
|
409 |
$('#annotation-tab a:last-child').tab('show'); |
|
|
410 |
|
|
16
|
411 |
});//ready |