From a50bcdca77e1a9f2962670f1c8e1ab2f14510f02 Mon Sep 17 00:00:00 2001 From: janus_wel Date: Thu, 11 Dec 2008 17:57:10 +0000 Subject: follow HEAD - add "left" attr to hbox: clock.instance. - delete position settings. the clock position is fixed to right of commandline. - add ex-command ":clockjustify" add PLUGIN_INFO. git-svn-id: http://svn.coderepos.org/share/lang/javascript/vimperator-plugins/trunk@26435 d0d07461-0603-4401-acd4-de1884942a52 --- clock.js | 193 +++++++++++++++++++++++++++++++++++++++++++-------------------- 1 file changed, 131 insertions(+), 62 deletions(-) (limited to 'clock.js') diff --git a/clock.js b/clock.js index 358829a..3f8b246 100644 --- a/clock.js +++ b/clock.js @@ -1,57 +1,106 @@ -/* - * ==VimperatorPlugin== - * @name clock.js - * @description clock. - * @description-ja とけい。 - * @author janus_wel - * @version 0.14 - * @minversion 2.0pre - * @maxversion 2.0pre - * ==/VimperatorPlugin== - * - * LICENSE - * New BSD License - * - * USAGE - * you can customize below variables - * - * clock_format: clock format. default is '[%t]'. - * available special tokens: - * %t: time hh:mm - * %d: day MM/DD - * %y: year YYYY - * %a: A abbreviation for the day of the week. - * clock_position: id of element that is marker of insert position. - * default is 'liberator-commandline-command' ( after commandline ) - * clock_after: boolean that show insert after of the element - * specified by 'clock_position'. - * default is true. - * - * refer: http://d.hatena.ne.jp/janus_wel/20081128/1227849365 - * - * available commands - * - * :clockhide - * :clockappear - * :clockstop - * :clockstart - * - * EXAMPLE - * in .vimperatorrc - * - * let clock_format='(%t %d)' - * let clock_position='liberator-commandline-prompt' - * let clock_after='false' - * - * this exapmple show clock in before prompt. - * - * */ +let PLUGIN_INFO = + +{NAME} +clock +とけい +janus_wel +New BSD License +0.15 +2.0pre +2.0pre + + +; ( function () { // definitions --- // default settings -const format = liberator.globalVariables.clock_format || '[%t]'; +const format = liberator.globalVariables.clock_format || '[%t]'; // class definitions function Clock() { @@ -152,6 +201,8 @@ Clock.prototype = { generate: function () { let box = window.document.createElement('hbox'); box.setAttribute('id', this._constants.prefix + 'box'); + box.setAttribute('style', 'display: block;'); + box.setAttribute('class', 'liberator-container'); let format = this._format; let generator = this._constants.generator; @@ -188,8 +239,13 @@ Clock.prototype = { }, get instance() this._box, + get width() this._box.boxObject.width, + hide: function () this._box.setAttribute('style', 'display: none;'), appear: function () this._box.setAttribute('style', 'display: block;'), + + justify: function (parentWidth) this._box.setAttribute('left', parentWidth - this.width), + start: function () { let info = this._intervalInfo; for (let [k, i] in Iterator(info)) { @@ -210,26 +266,32 @@ Clock.prototype = { }; +// main --- +let commandlineStack = getCommandlineStack(); +if (!commandlineStack) { + let errmsg = 'clock.js: not found the commandline.'; + liberator.log(errmsg, 0); + liberator.echoerr(errmsg); + return; +} + +// build clock let clock = new Clock(format); clock.generate(); // insert -{ - let msg = window.document.getElementById('liberator-message'); - let stack = msg.parentNode; - let box = window.document.createElement('hbox'); - stack.replaceChild(box, msg); - box.appendChild(msg); - box.appendChild(clock.instance); - msg.inputField.QueryInterface(Components.interfaces.nsIDOMNSEditableElement); -} +commandlineStack.appendChild(clock.instance); +// why double? +clock.justify(commandlineStack.boxObject.width); +clock.justify(commandlineStack.boxObject.width); // register command [ - [['clockhide'], 'hide clock', function () clock.hide(), ], - [['clockappear'], 'clock appear', function () clock.appear(), ], - [['clockstart'], 'start clock', function () clock.start(), ], - [['clockstop'], 'stop clock', function () clock.stop(), ], + [['clockhide'], 'hide clock', function () clock.hide() ], + [['clockappear'], 'clock appear', function () clock.appear() ], + [['clockstart'], 'start clock', function () clock.start() ], + [['clockstop'], 'stop clock', function () clock.stop() ], + [['clockjustify'], 'justify', function () clock.justify(getCommandlineStack().boxObject.width) ], ].forEach( function ([n, d, f]) commands.addUserCommand(n, d, f, {}) ); @@ -260,6 +322,13 @@ function year() { return new Date().getFullYear().toString(10); } +// node control +function getCommandlineStack() { + let messageTextarea = window.document.getElementById('liberator-message'); + let commandlineStack = messageTextarea.parentNode; + return commandlineStack.localName === 'stack' ? commandlineStack : null; +} + // type conversion function stringToBoolean(str, defaultValue) { return !str ? (defaultValue ? true : false) -- cgit v1.2.3