-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Notifications about friends requests
- Loading branch information
1 parent
d619d1a
commit 5c9bcb2
Showing
8 changed files
with
331 additions
and
5 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
function getCookie(name) { | ||
var matches = document.cookie.match(new RegExp( | ||
"(?:^|; )" + name.replace(/([\.$?*|{}\(\)\[\]\\\/\+^])/g, '\\$1') + "=([^;]*)" | ||
)); | ||
return matches ? decodeURIComponent(matches[1]) : undefined; | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
socket.on(getCookie("danchat.token"), function(update) { | ||
if (update.type === "newIncomingRequest") { | ||
VanillaToasts.create({ | ||
title: "Уведомление", | ||
text: `<a class="login" href="/u/${update.login}"><b style="color:${update.color}">${update.login}</b></a> (${update.name}) хочет с вами дружить`, | ||
type: "info", | ||
callback: ()=>{ | ||
location = "/incoming" | ||
}, | ||
timeout:20000 | ||
}); | ||
} else if (update.type === "acceptOutcomingRequest") { | ||
VanillaToasts.create({ | ||
title: "Уведомление", | ||
text: `<a class="login" href="/u/${update.login}"><b style="color:${update.color}">${update.login}</b></a> (${update.name}) принял${update.sex?"":"а"} вашу заявку`, | ||
type: "success", | ||
callback: ()=>{ | ||
location = "/friends" | ||
}, | ||
timeout:20000 | ||
}); | ||
} else if (update.type === "deletingFromFriends") { | ||
VanillaToasts.create({ | ||
title: "Уведомление", | ||
text: `<a class="login" href="/u/${update.login}"><b style="color:${update.color}">${update.login}</b></a> (${update.name}) удалил${update.sex?"":"а"} вас из друзей`, | ||
type: "error", | ||
callback: ()=>{ | ||
location = "/friends" | ||
}, | ||
timeout:20000 | ||
}); | ||
} | ||
}) |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,132 @@ | ||
(function(root, factory) { | ||
try { | ||
// commonjs | ||
if (typeof exports === 'object') { | ||
module.exports = factory(); | ||
// global | ||
} else { | ||
root.VanillaToasts = factory(); | ||
} | ||
} catch(error) { | ||
console.log('Isomorphic compatibility is not supported at this time for VanillaToasts.') | ||
} | ||
})(this, function() { | ||
|
||
// We need DOM to be ready | ||
if (document.readyState === 'complete') { | ||
init(); | ||
} else { | ||
window.addEventListener('DOMContentLoaded', init); | ||
} | ||
|
||
// Create VanillaToasts object | ||
VanillaToasts = { | ||
// In case toast creation is attempted before dom has finished loading! | ||
create: function() { | ||
console.error([ | ||
'DOM has not finished loading.', | ||
'\tInvoke create method when DOM\s readyState is complete' | ||
].join('\n')) | ||
}, | ||
//function to manually set timeout after create | ||
setTimeout: function() { | ||
console.error([ | ||
'DOM has not finished loading.', | ||
'\tInvoke create method when DOM\s readyState is complete' | ||
].join('\n')) | ||
}, | ||
toasts: {} //store toasts to modify later | ||
}; | ||
var autoincrement = 0; | ||
|
||
// Initialize library | ||
function init() { | ||
// Toast container | ||
var container = document.createElement('div'); | ||
container.id = 'vanillatoasts-container'; | ||
document.body.appendChild(container); | ||
|
||
// @Override | ||
// Replace create method when DOM has finished loading | ||
VanillaToasts.create = function(options) { | ||
var toast = document.createElement('div'); | ||
toast.id = ++autoincrement; | ||
toast.id = 'toast-' + toast.id; | ||
toast.className = 'vanillatoasts-toast'; | ||
|
||
// title | ||
if (options.title) { | ||
var h4 = document.createElement('h4'); | ||
h4.className = 'vanillatoasts-title'; | ||
h4.innerHTML = options.title; | ||
toast.appendChild(h4); | ||
} | ||
|
||
// text | ||
if (options.text) { | ||
var p = document.createElement('p'); | ||
p.className = 'vanillatoasts-text'; | ||
p.innerHTML = options.text; | ||
toast.appendChild(p); | ||
} | ||
|
||
// icon | ||
if (options.icon) { | ||
var img = document.createElement('img'); | ||
img.src = options.icon; | ||
img.className = 'vanillatoasts-icon'; | ||
toast.appendChild(img); | ||
} | ||
|
||
// click callback | ||
if (typeof options.callback === 'function') { | ||
toast.addEventListener('click', options.callback); | ||
} | ||
|
||
// toast api | ||
toast.hide = function() { | ||
toast.className += ' vanillatoasts-fadeOut'; | ||
toast.addEventListener('animationend', removeToast, false); | ||
}; | ||
|
||
// autohide | ||
if (options.timeout) { | ||
setTimeout(toast.hide, options.timeout); | ||
} | ||
|
||
if (options.type) { | ||
toast.className += ' vanillatoasts-' + options.type; | ||
} | ||
|
||
toast.addEventListener('click', toast.hide); | ||
|
||
|
||
function removeToast() { | ||
document.getElementById('vanillatoasts-container').removeChild(toast); | ||
delete VanillaToasts.toasts[toast.id]; //remove toast from object | ||
} | ||
|
||
document.getElementById('vanillatoasts-container').appendChild(toast); | ||
|
||
//add toast to object so its easily gettable by its id | ||
VanillaToasts.toasts[toast.id] = toast; | ||
|
||
return toast; | ||
} | ||
|
||
/* | ||
custom function to manually initiate timeout of | ||
the toast. Useful if toast is created as persistant | ||
because we don't want it to start to timeout until | ||
we tell it to | ||
*/ | ||
VanillaToasts.setTimeout = function(toastid, val) { | ||
if(VanillaToasts.toasts[toastid]){ | ||
setTimeout(VanillaToasts.toasts[toastid].hide, val); | ||
} | ||
} | ||
} | ||
|
||
return VanillaToasts; | ||
|
||
}); |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
#vanillatoasts-container { | ||
position: fixed; | ||
top: 0; | ||
right: 0; | ||
width: 320px; | ||
font-family: 'Helvetica'; | ||
} | ||
|
||
.vanillatoasts-toast { | ||
position: relative; | ||
padding: 20px 17px; | ||
margin: 20px; | ||
border-radius: 10px; | ||
background: #F5F5F5; | ||
cursor: pointer; | ||
box-shadow: 1px 1px 3px rgba(0, 0, 0, 0.1); | ||
animation-duration: .3s; | ||
animation-name: VanillaToasts; | ||
animation-timing-function: cubic-bezier(0.215, 0.610, 0.355, 1.000); | ||
} | ||
|
||
.vanillatoasts-fadeOut { | ||
animation-name: VanillaToastsFadeOut; | ||
animation-duration: .3s; | ||
animation-timing-function: cubic-bezier(0.215, 0.610, 0.355, 1.000); | ||
animation-fill-mode: forwards; | ||
} | ||
|
||
#vanillatoasts-container p, | ||
#vanillatoasts-container h4 { | ||
margin: 3px 0!important; | ||
} | ||
|
||
.vanillatoasts-title { | ||
font-weight: 700; | ||
font-size: 15px; | ||
margin-bottom: 10px; | ||
} | ||
|
||
.vanillatoasts-text { | ||
font-size: 14px; | ||
color: #2e2e2e; | ||
} | ||
|
||
.vanillatoasts-icon { | ||
position: absolute; | ||
top: 5px; | ||
left: -40px; | ||
width: 50px; | ||
height: 50px; | ||
border-radius: 100%; | ||
box-shadow: 1px 1px 3px rgba(0, 0, 0, 0.1); | ||
background: #FFF; | ||
} | ||
|
||
.vanillatoasts-toast a, .vanillatoasts-toast a:hover { | ||
color: #549EDB !important; | ||
text-decoration: none !important; | ||
} | ||
|
||
/** toast types */ | ||
.vanillatoasts-success { | ||
border-bottom: 5px solid #51C625; | ||
} | ||
|
||
.vanillatoasts-warning { | ||
border-bottom: 5px solid #DB9215; | ||
} | ||
|
||
.vanillatoasts-error { | ||
border-bottom: 5px solid #DB2B1D; | ||
} | ||
|
||
.vanillatoasts-info { | ||
border-bottom: 5px solid #27ABDB; | ||
} | ||
|
||
@keyframes VanillaToasts { | ||
from { | ||
transform: translate3d(400px, 0, 0);; | ||
opacity: 0; | ||
} | ||
to { | ||
transform: translate3d(0, 0, 0); | ||
opacity: 1; | ||
} | ||
} | ||
|
||
@keyframes VanillaToastsFadeOut { | ||
from { | ||
transform: translate3d(0, 0, 0); | ||
opacity: 1; | ||
} | ||
to { | ||
transform: translate3d(400px, 0, 0); | ||
opacity: 0; | ||
} | ||
} |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
<meta charset="utf-8" /> | ||
<link rel="shortcut icon" href="favicon.ico" type="image/x-icon" /> | ||
<link rel="stylesheet" type="text/css" href="/styles/style.css" /> | ||
<link rel="stylesheet" type="text/css" href="/styles/vanillatoasts.css" /> |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,5 @@ | ||
<script src="https://cdnjs.cloudflare.com/ajax/libs/socket.io/2.3.0/socket.io.slim.js" integrity="sha256-Dul4c09cdrWKXVtallPxF558lwxMwCC8dXJdZ0PVW54=" crossorigin="anonymous"></script> | ||
<script src="/js/standart.js"></script> | ||
<script src="/js/functions.js"></script> | ||
<script src="/js/notifications.js"></script> | ||
<script src="/js/vanillatoasts.js"></script> |