feature(notify) add

This commit is contained in:
coderaiser 2014-01-03 09:35:04 +00:00
parent b7e8c929b6
commit acf9601faf
3 changed files with 64 additions and 51 deletions

View file

@ -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',

View file

@ -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
View 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);