mirror of
https://github.com/coderaiser/cloudcmd.git
synced 2026-01-23 02:35:49 +00:00
feature(notify) add
This commit is contained in:
parent
b7e8c929b6
commit
acf9601faf
3 changed files with 64 additions and 51 deletions
|
|
@ -40,6 +40,7 @@
|
|||
client + 'key.js',
|
||||
client + 'listeners.js',
|
||||
lib + 'client.js',
|
||||
client + 'notify.js',
|
||||
client + 'loader.js',
|
||||
client + 'dom.js',
|
||||
lib + 'cloudfunc.js',
|
||||
|
|
|
|||
|
|
@ -641,55 +641,6 @@ var CloudCmd, Util, DOM, CloudFunc, Dialog;
|
|||
return lRet;
|
||||
};
|
||||
},
|
||||
NotifyProto = function() {
|
||||
var Show, Allow,
|
||||
Notify = this,
|
||||
Notification = window.Notification;
|
||||
|
||||
Events.add({
|
||||
'blur' :function() {
|
||||
Show = true;
|
||||
},
|
||||
'focus': function() {
|
||||
Show = false;
|
||||
}
|
||||
}, window);
|
||||
|
||||
this.send = function(msg) {
|
||||
CloudCmd.getConfig(function(config) {
|
||||
var notify,
|
||||
notifications = config.notifications,
|
||||
focus = window.focus.bind(window),
|
||||
granted = Notify.check();
|
||||
|
||||
if (notifications && granted && Show) {
|
||||
notify = new Notification(msg, {
|
||||
icon: '/img/favicon/favicon-notify.png',
|
||||
});
|
||||
|
||||
Events.addClick(focus, notify);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
this.check = function () {
|
||||
var ret,
|
||||
Not = Notification,
|
||||
perm = Not && Not.permission;
|
||||
|
||||
if (perm === 'granted')
|
||||
ret = true;
|
||||
|
||||
return ret;
|
||||
};
|
||||
|
||||
this.request = function () {
|
||||
var Not = Notification;
|
||||
|
||||
if (Not)
|
||||
Not.requestPermission();
|
||||
};
|
||||
},
|
||||
|
||||
CmdProto = function() {
|
||||
var Cmd = this,
|
||||
|
|
@ -1789,7 +1740,6 @@ var CloudCmd, Util, DOM, CloudFunc, Dialog;
|
|||
|
||||
DOMTree = Util.extendProto(DOMTreeProto),
|
||||
Events = Util.extendProto(EventsProto),
|
||||
Notify = Util.extendProto(NotifyProto),
|
||||
Images = Util.extendProto(ImagesProto),
|
||||
RESTful = Util.extendProto(RESTfulProto),
|
||||
Storage = Util.extendProto(StorageProto);
|
||||
|
|
@ -1804,7 +1754,6 @@ var CloudCmd, Util, DOM, CloudFunc, Dialog;
|
|||
RESTful : RESTful,
|
||||
Images : Images,
|
||||
Storage : Storage,
|
||||
Notify : Notify,
|
||||
Dialog : Dialog
|
||||
}
|
||||
]);
|
||||
|
|
|
|||
63
lib/client/notify.js
Normal file
63
lib/client/notify.js
Normal file
|
|
@ -0,0 +1,63 @@
|
|||
var CloudCmd;
|
||||
|
||||
(function(Util, DOM) {
|
||||
'use strict';
|
||||
|
||||
var Notify = Util.extendProto(NotifyProto),
|
||||
DOMProto = Object.getPrototypeOf(DOM);
|
||||
|
||||
Util.extend(DOMProto, {
|
||||
Notify: Notify
|
||||
});
|
||||
|
||||
function NotifyProto() {
|
||||
var Events = DOM.Events,
|
||||
Show, Allow,
|
||||
Notify = this,
|
||||
Notification = window.Notification;
|
||||
|
||||
Events.add({
|
||||
'blur' :function() {
|
||||
Show = true;
|
||||
},
|
||||
'focus': function() {
|
||||
Show = false;
|
||||
}
|
||||
}, window);
|
||||
|
||||
this.send = function(msg) {
|
||||
CloudCmd.getConfig(function(config) {
|
||||
var notify,
|
||||
notifications = config.notifications,
|
||||
focus = window.focus.bind(window),
|
||||
granted = Notify.check();
|
||||
|
||||
if (notifications && granted && Show) {
|
||||
notify = new Notification(msg, {
|
||||
icon: '/img/favicon/favicon-notify.png',
|
||||
});
|
||||
|
||||
Events.addClick(focus, notify);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
this.check = function () {
|
||||
var ret,
|
||||
Not = Notification,
|
||||
perm = Not && Not.permission;
|
||||
|
||||
if (perm === 'granted')
|
||||
ret = true;
|
||||
|
||||
return ret;
|
||||
};
|
||||
|
||||
this.request = function () {
|
||||
var Not = Notification;
|
||||
|
||||
if (Not)
|
||||
Not.requestPermission();
|
||||
};
|
||||
}
|
||||
})(Util, DOM);
|
||||
Loading…
Add table
Add a link
Reference in a new issue