]> git.r.bdr.sh - rbdr/r.bdr.sh/blame - jekyll/js/unlimited_pizza.js
Remove unused multimedia
[rbdr/r.bdr.sh] / jekyll / js / unlimited_pizza.js
CommitLineData
0982546d
BB
1'use strict';
2
81003de3
BB
3const UnlimitedPizza = {
4
5 _loadPepperoni() {
6
7 const pepperoniElement = document.querySelector('[data-application="pepperoni"]');
8
9 new Pepperoni({
10 element: pepperoniElement
11 });
12 },
0982546d 13
81003de3
BB
14 _loadGuestbook() {
15
0982546d
BB
16 },
17
81003de3
BB
18 _loadGuestbookEntries() {
19
20 }
21};
22
23window.addEventListener('load', UnlimitedPizza._onLoad.bind(UnlimitedPizza));
24
25Class("UnlimitedPizza").inherits(Widget)({
bd7473dd 26 _fb : null,
0982546d
BB
27
28 init : function (config) {
29 Widget.prototype.init.call(this, config)
30
bd7473dd
BB
31 this._fb = new Firebase("https://guestbook-nsovocal.firebaseio.com");
32
0982546d
BB
33 this._bindInternalEvents();
34 },
35
36 _bindInternalEvents : function bindInternalEvents() {
37 this.bind('activate', this._onActivate.bind(this));
38 },
39
0982546d
BB
40 /*
41 * Loads everything.
42 */
43 _load : function _load() {
44
bd7473dd
BB
45 // Pepperoni is our recording widget.
46 this._loadPepperoni();
47
48 // Simple guestbook functionality
49 this._loadGuestbook();
50 this._loadPosts();
0982546d 51 },
bd7473dd
BB
52
53 _loadGuestbook : function () {
54 var form = this.element.find('.guestbook-form form');
55 form.on('submit', function submitPost(ev) {
56 ev.preventDefault();
57
58 var formArray = form.serializeArray();
59 var recorder = this['recorder-0'];
60
61 recorder.finalize(function (buffer) {
62 var fb, arrayBuffer, fileReader;
63
64 if (buffer.size <= 44) {
65 alert("You need to record something.");
66 return;
67 }
68 if (formArray[0].value.length === 0) {
69 alert("You need a name.");
70 return;
71 }
72
73 fb = this._fb;
74
75 fileReader = new FileReader();
76 fileReader.onload = function() {
77 var binary, bytes, length, i;
78
79 binary = '';
80 bytes = new Uint8Array( this.result );
81 length = bytes.byteLength;
82 for (i = 0; i < length; i++) {
83 binary += String.fromCharCode( bytes[ i ] );
84 }
85
86 fb.push({
87 buffer: btoa(binary),
88 name: formArray[0].value
89 });
90 recorder.clear();
91 };
92 fileReader.readAsArrayBuffer(buffer);
93 }.bind(this));
94 return false;
95 }.bind(this))
96 },
97
98 _loadPosts : function () {
99 var feed = this.element.find('.guestbook-feed');
100
101 console.log("Loadin", feed.length);
102 if (feed.length > 0) {
103 this._fb.on('value', function (data) {
104 var posts, property, post;
105
106 // Clear feed
107 feed.empty();
108 posts = data.val();
109
110 for (property in posts) {
111 if (posts.hasOwnProperty(property)) {
112 post = posts[property];
113
114 feed.append($('<li>\
115 <div class="author">FROM: ' + post.name + '</div>\
116 <div class="content">\
117 <audio src="data:audio/wav;base64,' + post.buffer + '" controls></audio>\
118 </div></li>'))
119 }
120 }
121 });
122 }
0982546d
BB
123 }
124 }
125});