aboutsummaryrefslogtreecommitdiffstats
path: root/notifier
diff options
context:
space:
mode:
authorsuVene2008-12-06 18:51:26 +0000
committersuVene2008-12-06 18:51:26 +0000
commit90723baa596d15b60f8e7d58fe14c12c47bfc728 (patch)
tree2d76664bcfbadb991b7a0d205804d243ad55ad30 /notifier
parentf417812b520e599923e346715dc455021db1ceff (diff)
downloadvimperator-plugins-90723baa596d15b60f8e7d58fe14c12c47bfc728.tar.bz2
変更通知framework.& それを利用したGrowl風plugin(途中)
git-svn-id: http://svn.coderepos.org/share/lang/javascript/vimperator-plugins/trunk@26017 d0d07461-0603-4401-acd4-de1884942a52
Diffstat (limited to 'notifier')
-rw-r--r--notifier/jquery.jgrowl.css87
-rw-r--r--notifier/observer_growl.js120
-rw-r--r--notifier/subject_test.js52
3 files changed, 259 insertions, 0 deletions
diff --git a/notifier/jquery.jgrowl.css b/notifier/jquery.jgrowl.css
new file mode 100644
index 0000000..5cbd9ed
--- /dev/null
+++ b/notifier/jquery.jgrowl.css
@@ -0,0 +1,87 @@
+
+div.observer_growl {
+ padding: 10px;
+ z-index: 9999;
+}
+
+/** Normal Style Positions **/
+body > div.observer_growl {
+ position: fixed;
+}
+
+body > div.observer_growl.top-left {
+ left: 0px;
+ top: 0px;
+}
+
+body > div.observer_growl.top-right {
+ right: 0px;
+ top: 0px;
+}
+
+body > div.observer_growl.bottom-left {
+ left: 0px;
+ bottom: 0px;
+}
+
+body > div.observer_growl.bottom-right {
+ right: 0px;
+ bottom: 0px;
+}
+
+body > div.observer_growl.center {
+ top: 0px;
+ width: 50%;
+ left: 25%;
+}
+
+/** Cross Browser Styling **/
+div.center div.observer_growl_notification, div.center div.observer_growl-closer {
+ margin-left: auto;
+ margin-right: auto;
+}
+
+div.observer_growl div.observer_growl_notification, div.observer_growl div.observer_growl-closer {
+ background-color: #000;
+ color: #fff;
+ opacity: .85;
+ filter: alpha(opacity = 85);
+ zoom: 1;
+ width: 235px;
+ padding: 10px;
+ margin-top: 5px;
+ margin-bottom: 5px;
+ font-family: Tahoma, Arial, Helvetica, sans-serif;
+ font-size: 12px;
+ text-align: left;
+ display: none;
+ -moz-border-radius: 5px;
+ -webkit-border-radius: 5px;
+}
+
+div.observer_growl div.observer_growl_notification {
+ min-height: 40px;
+}
+
+div.observer_growl div.observer_growl_notification div.header {
+ font-weight: bold;
+ font-size: 10px;
+}
+
+div.observer_growl div.observer_growl_notification div.close {
+ float: right;
+ font-weight: bold;
+ font-size: 12px;
+ cursor: pointer;
+}
+
+div.observer_growl div.observer_growl-closer {
+ height: 15px;
+ padding-top: 4px;
+ padding-bottom: 4px;
+ cursor: pointer;
+ font-size: 11px;
+ font-weight: bold;
+ text-align: center;
+}
+
diff --git a/notifier/observer_growl.js b/notifier/observer_growl.js
new file mode 100644
index 0000000..b6f1d96
--- /dev/null
+++ b/notifier/observer_growl.js
@@ -0,0 +1,120 @@
+/**
+ * notifier.js plugin observer
+ * @name observer_growl.js
+ * @description growl when notified.
+ * @description-ja Growl風通知。
+ * @author suVene suvene@zeromemory.info
+ * @version 0.1.0
+ * Last Change: 07-Dec-2008.
+ *
+ * use JQuery
+ * http://jquery.com/
+ * use JGrowl
+ * http://stanlemon.net/projects/jgrowl.html
+ */
+(function() {
+
+var notifier = liberator.plugins.notifier;
+if (!notifier) return;
+
+var lib = notifier.lib;
+var $U = lib.$U;
+var logger = $U.getLogger('observer_growl');
+
+var Growl = function() {//{{{
+ this.initialize.apply(this, arguments);
+}
+Growl.prototype = {
+ defaults: {
+ life: 3000
+ },
+ initialize: function(dom, container) {
+ this.dom = dom;
+ this.container = container;
+ this.created = new Date();
+ this.life = this.defaults.life;
+ dom.childNodes[0].addEventListener("click", $U.bind(this, this.remove), false);
+ },
+ remove: function() {
+ this.container.removeChild(this.dom);
+ },
+
+}//}}}
+
+notifier.observer.register({
+ initialize: function () {
+ logger.log('initialize');
+ this.count = 1;
+
+ io.getRuntimeDirectories('').forEach(function(dir) {
+ let path = io.expandPath(dir.path + '/plugin/notifier');
+ $U.readDirectory(path, '^jquery' , function(f) {
+ try {
+ io.source(f.path, true)
+ logger.log('load success: ' + f.leafName);
+ } catch (e) {
+ logger.log('load failed: ' + f.leafName);
+ }
+ });
+ });
+ },
+ update: function(message) {
+ logger.log('update:' + this.count);
+
+ var doc = window.content.document;
+ var container = doc.getElementById("observer_growl");
+ if (!container) {
+ doc.body.appendChild(util.xmlToDom(<div id="observer_growl" class="observer_growl top-right" />, doc));
+ container = doc.getElementById("observer_growl");
+ }
+
+ this.createPopup(doc, message, container);
+ container.appendChild(this.createPopup(doc, message, container));
+
+ if (container.childNodes.length == 1) {
+ var interval = setInterval($U.bind(this, this.checkStatus), 1000);
+ container.__interval__ = interval;
+ }
+
+ this.count++;
+ },
+ createPopup: function(doc, message, nodes) {
+ var dom;
+ var html =
+ <div class="observer_growl_notification" style="display: block;">
+ <div class="close">&#215;</div>
+ <div class="header">{util.escapeHTML(this.count + ': ' + message.title)}</div>
+ <div class="message">{util.escapeHTML(message.message)}</div>
+ </div>;
+ dom = util.xmlToDom(html, doc, nodes);
+ dom.__data__ = new Growl(dom, nodes);
+
+ let count = this.count;
+ return dom;
+ },
+ checkStatus: function() {
+
+ var doc = window.content.document;
+ var container = doc.getElementById("observer_growl");
+ if (!container) return;
+
+ var removeNodes = [];
+ for (let i = 0, len = container.childNodes.length; i < len; i++) {
+ let item = container.childNodes[i];
+ let growl = item.__data__;
+ if (growl && growl.created &&
+ growl.created.getTime() + growl.life < (new Date()).getTime()) {
+ removeNodes.push(item);
+ }
+ }
+ removeNodes.forEach(function(n) container.removeChild(n));
+
+ if (container.childNodes.length == 0)
+ clearInterval(container.__interval__);
+
+ }
+});
+
+})();
+// vim: set fdm=marker sw=4 ts=4 sts=0 et:
+
diff --git a/notifier/subject_test.js b/notifier/subject_test.js
new file mode 100644
index 0000000..b5689c6
--- /dev/null
+++ b/notifier/subject_test.js
@@ -0,0 +1,52 @@
+/**
+ * notifier.js plugin subject
+ * @name subject_test.js
+ * @description notify if ...
+ * @description-ja ... の時ポップアップ通知。
+ * @author suVene suvene@zeromemory.info
+ * @version 0.1.0
+ * Last Change: 07-Dec-2008.
+ */
+(function() {
+
+var notifier = liberator.plugins.notifier;
+if (!notifier) return;
+
+var lib = notifier.lib;
+var $U = lib.$U;
+var logger = $U.getLogger('subject_test');
+
+notifier.subject.register({
+ interval: 3,
+ initialize: function() {
+ logger.log('initialize');
+ this.count = 0;
+ },
+ check: function() {
+ this.count++;
+ logger.log('check');
+ var req = new lib.Request(
+ 'http://localhost:8080/index.html',
+ null, // headers {}
+ {
+ encode: 'shift_jis'
+ }
+ );
+ req.addEventListener('onSuccess', $U.bind(this, function(res) {
+ var text = res.responseText;
+ logger.log('success!! ');
+ var message = new notifier.Message('TEST', text);
+ this.notify(message);
+
+ if (this.count == 5) {
+ notifier.subject.unregister(this);
+ this.count = 0;
+ }
+ }));
+ req.get();
+ }
+});
+
+})();
+// vim: set fdm=marker sw=4 ts=4 sts=0 et:
+