Skip to content

Instantly share code, notes, and snippets.

View vldvel's full-sized avatar

Vlad vldvel

  • Amsterdam
View GitHub Profile
@vldvel
vldvel / Notification-properties.js
Created March 14, 2018 13:28
Notification properties
const notificationProps = {
title: 'I\'m notification',
body: 'Here is my desription',
icon: 'https://avatars1.githubusercontent.com/u/22643415',
vibrate: [50, 100, 150]
}
const myNotification = new Notification(notificationProps.title, notificationProps);
console.log(myNotification.title); // 'I\'m notification'
@vldvel
vldvel / Notification-onclick.js
Created March 14, 2018 14:39
Notification onclick
function notifyClicked = () => {
console.log('notify has been clicked');
}
Notification.onclick = notifyClicked; // won't work
Notification.prototype.onclick = notifyClicked; // won't work
const notification = Notification('Notificated!');
notification.__proto__.onclick = notifyClicked; // won't work
@vldvel
vldvel / Notification-permission-request.js
Created March 15, 2018 06:46
Notification request permission
Notification.requestPermission();
@vldvel
vldvel / Notification-close-simple.js
Created March 15, 2018 12:15
Notification close simple
const notification = new Notification('Hello world!');
setTimeout(() => {
notification.close();
}, 600);
@vldvel
vldvel / Notification.js
Last active March 15, 2018 12:34
Notification API
function createNotification () {
// first let's check browser support
if (!('Notification' in window)) {
throw new Error('Browser doesn\'t support notifications');
}
// now let's look whether permission is already granted or not
switch (Notification.permission) {
case 'granted': {
return innerCreateNotification;
}
@vldvel
vldvel / Box-shadow.js
Created March 15, 2018 15:24
Box shadows in JavaScript
const offsetX = 10; // horizontal distance - any number
const offsetY = 10; // vertical distance - any number
const blurRadius = 20; // shadow blur - positive number - default = 0
const spreadRadius = 40; // shadow size - any number - deafult = 0
const color = 'rgba(255, 255, 199, 0.7)'; // color - rgb/rgba/hsl/hsla
// basic options
element0.style.boxShadow = `${offsetX}px ${offsetY}px ${color}`;
// full options
@vldvel
vldvel / MutationObserver-simple.js
Last active March 22, 2018 10:20
MutationObserver simple
// target element that we will observe
const target = document.body;
// config object
const config = {
attributes: true,
attributeOldValue: true,
characterData: true,
characterDataOldValue: true,
childList: true,
@vldvel
vldvel / MutationObserver-config.js
Created March 21, 2018 15:04
MutationObserver config
// by default all false
// you can pick as many as you want, but at least one of - attributes, characterData, or childList
const observerConfig = {
attributes: true, // attribute changes will be observed | on add/remove/change attributes
attributeOldValue: true, // will show oldValue of attribute | on add/remove/change attributes | default: null
characterData: true, // data changes will be observed | on add/remove/change characterData
characterDataOldValue: true, // will show OldValue of characterData | on add/remove/change characterData | default: null
@vldvel
vldvel / MutationObserver-subscriber-simple.js
Last active October 19, 2019 03:12
MutationObserver subscriber simple
function subscriber(mutations) {
console.log(mutations);// [...]
console.log(mutations.constructor);// Array
mutations.forEach((mutation) => {
console.log(mutation); // {...}
console.log(mutation.constructor); // MutationRecord
});
@vldvel
vldvel / MutationObserver-constructor.js
Created March 22, 2018 07:53
MutationObserver constructor
// create subscriber
function subscriber (mutations) {
mutations.forEach((mutation) => {
console.log(mutation);
});
}
// create observer
const observer = new MutationObserver(subscriber);