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