From bb1f5f373fd71a77d6a47d472cb9a171a669e03f Mon Sep 17 00:00:00 2001 From: janus_wel Date: Sat, 29 Nov 2008 03:38:06 +0000 Subject: the process to convert type from string to boolean cut off to function stringToBoolean(). git-svn-id: http://svn.coderepos.org/share/lang/javascript/vimperator-plugins/trunk@25326 d0d07461-0603-4401-acd4-de1884942a52 --- clock.js | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) (limited to 'clock.js') diff --git a/clock.js b/clock.js index 1f65961..12b26e1 100644 --- a/clock.js +++ b/clock.js @@ -4,7 +4,7 @@ * @description clock. * @description-ja とけい。 * @author janus_wel - * @version 0.12 + * @version 0.13 * @minversion 2.0pre * @maxversion 2.0pre * ==/VimperatorPlugin== @@ -53,11 +53,7 @@ // default settings const format = liberator.globalVariables.clock_format || '[%t]'; const position = liberator.globalVariables.clock_position || 'liberator-commandline-command'; -let atemp = liberator.globalVariables.clock_after; -const after = (atemp === undefined) ? true - : (atemp.toLowerCase() === 'false') ? false - : (/^\d+$/.test(atemp)) ? parseInt(atemp, 10) - : true; +const after = stringToBoolean(liberator.globalVariables.clock_after, true); // class definitions function Clock() { @@ -227,18 +223,18 @@ if (!insertBase) { let clock = new Clock(format); clock.generate(); -// appendChild +// insert after ? insertNodeAfterSpecified(clock.instance, insertBase) : insertNodeBeforeSpecified(clock.instance, insertBase); // register command [ - [['clockhide'], 'hide clock', function () clock.hide(), ], + [['clockhide'], 'hide clock', function () clock.hide(), ], [['clockappear'], 'clock appear', function () clock.appear(), ], - [['clockstart'], 'start clock', function () clock.start(), ], - [['clockstop'], 'stop clock', function () clock.stop(), ], -].forEach( function ([names, desc, func]) commands.addUserCommand(names, desc, func, {}) ); + [['clockstart'], 'start clock', function () clock.start(), ], + [['clockstop'], 'stop clock', function () clock.stop(), ], +].forEach( function ([n, d, f]) commands.addUserCommand(n, d, f, {}) ); // stuff functions --- @@ -281,6 +277,14 @@ function insertNodeAfterSpecified(inserted, specified) { return specified.parentNode.appendChild(inserted); } } + +// type conversion +function stringToBoolean(str, defaultValue) { +return !str ? (defaultValue ? true : false) + : str.toLowerCase() === 'false' ? false + : /^\d+$/.test(str) ? (parseInt(str) ? true : false) + : true; +} } )(); // vim: set sw=4 ts=4 et; -- cgit v1.2.3