forked from lucaboieru/pin-notification
-
Notifications
You must be signed in to change notification settings - Fork 1
/
ui.js
39 lines (32 loc) · 1.12 KB
/
ui.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
M.wrap('github/lucaboieru/pin-notification/dev/ui.js', function (require, module, exports) {
module.exports = function (config) {
var self = this;
// adding homescreen icon and meta
var link = document.createElement('link');
link.href = config.icon;
link.rel = 'shortcut icon';
$(link).attr('sizes', '196x196');
var linkApple = document.createElement('link');
linkApple.href = config.icon;
linkApple.rel = 'apple-touch-icon';
var meta = document.createElement('meta');
for (var prop in config.meta) {
meta[prop] = config.meta[prop];
}
$("head").append(link).append(linkApple).append(meta);
var device;
if (navigator.userAgent.match(/(iPod|iPhone|iPad)/) && navigator.userAgent.match(/AppleWebKit/)) {
device = "ios";
} else {
device = "other";
}
if (config.selectors[device] && window.localStorage.getItem("notification") === null) {
$(config.selectors[device]).show();
$(self.dom).parent().show();
$(self.dom).parent().on('click', function () {
$(this).hide();
window.localStorage.setItem("notification", false);
});
}
}
return module; });