Created
October 14, 2019 11:00
-
-
Save DominicFinn/5d8cd1e6851224ba7864b922ea9788d4 to your computer and use it in GitHub Desktop.
Firebase talking to unbounce
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<script src="https://www.gstatic.com/firebasejs/7.1.0/firebase-app.js"></script> | |
<script src="https://www.gstatic.com/firebasejs/5.0.3/firebase-firestore.js"></script> | |
<script src="https://www.gstatic.com/firebasejs/5.0.3/firebase-auth.js"></script> | |
<script src="https://code.jquery.com/jquery-1.12.4.js" crossorigin="anonymous"></script> | |
<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js" crossorigin="anonymous"></script> | |
<script> | |
debugger; | |
$(document).ready(function() { | |
debugger; | |
var config = { | |
apiKey: "", | |
authDomain: "", | |
databaseURL: "", | |
projectId: "", | |
storageBucket: "", | |
messagingSenderId: "", | |
appId: "" | |
}; | |
firebase.initializeApp(config); | |
firebase.auth().signInAnonymously().catch(function(error) { | |
var errorCode = error.code; | |
var errorMessage = error.message; | |
console.log(errorCode + ":" + errorMessage); | |
}); | |
firebase.auth().onAuthStateChanged(function(user) { | |
if (user) { | |
const db = firebase.firestore(); | |
db.settings({ timestampsInSnapshots: true }); | |
var unis = []; | |
db.collection("universities").get().then((querySnapshot) => { | |
querySnapshot.forEach((doc) => { | |
unis.push(doc.data().name); | |
}); | |
var $uni_name = $("#university"); | |
$uni_name.autocomplete({ | |
source: unis | |
}); | |
if(document.forms.length > 0) { | |
document.forms[0].addEventListener('submit', function() { | |
db.collection("universities").add({ | |
name: $uni_name.val() | |
}); | |
}); | |
} | |
}); | |
var groups = []; | |
db.collection("groups").get().then((querySnapshot) => { | |
querySnapshot.forEach((doc) => { | |
groups.push(doc.data().name); | |
}); | |
var $society_name = $("#society_name"); | |
$society_name.autocomplete({ | |
source: groups | |
}); | |
if(document.forms.length > 0) { | |
document.forms[0].addEventListener('submit', function() { | |
db.collection("groups").add({ | |
name: $society_name.val() | |
}); | |
}); | |
} | |
}); | |
} | |
}); | |
}); | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment