+ // Pepperoni is our recording widget.
+ this._loadPepperoni();
+
+ // Simple guestbook functionality
+ this._loadGuestbook();
+ this._loadPosts();
+ },
+
+ _loadGuestbook : function () {
+ var form = this.element.find('.guestbook-form form');
+ form.on('submit', function submitPost(ev) {
+ ev.preventDefault();
+
+ var formArray = form.serializeArray();
+ var recorder = this['recorder-0'];
+
+ recorder.finalize(function (buffer) {
+ var fb, arrayBuffer, fileReader;
+
+ if (buffer.size <= 44) {
+ alert("You need to record something.");
+ return;
+ }
+ if (formArray[0].value.length === 0) {
+ alert("You need a name.");
+ return;
+ }
+
+ fb = this._fb;
+
+ fileReader = new FileReader();
+ fileReader.onload = function() {
+ var binary, bytes, length, i;
+
+ binary = '';
+ bytes = new Uint8Array( this.result );
+ length = bytes.byteLength;
+ for (i = 0; i < length; i++) {
+ binary += String.fromCharCode( bytes[ i ] );
+ }
+
+ fb.push({
+ buffer: btoa(binary),
+ name: formArray[0].value
+ });
+ recorder.clear();
+ };
+ fileReader.readAsArrayBuffer(buffer);
+ }.bind(this));
+ return false;
+ }.bind(this))