]>
git.r.bdr.sh - rbdr/r.bdr.sh/blob - jekyll/js/unlimited_pizza.js
3 const UnlimitedPizza
= {
7 const pepperoniElement
= document
.querySelector('[data-application="pepperoni"]');
10 element: pepperoniElement
18 _loadGuestbookEntries() {
23 window
.addEventListener('load', UnlimitedPizza
._onLoad
.bind(UnlimitedPizza
));
25 Class("UnlimitedPizza").inherits(Widget
)({
28 init : function (config
) {
29 Widget
.prototype.init
.call(this, config
)
31 this._fb
= new Firebase("https://guestbook-nsovocal.firebaseio.com");
33 this._bindInternalEvents();
36 _bindInternalEvents : function bindInternalEvents() {
37 this.bind('activate', this._onActivate
.bind(this));
43 _load : function _load() {
45 // Pepperoni is our recording widget.
46 this._loadPepperoni();
48 // Simple guestbook functionality
49 this._loadGuestbook();
53 _loadGuestbook : function () {
54 var form
= this.element
.find('.guestbook-form form');
55 form
.on('submit', function submitPost(ev
) {
58 var formArray
= form
.serializeArray();
59 var recorder
= this['recorder-0'];
61 recorder
.finalize(function (buffer
) {
62 var fb
, arrayBuffer
, fileReader
;
64 if (buffer
.size
<= 44) {
65 alert("You need to record something.");
68 if (formArray
[0].value
.length
=== 0) {
69 alert("You need a name.");
75 fileReader
= new FileReader();
76 fileReader
.onload = function() {
77 var binary
, bytes
, length
, i
;
80 bytes
= new Uint8Array( this.result
);
81 length
= bytes
.byteLength
;
82 for (i
= 0; i
< length
; i
++) {
83 binary
+= String
.fromCharCode( bytes
[ i
] );
88 name: formArray
[0].value
92 fileReader
.readAsArrayBuffer(buffer
);
98 _loadPosts : function () {
99 var feed
= this.element
.find('.guestbook-feed');
101 console
.log("Loadin", feed
.length
);
102 if (feed
.length
> 0) {
103 this._fb
.on('value', function (data
) {
104 var posts
, property
, post
;
110 for (property
in posts
) {
111 if (posts
.hasOwnProperty(property
)) {
112 post
= posts
[property
];
115 <div class="author">FROM: ' + post
.name
+ '</div>\
116 <div class="content">\
117 <audio src="data:audio/wav;base64,' + post
.buffer
+ '" controls></audio>\