Comparing version 0.0.2 to 0.0.3
{ | ||
"name": "trollbox", | ||
"version": "0.0.2", | ||
"version": "0.0.3", | ||
"description": "", | ||
@@ -5,0 +5,0 @@ "main": "trollbox.js", |
(function (root) { | ||
'use strict' | ||
/** | ||
* WARNING: ugly code ahead. | ||
* this is a quick and dirty MVP. | ||
*/ | ||
function Trollbox (config) { | ||
@@ -13,3 +18,5 @@ const scriptId = 'FirebaseScript' | ||
document.body.appendChild(script) | ||
script.onload = () => onLoad(config) | ||
script.onload = function () { | ||
onLoad(config) | ||
} | ||
} | ||
@@ -31,3 +38,3 @@ | ||
const post = (message) => { | ||
const post = function (message) { | ||
ref.push().set({ | ||
@@ -42,3 +49,3 @@ user, | ||
const onMessage = (snapshot) => { | ||
const onMessage = function (snapshot) { | ||
const value = snapshot.val() | ||
@@ -59,3 +66,10 @@ | ||
const app = window.firebase.initializeApp(config.firebase) | ||
var app = null | ||
if (window.firebaseApp) { | ||
app = window.firebaseApp | ||
} else { | ||
app = window.firebase.initializeApp(config.firebase) | ||
window.firebaseApp = app | ||
} | ||
const db = app.database() | ||
@@ -92,3 +106,3 @@ const ref = db.ref(`trollbox/${channel}`) | ||
form.addEventListener('submit', event => { | ||
form.addEventListener('submit', function (event) { | ||
event.preventDefault() | ||
@@ -95,0 +109,0 @@ const input = event.target.message |
Sorry, the diff of this file is not supported yet
8127
194