16
16
-->
17
17
< html >
18
18
< head >
19
- < script src ="https://cdn.firebase .com/js/client/2.2.1 /firebase.js "> </ script >
19
+ < script src ="https://www.gstatic .com/firebasejs/3.5.2 /firebase.js "> </ script >
20
20
< script src ="https://ajax.googleapis.com/ajax/libs/jquery/1.9.0/jquery.min.js "> </ script >
21
21
< script src ="bower_components/webcomponentsjs/webcomponents-lite.js "> </ script >
22
22
< link rel ="import " href ="./bower_components/polymer-color-picker/polymer-color-picker.html ">
23
23
</ head >
24
24
< script >
25
- // TODO: Needs security.
26
- var firebaseUrl = 'https://example.firebaseio.com' ;
27
- var firebaseSecret = secret_or_token ;
25
+ // NOTICE: Retrieve these values from the Firebase console to run the sample.
26
+ var firebaseDb = 'example.firebaseio.com' ;
27
+ var firebaseAuthDomain = 'example.firebaseapp.com' ;
28
+ var firebaseApiKey = 'token_or_secret' ;
28
29
</ script >
29
30
< body >
30
31
< h2 > Paint Demo</ h3 >
@@ -113,32 +114,31 @@ <h3>Debugger / tester</h3>
113
114
}
114
115
</ pre >
115
116
116
- < script >
117
- // Firebase reference and authentication stored globally.
118
- // TODO: Encapsualte into objects, move to separate JS file
119
- var pixelData = new Firebase ( firebaseUrl ) ;
120
- pixelData . authWithCustomToken ( firebaseSecret , function ( error , result ) {
121
- if ( error ) {
122
- console . log ( "Authentication Failed!" , error ) ;
123
- } else {
124
- console . log ( "Authenticated successfully with payload:" , result . auth ) ;
125
- console . log ( "Auth expires at:" , new Date ( result . expires * 1000 ) ) ;
126
- refreshData ( ) ;
127
- } } ) ;
117
+ < script >
118
+ // Initialize Firebase
119
+ var config = {
120
+ apiKey : firebaseApiKey ,
121
+ authDomain : firebaseAuthDomain ,
122
+ databaseURL : "https://" + firebaseDb ,
123
+ storageBucket : '' , // not used
124
+ messagingSenderId : '' , // not used
125
+ } ;
126
+ firebase . initializeApp ( config ) ;
127
+ var pixelData = firebase . database ( ) ;
128
128
129
129
/**
130
130
* Explicitly refreshes data from Firebase.
131
131
* TODO: replace with streaming function that listens for events / updates.
132
132
*/
133
133
function refreshData ( ) {
134
- pixelData . once ( "value" , function ( snapshot ) {
134
+ pixelData . ref ( '/rgbdata/' ) . once ( "value" , function ( snapshot ) {
135
135
console . log ( snapshot . val ( ) ) ;
136
- document . getElementById ( 'pixelData' ) . value = JSON . stringify ( snapshot . val ( ) [ 'rgbdata' ] , 2 ) ;
136
+ document . getElementById ( 'pixelData' ) . value = JSON . stringify ( snapshot . val ( ) , 2 ) ;
137
137
138
138
for ( var i = 0 ; i < 32 ; i ++ ) {
139
139
var qString = 'pixel' + i ;
140
- if ( snapshot . val ( ) [ 'rgbdata' ] [ qString ] ) {
141
- var hexString = parseInt ( snapshot . val ( ) [ 'rgbdata' ] [ qString ] ) . toString ( 16 ) ;
140
+ if ( snapshot . val ( ) [ qString ] ) {
141
+ var hexString = parseInt ( snapshot . val ( ) [ qString ] ) . toString ( 16 ) ;
142
142
var zeroPrepend = 6 - hexString . length ;
143
143
for ( var j = 0 ; j < zeroPrepend ; j ++ ) {
144
144
hexString = '0' + hexString ;
@@ -161,7 +161,7 @@ <h3>Debugger / tester</h3>
161
161
* the Firebase database. Note that this is best for debugging.
162
162
*/
163
163
function pushData ( ) {
164
- pixelData . set ( { ' rgbdata' : JSON . parse ( document . getElementById ( 'pixelData' ) . value ) } ) ;
164
+ pixelData . ref ( '/ rgbdata/' ) . set ( JSON . parse ( document . getElementById ( 'pixelData' ) . value ) ) ;
165
165
refreshData ( ) ;
166
166
}
167
167
@@ -199,7 +199,7 @@ <h3>Debugger / tester</h3>
199
199
*/
200
200
function updatePixel ( pixelId ) {
201
201
var path = 'rgbdata/' + pixelId ;
202
- var pixelRef = pixelData . child ( path ) ;
202
+ var pixelRef = pixelData . ref ( path ) ;
203
203
var colorHex =
204
204
rgb2hex ( document . getElementById ( pixelId ) . style . backgroundColor )
205
205
. split ( '#' ) [ 1 ] ;
0 commit comments