From f649f627eb9f847c61d9c77844da5f78810e0ecb Mon Sep 17 00:00:00 2001 From: jtfairbank Date: Fri, 4 Sep 2015 19:25:59 -0700 Subject: [PATCH 1/2] Refactor For Clear Variable Names Closes #2. Thank you guys so much for this example! Once I found it I could implement a photo-uploader for our app in an hour. It was so much easier to understand than other tutorials. --- firepano.js | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/firepano.js b/firepano.js index f8034e8..32a8bd8 100644 --- a/firepano.js +++ b/firepano.js @@ -2,17 +2,16 @@ var spinner = new Spinner({color: '#ddd'}); var firebaseRef = 'https://firepano.firebaseio.com/'; function handleFileSelect(evt) { - var f = evt.target.files[0]; + var selectedFileURL = evt.target.files[0]; var reader = new FileReader(); - reader.onload = (function(theFile) { - return function(e) { + reader.onload = function(e) { var filePayload = e.target.result; // Generate a location that can't be guessed using the file's contents and a random number var hash = CryptoJS.SHA256(Math.random() + CryptoJS.SHA256(filePayload)); - var f = new Firebase(firebaseRef + 'pano/' + hash + '/filePayload'); + var fileRef = new Firebase(firebaseRef + 'pano/' + hash + '/filePayload'); spinner.spin(document.getElementById('spin')); // Set the file payload to Firebase and register an onComplete handler to stop the spinner and show the preview - f.set(filePayload, function() { + fileRef.set(filePayload, function() { spinner.stop(); document.getElementById("pano").src = e.target.result; $('#file-upload').hide(); @@ -20,8 +19,8 @@ function handleFileSelect(evt) { window.location.hash = hash; }); }; - })(f); - reader.readAsDataURL(f); + }; + reader.readAsDataURL(selectedFileURL); } $(function() { @@ -36,8 +35,8 @@ $(function() { } else { // A hash was passed in, so let's retrieve and render it. spinner.spin(document.getElementById('spin')); - var f = new Firebase(firebaseRef + '/pano/' + hash + '/filePayload'); - f.once('value', function(snap) { + var fileRef = new Firebase(firebaseRef + '/pano/' + hash + '/filePayload'); + fileRef.once('value', function(snap) { var payload = snap.val(); if (payload != null) { document.getElementById("pano").src = payload; From fcb3b074fd9fbad73a56e142b1a0672a268b2205 Mon Sep 17 00:00:00 2001 From: jtfairbank Date: Fri, 4 Sep 2015 19:48:20 -0700 Subject: [PATCH 2/2] Whoops --- firepano.js | 27 +++++++++++++-------------- 1 file changed, 13 insertions(+), 14 deletions(-) diff --git a/firepano.js b/firepano.js index 32a8bd8..1db7259 100644 --- a/firepano.js +++ b/firepano.js @@ -5,20 +5,19 @@ function handleFileSelect(evt) { var selectedFileURL = evt.target.files[0]; var reader = new FileReader(); reader.onload = function(e) { - var filePayload = e.target.result; - // Generate a location that can't be guessed using the file's contents and a random number - var hash = CryptoJS.SHA256(Math.random() + CryptoJS.SHA256(filePayload)); - var fileRef = new Firebase(firebaseRef + 'pano/' + hash + '/filePayload'); - spinner.spin(document.getElementById('spin')); - // Set the file payload to Firebase and register an onComplete handler to stop the spinner and show the preview - fileRef.set(filePayload, function() { - spinner.stop(); - document.getElementById("pano").src = e.target.result; - $('#file-upload').hide(); - // Update the location bar so the URL can be shared with others - window.location.hash = hash; - }); - }; + var filePayload = e.target.result; + // Generate a location that can't be guessed using the file's contents and a random number + var hash = CryptoJS.SHA256(Math.random() + CryptoJS.SHA256(filePayload)); + var fileRef = new Firebase(firebaseRef + 'pano/' + hash + '/filePayload'); + spinner.spin(document.getElementById('spin')); + // Set the file payload to Firebase and register an onComplete handler to stop the spinner and show the preview + fileRef.set(filePayload, function() { + spinner.stop(); + document.getElementById("pano").src = e.target.result; + $('#file-upload').hide(); + // Update the location bar so the URL can be shared with others + window.location.hash = hash; + }); }; reader.readAsDataURL(selectedFileURL); }