From acf9601fafbc2f1d8411036956d9926c8d52115d Mon Sep 17 00:00:00 2001 From: coderaiser Date: Fri, 3 Jan 2014 09:35:04 +0000 Subject: [PATCH] feature(notify) add --- html/index.html | 1 + lib/client/dom.js | 51 ----------------------------------- lib/client/notify.js | 63 ++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 64 insertions(+), 51 deletions(-) create mode 100644 lib/client/notify.js diff --git a/html/index.html b/html/index.html index 150a73b6..83268de8 100644 --- a/html/index.html +++ b/html/index.html @@ -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', diff --git a/lib/client/dom.js b/lib/client/dom.js index daeaea1c..28b431bd 100644 --- a/lib/client/dom.js +++ b/lib/client/dom.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 } ]); diff --git a/lib/client/notify.js b/lib/client/notify.js new file mode 100644 index 00000000..2c265cc3 --- /dev/null +++ b/lib/client/notify.js @@ -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);