-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathBBB.js
1215 lines (1077 loc) · 49.5 KB
/
BBB.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* BBB v0.3
* By Steven Weerdenburg and Kevin Lasconia
* Last Modification: 12/09/2010
*/
var bbb = (function(){
var _chapters = []; // Array of Chapters/Bookmarks
var _recommended = []; // Array of recommended videos
var _video;
var _stats; // Statistics object
var _vid = 0,
_toc = 0; // id to store the table of contents and video player
var _hasMadeToc = false;
var _hasTocChanged = false;
var _curr = -1;
var currChap = 0;
var _playSeq = 0;
var canVideo = !!document.createElement('video').play;
var endPoint = {
root: "",
service: "",
fullUri: function() { return endPoint.root+endPoint.service; }
};
if (typeof XMLHttpRequest == "undefined") {
XMLHttpRequest = function () {
try { return new ActiveXObject("Msxml2.XMLHTTP.6.0"); } catch (e) {}
try { return new ActiveXObject("Msxml2.XMLHTTP.3.0"); } catch (f) {}
try { return new ActiveXObject("Msxml2.XMLHTTP"); } catch (g) {}
// Impossible to support XHR
throw new Error("This browser does not support XMLHttpRequest.");
};
}
function addEvent(owner, event, func) {
if (owner.addEventListener)
owner.addEventListener(event, func, false); // Follow standards if possible
else if (owner.attachEvent)
owner.attachEvent(event, func); // IE
else
owner["on"+event] = func; // No DOM 2 support, go old school DOM 0
}
return {
// A module for local storage (Cookies and HTML 5 Local Storage)
storage: (function() {
return {
setCookie: function (name, value, expDays){
var sDate = "";
if (!name.length)
throw "name can't be empty";
else {
if (expDays) {
var oDate = new Date();
oDate.setTime(oDate.getTime() + (days * 24 * 60 * 60 * 1000));
sDate = "; expires=" + date.toGMTString();
}
document.cookie = name + "=" + value + sDate;
}
},
// return string
getCookie: function(name){
if (document.cookie.length > 0) {
var start = document.cookie.indexOf(name + "=");
if (start !== -1) {
start += name.length + 1;
var end = document.cookie.indexOf(";", start);
if (end === -1)
end = document.cookie.length;
return unescape(document.cookie.substring(start, end));
}
}
return "";
}
}
})(),
// A Bookmark object for the manager to work with
Bookmark: function(params) {
var params = params || {};
var title = params["title"] || "";
var description = params["description"] || "";
var src = params["src"] || "";
var startTime = parseFloat(params["startTime"] || 0);
var endTime = parseFloat(params["endTime"] || 0);
if (startTime < 0 || endTime < 0)
throw "Start and end times must be positive!";
else if (startTime == endTime)
throw "Start and end times can not be the same!";
else if (startTime < endTime) {
startTime = startTime;
endTime = endTime;
} else {
endTime = startTime;
startTime = endTime;
}
this.getTitle = function() { return title; },
this.getDescription= function() { return description; },
this.getSrc = function() { return src; },
this.getStartTime = function() { return startTime; },
this.getEndTime = function() { return endTime; },
this.toString = function(){
return "Source: " + src + "\nTitle: " + title + "\nDescription: " + description + "\nStart Time: " + startTime + "\nEnd Time: " + endTime;
},
this.toJSON = function(){
return '{ "src": "' + src + '", "title": "' + title + '", "description": "' + description + '", "startTime": ' + startTime + ', "endTime": ' + endTime + ' }';
}
},
// A Video object for the manager to work with
Video: function (params) {
var id = 0;
var title = "";
var description = "";
var duration = "";
var src = "";
var rating = "";
var thumbnailSrc = "";
var tags = [];
if (params) {
id = params['id'];
title = params['title'];
description = params['description'];
duration = params['duration'];
src = params['src'];
rating = params['rating'];
thumbnailSrc = params['thumbnailSrc'];
}
return {
getId: function () {
return id;
},
getTitle: function () {
return title;
},
getDescription: function () {
return description;
},
getDuration: function () {
return duration;
},
getSrc: function () {
return src;
},
getRating: function () {
return rating;
},
getThumbnailSrc: function () {
return thumbnailSrc;
}
}
},
// A Statistics object for the manager to work with
Statistics: function (params) {
var ip = 0;
var onLoad = false;
var _25 = false;
var _50 = false;
var _75 = false;
var _90 = false;
var _100 = false;
var cc_on = false;
var cc_off = false;
var ad_on = false;
var ad_off = false;
if (params) {
ip = params['ip'];
onLoad = params['onLoad'];
_25 = params['_25'];
_50 = params['_50'];
_75 = params['_75'];
_90 = params['_90'];
_100 = params['_100'];
//cc_on = params['cc_on'];
//cc_off = params['cc_off'];
//ad_on = params['ad_on'];
//ad_off = params['ad_off'];
}
return {
getIp: function () {
return ip;
},
getOnLoad: function () {
return onLoad;
},
get25: function () {
return _25;
},
get50: function () {
return _50;
},
get75: function () {
return _75;
},
get90: function () {
return _90;
},
get100: function () {
return _100;
}
}
},
fetchVideos: function () {
// Eventually be replaced by server calls
bbb.addRecVideo({
id: 1,
title: 'Green Screen',
description: 'Demo',
duration: '0:10',
src: 'http://matrix.senecac.on.ca/~kclascon/DPS909/d4/video.ogv',
rating: 'G',
thumbnailSrc: 'video.jpg',
tags: ['test']
});
bbb.addRecVideo({
id: 2,
title: 'Big Buck Bunny',
description: 'An animated video',
duration: '0:32',
src: 'http://upload.wikimedia.org/wikipedia/commons/7/75/Big_Buck_Bunny_Trailer_400p.ogg',
rating: 'G',
thumbnailSrc: 'bunny.jpg',
tags: ['test']
});
bbb.addRecVideo({
id: 3,
title: 'Indy',
description: 'Cars on the track',
duration: '0:24',
src: 'http://jbuckley.ca/~hoops/indy.ogv',
rating: 'G',
thumbnailSrc: 'indy.jpg',
tags: ['test']
});
bbb.addRecVideo({
id: 4,
title: 'Dire Wolf Fanclub',
description: '???',
duration: '2:28',
src: 'http://jbuckley.ca/~hoops/DireWolfFanClub.ogv',
rating: 'G',
thumbnailSrc: 'dwfc.jpg',
tags: ['test']
});
},
// (Re-)initialize all values except internal element pointers
// (Re-)initialize all values
init: function(params){
params = params || {};
if (canVideo) {
this.setVideoId(params.playerId);
this.setTOCId(params.tocId);
// Default search directory "BBB" for callPage
// Careful, cross-origin issues may result if specified
endPoint.root = params.remoteServer || location.href.substring(0, location.href.lastIndexOf("/BBB/")+5);
endPoint.service = params.chapterStorage || "";
this.fetchVideos();
this.fetchChapters(endPoint.fullUri());
if (params.statistics)
bbb.trackStatistics();
if (params.watermark)
bbb.displayWatermark();
if (params.formDivId) {
bbb.popcornGenerator.setupWhenReady(params.formDivId);
}
}
},
setupWhenReady: function(params) {
var self = this;
addEvent(document, "DOMContentLoaded", function() {
self.init(params);
});
},
fetchChapters: function(endPoint) {
var request = new XMLHttpRequest();
_chapters = [];
_hasMadeToc = false;
_hasTocChanged = true; // In event TOC has been output before calling init, this will redraw table
_curr = -1;
request.open("GET",endPoint);
request.onreadystatechange = function() {
var arr = [];
var i=0, numItems = 0;
if (request.readyState === 4) {
if (request.status === 200) {
arr = JSON.parse(request.responseText);
numItems = arr.length;
for(i=0; i<numItems; i++) {
bbb.addChapter(arr[i]);
}
bbb.printTOC();
bbb.onReady();
} else if (request.status === 404) {
bbb.onError("Could not find bookmark server");
} else if (request.status === 405) {
bbb.onError("Permission denied to bookmark server");
}
}
};
request.send();
},
// Add a chapter
addChapter: function(_c){
_chapters.push(new bbb.Bookmark(_c));
_hasTocChanged = true;
},
// Add a chapter
removeChapter: function (_idx) {
_chapters.splice(_idx, 1);
_hasTocChanged = true;
},
// Chapters module
chapters: (function() {
var tempIn= 0;
var tempOut= 0;
return {
setStartEnd: function(timeToSet, isStart) {
if (isStart)
tempIn = timeToSet;
else
tempOut = timeToSet;
},
getTempIn: function() {
return tempIn;
},
getTempOut: function() {
return tempOut;
},
// obj contains title, description, source
// Compliments tempIn and tempOut to produce all information for a chapter
makeChapter: function(obj) {
obj.startTime = tempIn;
obj.endTime = tempOut;
// May throw error if params are invalid
bbb.addChapter(obj, true);
tempIn = 0;
tempOut = 0;
}
}
})(),
// Add a video
addRecVideo: function (_v) {
_recommended.push(bbb.Video(_v));
},
// Set initial video
setVideo: function (_v) {
_video = (bbb.Video(_v));
},
// Get initial video
getVideo: function () {
return _video;
},
// Output video info
printVideoInfo: function (_c) {
if (_c === true) {
var info = document.createElement('div');
info.setAttribute('id', 'vidInfo');
info.innerHTML = '<b>Video Information</b><br/>Title: ' + _video.getTitle() + '<br/>Description: ' + _video.getDescription() + '<br/>Duration: ' + _video.getDuration() + ' sec' + '<br/>Rating: ' + _video.getRating();
document.body.appendChild(info);
}
else {
var existing = document.getElementById('vidInfo');
document.body.removeChild(existing);
}
},
// Set statistics
setStatistics: function (_s) {
_stats = (bbb.Statistics(_s));
},
// Output video stats
printVideoStats: function () {
var vidStats = document.createElement('div');
vidStats.setAttribute('id', 'vidStats');
vidStats.innerHTML = '<b>Stats</b><br/>IP: ' + _stats.getIp() + '<br/>Reached 25%: ' + _stats.get25() + '<br/>Reached 50%: ' + _stats.get50() + '<br/>Reached 75%: ' + _stats.get75() + '<br/>Reached 90%: ' + _stats.get90() + '<br/>Reached 100%: ' + _stats.get100();
document.body.appendChild(vidStats);
},
// Set the table of contents (<table>) and player (<video>) elements based on id
// Only set them if the currently stored element is null or has a differing id
setTOCId: function (_id) {
if (_id && (!this._toc || this._toc.id !== _id)) { // Valid id given and No id supplied yet or different id supplied
this._toc = document.getElementById(_id);
_hasTocChanged = true;
}
},
setVideoId: function (_id) {
if (canVideo) {
if (_id && (!this._vid || this._vid.id !== _id)) { // valid id given and No id supplied yet or different id supplied
// Store locally for easy reference for event setup
this._vid = document.getElementById(_id);
}
}
},
// output the TOC
printTOC: function () {
if (canVideo) {
if (this._toc) {
var tr = 0;
var srcElem = 0;
var th = 0;
if (!_hasMadeToc) {
tr = this._toc.insertRow(0);
// DOM approach for tables (IE doesn't like tr.innerHTML)
th = document.createElement('th');
th.innerHTML = "Chapter Title";
tr.appendChild(th);
th = document.createElement('th');
th.innerHTML = "Description";
tr.appendChild(th);
th = document.createElement('th');
th.innerHTML = "Start Time";
tr.appendChild(th);
th = document.createElement('th');
th.innerHTML = "End Time";
tr.appendChild(th);
th = document.createElement('th');
th.innerHTML = 'Delete';
tr.appendChild(th);
_hasMadeToc = true;
}
if (_hasTocChanged) {
// Delete existing rows
for (var i = this._toc.rows.length - 1; i > 0; i--)
this._toc.deleteRow(i);
for (var i = _chapters.length - 1; i >= 0; i--) {
tr = this._toc.insertRow(1);
srcElem = document.createElement('a');
var item = _chapters[i];
srcElem.href = 'javascript:bbb.playChapter(' + i + ');';
srcElem.innerHTML = item.getTitle();
tr.insertCell(0).appendChild(srcElem);
tr.insertCell(1).appendChild(document.createTextNode(item.getDescription()));
tr.insertCell(2).appendChild(document.createTextNode(item.getStartTime().toFixed(2)));
tr.insertCell(3).appendChild(document.createTextNode(item.getEndTime().toFixed(2)));
tr.insertCell(4).innerHTML = '<input type="checkbox" onclick="bbb.removeChapter(' + i + '); bbb.printTOC();" />';
}
tr = this._toc.insertRow(1);
tr.colspan = 4;
srcElem = document.createElement('a');
srcElem.href = 'javascript:bbb.playChapter(0, 1);';
srcElem.innerHTML = 'Play All';
tr.insertCell(0).appendChild(srcElem);
_hasTocChanged = false;
}
}
}
},
playChapter: function (idx, sequential) {
if (canVideo) {
if (idx !== _curr && idx >= 0 && idx < _chapters.length) {
var vid = this._vid;
bbb.popcornGenerator.setActiveVideo(vid);
_curr = idx;
currChap = _chapters[_curr];
bbb.onChangeVideo(currChap);
vid.addEventListener('loadedmetadata', function () {
vid.currentTime = currChap.getStartTime();
}, true);
vid.addEventListener('canplay', function () {
vid.play();
}, true);
vid.addEventListener('timeupdate', function () {
if (vid.currentTime >= currChap.getEndTime()) {
if (sequential) {
bbb.playChapter(idx + 1, sequential);
}
else {
vid.pause();
}
}
}, true);
vid.src = currChap.getSrc();
vid.load();
vid.play();
}
}
},
trackStatistics: function (ip) {
var stats = {
ip: 0,
onLoad: false,
_25: false,
_50: false,
_75: false,
_90: false,
_100: false,
cc_on: false,
cc_off: false,
ad_on: false,
ad_off: false
};
var vid = this._vid;
var duration = vid.duration;
$.getJSON("http://jsonip.appspot.com?callback=?", function (data) {
stats.ip = data.ip;
});
var durationListener = function () {
if (parseInt(vid.currentTime, 10) === parseInt(duration * 0.25, 10)) {
vid.removeEventListener('timeupdate', durationListener, false);
stats._25 = true;
}
else if (parseInt(vid.currentTime, 10) === parseInt(duration * 0.50, 10)) {
vid.removeEventListener('timeupdate', durationListener, false);
stats._50 = true;
}
else if (parseInt(vid.currentTime, 10) === parseInt(duration * 0.75, 10)) {
vid.removeEventListener('timeupdate', durationListener, false);
stats._75 = true;
}
else if (parseInt(vid.currentTime, 10) === parseInt(duration * 0.90, 10)) {
vid.removeEventListener('timeupdate', durationListener, false);
stats._90 = true;
}
vid.addEventListener('timeupdate', durationListener, false);
}
var endListener = function () {
stats._100 = true;
//Debugging purposes
alert('[Statistics]\nIP: ' + stats.ip + '\n25%: ' + stats._25 + '\n50%: ' + stats._50 + '\n75%: ' + stats._75 + '\n90%: ' + stats._90 + '\n100%: ' + stats._100);
//Add in cc and add stuff later
bbb.setStatistics({
ip: stats.ip,
_25: stats._25,
_50: stats._50,
_75: stats._75,
_90: stats._90,
_100: stats._100
});
var s = document.getElementById('vidStats');
if (s) {
document.body.removeChild(s);
}
//bbb.printVideoStats();
if (_stats) {
_stats = null;
}
bbb.displayRecommendedVideos();
}
vid.addEventListener('timeupdate', durationListener, false);
vid.addEventListener('ended', endListener, false);
},
// Stub method to send stats to BBB server
sendStatistics: function () {
// Probably convert statistics object into JSON and send it
},
// Displays rec'd videos
displayRecommendedVideos: function () {
var numVids = _recommended.length;
var i;
var recCont = document.createElement('div');
recCont.setAttribute('id', 'container');
recCont.style.position = "absolute";
document.body.appendChild(recCont);
var cont = document.getElementById('container');
for (i = 0; i < numVids; ++i) {
// Generate thumbnails
var image = document.createElement('img');
image.src = _recommended[i].getThumbnailSrc();
image.style.width = 70 + 'px';
image.style.height = 70 + 'px';
cont.appendChild(image);
// Generate title and duration links that will play the video
var info = document.createElement('div');
info.href = 'javascript:bbb.test();';
info.innerHTML = '<a href="javascript:bbb.playVideo(' + i + ');">' + _recommended[i].getTitle() + ' - ' + _recommended[i].getDuration(); + '</a>';
cont.appendChild(info);
}
},
// Will play a video using an index from an array of videos
// Will need to refactor to support tags to retrieve related videos
playVideo: function (idx) {
var vid = this._vid;
vid.src = _recommended[idx].getSrc();
vid.load();
vid.play();
var cont = document.getElementById('container');
document.body.removeChild(cont);
_video = _recommended[idx];
//This is a hack, fix later
bbb.printVideoInfo(false);
bbb.printVideoInfo(true);
},
displayWatermark: function (src, opacity, alpha) {
//Try and clean up code later :(
var vid = this._vid;
// Position of video player
var videoTop = parseInt(vid.style.top);
var videoLeft = parseInt(vid.style.left);
// Create div element
var watermarkDiv = document.createElement('div');
// Set div attributes
watermarkDiv.setAttribute('id', 'watermark');
watermarkDiv.className = 'watermark';
watermarkDiv.style.position = 'absolute';
watermarkDiv.style.left = videoLeft + 5 + 'px';
watermarkDiv.style.top = videoTop + 5 + 'px';
// Width and height will be hard-coded for now, will re-factor later
watermarkDiv.style.width = 150 + 'px';
watermarkDiv.style.height = 70 + 'px';
// If image source is not specificed, default image will be used
if (!src) {
watermarkDiv.style.backgroundImage = 'url("watermark.png")';
}
else {
watermarkDiv.style.backgroundImage = 'url("' + src + '")';
}
watermarkDiv.style.backgroundRepeat = "no-repeat";
// Arbitrary zIndex value to ensure watermark is above video player
watermarkDiv.style.zIndex = 100;
watermarkDiv.style.opacity = 0.4;
var alpha = 40;
watermarkDiv.style.filter = "alpha(opacity=" + alpha + ")";
document.body.appendChild(watermarkDiv);
},
popcornGenerator: (function() {
var SERVER = "popcornServer.php"; // Should be const, var for IE support
var doc = document;
var formMod = "", recMod = "", current = "", timeDisplay = "";
var currentIn = 0, currentOut = 0;
var vid = 0;
var isQuirk;
try {
doc.createElement('<input type="text">'); // Will not throw IE 5-8
isQuirk = true;
} catch (e) {
isQuirk = false;
}
// Factory of command object generators \\
// ------------------------------------ \\
var types = {
videotag: (function() {
var txtTag = makeInput("text", "txtVideoTag");
return {
outputHTML: function() {
clearChildren(formMod);
showTimelineEntry('inthisvideo');
recMod.style.display = "none";
formMod.appendChild(bindLabel(txtTag, 'Tag: '));
//formMod.innerHTML = 'Note: <input id="footText" name="footText" type="text" /><br />';
},
buildManifest: function() {
var timelineEntry = new TimelineEntry();
return {
manifestCat: '',
timelineCat: 'resources',
manifestXML: '',
timelineXML: '<videotag in="'+timelineEntry["in"]+'" out="'+timelineEntry.out+'" target="'+timelineEntry.target+'">'+txtTag.value+'</videotag>'
};
}
}
})(),
footnote: (function() {
var txtNote = makeInput("text", "footText");
return {
outputHTML: function() {
clearChildren(formMod);
showTimelineEntry('footnotediv');
recMod.style.display = "none";
formMod.appendChild(bindLabel(txtNote, 'Note: '));
//formMod.innerHTML = 'Note: <input id="footText" name="footText" type="text" /><br />';
},
buildManifest: function() {
var timelineEntry = new TimelineEntry();
return {
manifestCat: '',
timelineCat: 'footnotes',
manifestXML: '',
timelineXML: '<footnote in="'+timelineEntry["in"]+'" out="'+timelineEntry.out+'" target="'+timelineEntry.target+'">'+txtNote.value+'</footnote>'
};
}
}
})(),
lastfm: (function() {
var txtArtist = makeInput("text", "lastFMArtist");
return {
outputHTML: function() {
clearChildren(formMod);
showTimelineEntry('lastfmdiv');
recMod.style.display = "none";
formMod.appendChild(bindLabel(txtArtist, 'Artist: '));
//formMod.innerHTML = 'Artist: <input id="lastFMArtist" name="lastFMArtist" type="text" /><br />';
},
buildManifest: function() {
var timelineEntry = new TimelineEntry();
return {
manifestCat: '',
timelineCat: 'resources',
manifestXML: '',
timelineXML: '<wiki in="'+timelineEntry["in"]+'" out="'+timelineEntry.out+'" target="'+timelineEntry.target+
'" artist="'+txtArtist.value+'"/>'
};
}
}
})(),
twitter: (function() {
var controls = {
title: makeInput("text", "twitterTitle"),
source: makeInput("text", "twitterSource"),
width: makeInput("text", "twitterWidth"),
height: makeInput("text", "twitterHeight")
};
return {
outputHTML: function() {
clearChildren(formMod);
showTimelineEntry('personaltwitter');
recMod.style.display = "none";
var frag = newLine(bindLabel(controls.title, 'Title: '));
frag.appendChild(newLine(bindLabel(controls.source, 'Source: ')));
frag.appendChild(newLine(bindLabel(controls.width, 'Width: ')));
frag.appendChild(newLine(bindLabel(controls.height, 'Height: ')));
formMod.appendChild(frag);
//formMod.innerHTML = 'Artist: <input id="lastFMArtist" name="lastFMArtist" type="text" /><br />';
},
buildManifest: function() {
var timelineEntry = new TimelineEntry();
return {
manifestCat: '',
timelineCat: 'resources',
manifestXML: '',
timelineXML: '<wiki in="'+timelineEntry["in"]+'" out="'+timelineEntry.out+'" target="'+timelineEntry.target+'"/>'+
'" title="'+controls.title.value+'" source="'+controls.source.value+'" width="'+controls.width.value+'"/>'+
'" height="'+controls.height.value+'"/>'
};
}
}
})(),
googlenews: (function() {
var txtTopic = makeInput("text", "gNewsTopic");
return {
outputHTML: function() {
clearChildren(formMod);
showTimelineEntry('googlenewsdiv');
recMod.style.display = "none";
formMod.appendChild(bindLabel(txtTopic, 'Topic: '));
//formMod.innerHTML = 'Topic: <input id="gNewsTopic" name="gNewsTopic" type="text" /><br />';
},
buildManifest: function() {
var timelineEntry = new TimelineEntry();
return {
manifestCat: '',
timelineCat: 'resources',
manifestXML: '',
timelineXML: '<wiki in="'+timelineEntry["in"]+'" out="'+timelineEntry.out+'" target="'+timelineEntry.target+
'" topic="'+txtTopic.value+'"/>'
};
}
}
})(),
wiki: (function() {
var txtNumWords = makeInput("number", "wikiNumWords");
txtNumWords.step = 1;
txtNumWords.min = 1;
return {
outputHTML: function() {
clearChildren(formMod);
showTimelineEntry('wikidiv');
recMod.style.display = "block";
formMod.appendChild(bindLabel(txtNumWords, 'Number of Words: '));
//formMod.innerHTML = '# Words: <input id="wikiNumWords" name="wikiNumWords" type="number" step="1" min="1" /><br />';
},
buildManifest: function() {
var reSrc = new ManifestEntry();
var timelineEntry = new TimelineEntry();
return {
manifestCat: 'articles',
timelineCat: 'resources',
manifestXML: '<resource id="'+reSrc.id.value+'" src="'+reSrc.src.value+'" description="'+reSrc.description.value+'"/>',
timelineXML: '<wiki in="'+timelineEntry["in"]+'" out="'+timelineEntry.out+'" target="'+timelineEntry.target+
'" resourceid="'+reSrc.id.value+'" numberOfWords="'+txtNumWords.value+'"/>'
};
}
}
})(),
flickr: (function() {
var controls = {
numberofimages: makeInput("number", "flickrNumImgs"),
userid: makeInput("text", "flickrUserId"),
padding: makeInput("number", "flickrPadding")
};
controls.numberofimages.step = controls.padding.step = 1;
controls.numberofimages.min = controls.padding.min = 1;
return {
outputHTML: function() {
clearChildren(formMod);
showTimelineEntry('personalflickr');
recMod.style.display = "none";
var frag = newLine(bindLabel(controls.numberofimages, '# Images: '));
frag.appendChild(newLine(bindLabel(controls.userid, 'User ID: ')));
frag.appendChild(newLine(bindLabel(controls.padding, 'Padding: ')));
formMod.appendChild(frag);
//formMod.innerHTML = '# Images: <input id="flickrNumImgs" name="flickrNumImgs" type="number" step="1" min="1" /><br />'
// +'User ID: <input id="flickrUserId" name="flickrUserId" type="text" /><br />'
// +'Padding: <input id="flickrPadding" name="flickrPadding" type="number" step="1" min="1" /><br />';
},
buildManifest: function() {
var timelineEntry = new TimelineEntry();
return {
manifestCat: '',
timelineCat: 'resources',
manifestXML: '',
timelineXML: '<flickr in="'+timelineEntry["in"]+'" out="'+timelineEntry.out+'" target="'+timelineEntry.target+
'" numberofimages="'+controls.numberofimages.value+'" userid="'+controls.userid.value+
'" padding="'+controls.padding.value+'px"/>'
};
}
}
})()
};
// Formatting \\
// ---------- \\
function formatTime(t) {
var sec = Math.floor(t);
// hh:mm:ss:ms
return padNum(Math.floor(sec / 3600), 2)+":"+padNum(Math.floor(sec / 60), 2)+":"+padNum(sec, 2)+":"+padNum(Math.round((t-sec)*100), 2);
}
function padNum(num, len) {
var str = '' + num;
for(var i=str.length; i<len; i++) {
str = '0' + str;
}
return str;
}
// Basic Objects \\
// ------------- \\
function ManifestEntry() {
this.id = doc.getElementById("resrcId");
this.src = doc.getElementById("resrcSrc");
this.description = doc.getElementById("resrcDesc");
}
function TimelineEntry() {
this.target = doc.getElementById("timelineTarget").value;
this["in"] = formatTime(currentIn);
this.out = formatTime(currentOut);
}
// DOM Maniplation Functions \\
// ------------------------- \\
function makeInput(inputType, id, value) {
if (isQuirk === true) {
var input = doc.createElement('<input type="'+inputType+'">');
} else {
var input = doc.createElement('input');
input["type"] = inputType;
}
//var input = makeInputType(inputType);
input.id = input.name = id;
if (value)
input.value = value;
return input;
}
function bindLabel(input, labelText) {
var frag = doc.createDocumentFragment();
var lbl = doc.createElement('label');
lbl["for"] = input.id;
lbl.style.display= "block";
lbl.style.cssFloat = "left";
lbl.style.width= "200px";
lbl.appendChild(doc.createTextNode(labelText));
frag.appendChild(lbl);
frag.appendChild(input);
return frag;
}
function newLine(frag) {
if (!frag || !frag.nodeType)
return doc.createElement('br');
switch (frag.nodeType) {
case 1: // Element Node
case 3: // Text Node
var fgmt = doc.createDocumentFragment();
fgmt.appendChild(frag);
fgmt.appendChild(doc.createElement('br'));
return fgmt;
break;
case 11: // Doc Fragment
frag.appendChild(doc.createElement("br"));
return frag;
break;
default:
return doc.createElement('br');
break;
}
}
function clearChildren(node) {
while (node.hasChildNodes()) {
node.removeChild(node.lastChild);
}
}
// XHR, Remoting and Events \\
// ------------------------ \\
function sendDataToServer(endPoint, manifestData, actionType) {
var xhr = new XMLHttpRequest();
var params = [];
// Build query string
params.push('action='+actionType);
for(obj in manifestData) {