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