Skip to content

Instantly share code, notes, and snippets.

// Move on the map and add marker to a chosen position
function moveOnTheMap(map, chosenPositionMarker) {
map.on("click", function (e) {
lat = e.latlng.lat;
lon = e.latlng.lng;
document.getElementById("shop-location").value = lat + " " + lon;
let redIcon = new L.Icon({
iconUrl: "https://raw.githubusercontent.com/pointhi/leaflet-color-markers/master/img/marker-icon-2x-red.png",
shadowUrl: "https://cdnjs.cloudflare.com/ajax/libs/leaflet/0.7.7/images/marker-shadow.png",
// Uploading picture
function uploadImageToFirebaseStorage(elementName, fileName, img, edit) {
// // Create a reference for the storage, the folder and the filename
const storageRef = firebase.storage().ref('products/' + fileName);
// Upload the file and metadata
const uploadTask = storageRef.putString(img, 'base64');
// Register three observers:
// 1. 'state_changed' observer, called any time the state changes
// 2. Error observer, called on failure
// Real time update with Firebase for the Products
const getRealTimeUpdatesForProducts = (elementName, pageName) => {
...
db.collection('products').onSnapshot((doc) => {
let result = '';
doc.docs.forEach((doc) => {
...
const data = doc.data();
result += `
<div class="card-bg block block-strong inset">
// Listen for Auth Status Changes
auth.onAuthStateChanged(user => setUpUI(user));
// Logout
const logoutBtn = document.querySelector('#logout');
logoutBtn.addEventListener('click', () => auth.signOut());
// Get Threads Data
const getThreads = () => {
db.collection('threads')
.orderBy('created', 'desc')
.get().then(snapshot => setUpThreads(snapshot.docs));
}
<script>
getThreads();
</script>
<script>
return {
on: {
pageInit: function (e, page) {
signUp();
}
}
}
</script>
<script>
return {
on: {
pageInit: function (e, page) {
const newCommentBtn = document.querySelector('#new-comment');
// Toggle UI Element
auth.onAuthStateChanged(user => {
(user)
? newCommentBtn.classList.remove('display')
// Delete Thread/Comment Image
const deleteImage = (folder, id) => {
const ref = firebase.storage().ref(folder).child(id + '.jpg');
// Delete the file
ref.delete();
}