Skip to content

Instantly share code, notes, and snippets.

@xgqfrms-GitHub
Last active May 25, 2017 14:12
Show Gist options
  • Save xgqfrms-GitHub/bab5cd08a4c85707ce10dd5e0a1057e1 to your computer and use it in GitHub Desktop.
Save xgqfrms-GitHub/bab5cd08a4c85707ce10dd5e0a1057e1 to your computer and use it in GitHub Desktop.
Web API Notifications

Web API Notifications

https://developer.mozilla.org/zh-CN/docs/Web/API/USVString

https://developer.mozilla.org/zh-CN/docs/Web/API/Vibration_API

https://w3c.github.io/vibration/

https://www.w3.org/TR/vibration/

https://w3c-html-ig-zh.github.io/vibration/

https://developer.mozilla.org/zh-CN/docs/Web/API/notification/Using_Web_Notifications

let notification = new Notification('notification title', {
    dir: 'auto',
    lang: 'zh-CN',
    body: `Web Notification API`,
    tag: `ID_001`,
    icon: `https://cdn.xgqfrms.xyz/logo/icon.png`
});


const options = {
    dir: `auto`,
    lang: `zh-CN`,
    body: `Web Notification API`,
    tag: `ID_001`,
    badge: `https://cdn.xgqfrms.xyz/logo/logo.png`,
    icon: `https://cdn.xgqfrms.xyz/logo/icon.png`,
    data: `json`,
    image: `https://s3-us-west-2.amazonaws.com/s.cdpn.io/375439/profile/profile-512.jpg`,
    vibrate: [100, 200, 300],
    renotify: true,
    requireInteraction: false,
    silent: false,
    timestamp: 1234567890123456789
};


let notification = new Notification('notification title', options);


// actions: []

// vibrate: []

// onclick: null
// onclose: null
// onerror: null
// onshow: null

close: function(arguments, caller){
    // arguments
    // length: 0
    // name: "close"
}


Notification.close();

setTimeout(notification.close.bind(notification), 3000);



// Notification.onclose

// Notification.onerror

// Notification.onshow


// Notification.onclick


// Notification.permission 




notification.onclick = function(event) {
    event.preventDefault(); 
    // prevent the browser from focusing the Notification's tab
    window.open('https://www.xgqfrms.xyz', '_blank');
}

notification.onclick = function(event) {
    window.open('https://www.xgqfrms.xyz', '_blank');
}


notification.onclose = function(event) {
    alert(`You are closing the Notification!`);
    setTimeout(() => {
        window.open('https://www.xgqfrms.xyz', '_blank');
    }, 1000);
}



const {} = options;





Notification.requestPermission()
    .then(function(permission){
        console.log(permission);
        console.log(typeof(permission));
        // denied / granted / default
        if(permission === 'granted'){
            console.log(`permission has been got!`);
            notification;
        }else if(permission === 'denied'){
            console.log(`permission hasn't been got!`);
        }else{
            console.log(`permission Error!`);
        }
        // Nested Template String
        return ` 
            ${
                `${permission === `granted`}`
                ? 
                `${console.log("permission has been got!")}`
                :
                `${console.log("permission hasn't been got!")}`
            }
        `;
    }
);



window.addEventListener('load', function () {
    Notification.requestPermission(function (status) {
        // 这将使我们能在 Chrome/Safari 中使用 Notification.permission
        if (Notification.permission !== status) {
            Notification.permission = status;
        }
    });
});



Notification.requestPermission()
    .then(function(result) {
        if (result === 'denied') {
            console.log('Permission wasn\'t granted. Allow a retry.');
            return;
        }
        if (result === 'default') {
            console.log('The permission request was dismissed.');
            return;
        }
        // Do something with the granted permission.
        if (result === 'granted') {
            console.log('The permission request was granted.');
            return;
        }
    }
);
















# OK

```js

`
    ${
        var 
        ?
        ` ${var} `
        :
        ` ${var} `
    }
`

// OR

`
    ${
        ` ${var} `
        ?
        ` ${var} `
        :
        ` ${var} `
    }
`

error

${
    ${}
}

# es6-template-literals-nested & es6-template-literals-condition

https://gist.github.com/xgqfrms-GitHub/39afeb64766eccce920fbaeac5f89f23




@xgqfrms-GitHub
Copy link
Author

xgqfrms-GitHub commented May 25, 2017

Jquery

$('#pac_value').val(); === $('#pac_value')[0].value;

const packet = $('#packet')
    , redPacketName = $('#pac_name').val()
    , startTime = $('#pac_start').val()
    , endTime = $('#pac_end').val()
    , threshold = $('#pac_full').val()
    , validTime = $('#pac_condition').val()
    , redPacketDescr = $('#pac_extra').val()
    , redPacketMoney = $('#pac_value').val()
    , unlimit = $('#pac_unlimit')
    , limit = $('#pac_limit');

$(function(){
        let rp = parseInt($('#pac_value')[0].value);
        let cd = parseInt($('#pac_full')[0].value);
        if(rp > cd){
            // alert(`红包面值不可大于使用条件!`);
            Modal.setAlert('输入的红包面值不可大于使用条件!');
            return false;
        }
    });

@xgqfrms-GitHub
Copy link
Author

@xgqfrms-GitHub
Copy link
Author

https://scs.dd528.com/

第三方
18188888888
888888

@xgqfrms-GitHub
Copy link
Author

xgqfrms-GitHub commented May 25, 2017

https://javascript30.com/

Jquery

$('#pac_value').val(); === $('#pac_value')[0].value;

const packet = $('#packet')
    , redPacketName = $('#pac_name').val()
    , startTime = $('#pac_start').val()
    , endTime = $('#pac_end').val()
    , threshold = $('#pac_full').val()
    , validTime = $('#pac_condition').val()
    , redPacketDescr = $('#pac_extra').val()
    , redPacketMoney = $('#pac_value').val()
    , unlimit = $('#pac_unlimit')
    , limit = $('#pac_limit');

$(function(){
        let rp = parseInt($('#pac_value')[0].value);
        let cd = parseInt($('#pac_full')[0].value);
        if(rp > cd){
            // alert(`红包面值不可大于使用条件!`);
            Modal.setAlert('输入的红包面值不可大于使用条件!');
            return false;
        }
    });

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment