]>
git.r.bdr.sh - rbdr/r.bdr.sh/blob - jekyll/js/unlimited_pizza.js
af650ee3a52229399820678dd4e68c82a62977a4
3 Class("UnlimitedPizza").inherits(Widget
)({
6 * Gets instance, creates it if not available.
8 instance : function getInstance(config
) {
9 if (!this._mainInstance
) {
10 this._mainInstance
= new this(config
);
12 return this._mainInstance
;
19 init : function (config
) {
20 Widget
.prototype.init
.call(this, config
)
22 this._fb
= new Firebase("https://guestbook-nsovocal.firebaseio.com");
24 this._bindInternalEvents();
27 _bindInternalEvents : function bindInternalEvents() {
28 this.bind('activate', this._onActivate
.bind(this));
31 _onActivate : function _activate() {
32 // If this is the first time activating it... then load
41 _load : function _load() {
43 // Melty cheese is our header image widget.
44 this._loadMeltyCheese();
46 // Pepperoni is our recording widget.
47 this._loadPepperoni();
49 // Simple guestbook functionality
50 this._loadGuestbook();
54 _loadMeltyCheese : function () {
55 this.element
.find('.post-image').each(function (i
, headerElement
) {
57 // Create and activate
58 this.appendChild(new UnlimitedPizza
.MeltyCheese({
59 element : $(headerElement
),
62 this['header-' + i
].activate();
66 _loadPepperoni : function () {
67 this.element
.find('.pepperoni-widget').each(function (i
, widgetElement
) {
69 // Create and activate
70 this.appendChild(new UnlimitedPizza
.Pepperoni({
71 element : $(widgetElement
),
72 name : 'recorder-' + i
74 this['recorder-' + i
].activate();
78 _loadGuestbook : function () {
79 var form
= this.element
.find('.guestbook-form form');
80 form
.on('submit', function submitPost(ev
) {
83 var formArray
= form
.serializeArray();
84 var recorder
= this['recorder-0'];
86 recorder
.finalize(function (buffer
) {
87 var fb
, arrayBuffer
, fileReader
;
89 if (buffer
.size
<= 44) {
90 alert("You need to record something.");
93 if (formArray
[0].value
.length
=== 0) {
94 alert("You need a name.");
100 fileReader
= new FileReader();
101 fileReader
.onload = function() {
102 var binary
, bytes
, length
, i
;
105 bytes
= new Uint8Array( this.result
);
106 length
= bytes
.byteLength
;
107 for (i
= 0; i
< length
; i
++) {
108 binary
+= String
.fromCharCode( bytes
[ i
] );
112 buffer: btoa(binary
),
113 name: formArray
[0].value
117 fileReader
.readAsArrayBuffer(buffer
);
123 _loadPosts : function () {
124 var feed
= this.element
.find('.guestbook-feed');
126 console
.log("Loadin", feed
.length
);
127 if (feed
.length
> 0) {
128 this._fb
.on('value', function (data
) {
129 var posts
, property
, post
;
135 for (property
in posts
) {
136 if (posts
.hasOwnProperty(property
)) {
137 post
= posts
[property
];
140 <div class="author">FROM: ' + post
.name
+ '</div>\
141 <div class="content">\
142 <audio src="data:audio/wav;base64,' + post
.buffer
+ '" controls></audio>\