diff options
Diffstat (limited to 'src/static')
| -rw-r--r-- | src/static/comments.js | 63 | ||||
| -rw-r--r-- | src/static/style.css | 40 |
2 files changed, 100 insertions, 3 deletions
diff --git a/src/static/comments.js b/src/static/comments.js new file mode 100644 index 0000000..c8234d2 --- /dev/null +++ b/src/static/comments.js | |||
| @@ -0,0 +1,63 @@ | |||
| 1 | var firebaseConfig = { | ||
| 2 | apiKey: "AIzaSyD3E0XtiUJI4-JIxcIPZziNLGVaTdojz20", | ||
| 3 | authDomain: "mitja-felicijan-blog.firebaseapp.com", | ||
| 4 | databaseURL: "https://mitja-felicijan-blog.firebaseio.com", | ||
| 5 | projectId: "mitja-felicijan-blog", | ||
| 6 | storageBucket: "mitja-felicijan-blog.appspot.com", | ||
| 7 | messagingSenderId: "41650892882", | ||
| 8 | appId: "1:41650892882:web:b308f0a9c47198bdf7ef8b" | ||
| 9 | }; | ||
| 10 | firebase.initializeApp(firebaseConfig); | ||
| 11 | |||
| 12 | var database = firebase.database(); | ||
| 13 | var docPath = 'comments' + window.location.pathname.replace('.html', ''); | ||
| 14 | var submit = document.querySelector('#submit'); | ||
| 15 | var comments = document.querySelector('.comments ul'); | ||
| 16 | var textName = document.querySelector('#name'); | ||
| 17 | var textComment = document.querySelector('#comment'); | ||
| 18 | var ref = firebase.database().ref(docPath); | ||
| 19 | |||
| 20 | function encodeHTML(s) { | ||
| 21 | return s.replace(/&/g, '&').replace(/</g, '<').replace(/"/g, '"'); | ||
| 22 | } | ||
| 23 | |||
| 24 | ref.on("value", function (snapshot) { | ||
| 25 | comments.innerHTML = ''; | ||
| 26 | var commentList = Array(); | ||
| 27 | |||
| 28 | // generating normal array | ||
| 29 | snapshot.forEach(function (item) { | ||
| 30 | commentList.push(item.val()) | ||
| 31 | }); | ||
| 32 | |||
| 33 | // rendering html | ||
| 34 | commentList.reverse().forEach(function (item) { | ||
| 35 | var liItem = `<li> | ||
| 36 | <div><b>${encodeHTML(item.name)}</b> - ${encodeHTML(item.published)}</div> | ||
| 37 | <div>${encodeHTML(item.comment)}</div> | ||
| 38 | </li>`; | ||
| 39 | comments.innerHTML += liItem; | ||
| 40 | }); | ||
| 41 | |||
| 42 | }, function (errorObject) { | ||
| 43 | console.log("The read failed: " + errorObject.code); | ||
| 44 | }); | ||
| 45 | |||
| 46 | submit.addEventListener('click', function (evt) { | ||
| 47 | if (textName.value && textComment.value) { | ||
| 48 | submit.disabled = true; | ||
| 49 | firebase.database().ref(docPath + '/' + Date.now()).set({ | ||
| 50 | name: textName.value, | ||
| 51 | comment: textComment.value, | ||
| 52 | published: new Date().toISOString().slice(0, 16).replace('T', ' '), | ||
| 53 | }, function (error) { | ||
| 54 | if (error) { | ||
| 55 | alert('Data could not be saved.' + error); | ||
| 56 | } else { | ||
| 57 | textName.value = ''; | ||
| 58 | textComment.value = ''; | ||
| 59 | submit.disabled = false; | ||
| 60 | } | ||
| 61 | }); | ||
| 62 | } | ||
| 63 | }); | ||
diff --git a/src/static/style.css b/src/static/style.css index b7fe7f7..f76fea0 100644 --- a/src/static/style.css +++ b/src/static/style.css | |||
| @@ -1,3 +1,7 @@ | |||
| 1 | * { | ||
| 2 | box-sizing: border-box; | ||
| 3 | } | ||
| 4 | |||
| 1 | body { | 5 | body { |
| 2 | line-height: 150%; | 6 | line-height: 150%; |
| 3 | margin-bottom: 100px; | 7 | margin-bottom: 100px; |
| @@ -39,14 +43,19 @@ img { | |||
| 39 | } | 43 | } |
| 40 | 44 | ||
| 41 | ul.article-list li { | 45 | ul.article-list li { |
| 42 | margin-bottom: 10px; | 46 | margin-bottom: 10px; |
| 47 | } | ||
| 48 | |||
| 49 | ul.article-list li div { | ||
| 50 | display: flex; | ||
| 43 | } | 51 | } |
| 44 | 52 | ||
| 45 | ul.article-list time { | 53 | ul.article-list time { |
| 46 | display: inline-block; | 54 | display: inline-block; |
| 47 | min-width: 120px; | 55 | min-width: 130px; |
| 48 | } | 56 | } |
| 49 | 57 | ||
| 58 | |||
| 50 | article .info { | 59 | article .info { |
| 51 | font-style: oblique; | 60 | font-style: oblique; |
| 52 | } | 61 | } |
| @@ -84,6 +93,31 @@ p.modified { | |||
| 84 | color: #000; | 93 | color: #000; |
| 85 | } | 94 | } |
| 86 | 95 | ||
| 96 | |||
| 97 | .comments { | ||
| 98 | margin-top: 50px; | ||
| 99 | } | ||
| 100 | .comments ul { | ||
| 101 | margin-top: 30px; | ||
| 102 | padding-left: 15px; | ||
| 103 | } | ||
| 104 | .comments ul li { | ||
| 105 | margin-bottom: 20px; | ||
| 106 | } | ||
| 107 | .comments input, | ||
| 108 | .comments textarea { | ||
| 109 | width: 100%; | ||
| 110 | padding: 10px; | ||
| 111 | margin-bottom: 10px; | ||
| 112 | font-family: inherit; | ||
| 113 | font-size: inherit; | ||
| 114 | border: 1px solid lightgray; | ||
| 115 | } | ||
| 116 | .comments textarea { | ||
| 117 | resize: vertical; | ||
| 118 | height: 100px; | ||
| 119 | } | ||
| 120 | |||
| 87 | @media only screen and (max-width:480px) { | 121 | @media only screen and (max-width:480px) { |
| 88 | main { | 122 | main { |
| 89 | padding: 20px; | 123 | padding: 20px; |
