diff options
author | janus_wel | 2008-11-29 03:38:06 +0000 |
---|---|---|
committer | janus_wel | 2008-11-29 03:38:06 +0000 |
commit | bb1f5f373fd71a77d6a47d472cb9a171a669e03f (patch) | |
tree | e323897dcd122aab46577720281a6353bf0c9624 | |
parent | 69be12535ab2dc2b44dfe61a05ce444f3935d1f5 (diff) | |
download | vimperator-plugins-bb1f5f373fd71a77d6a47d472cb9a171a669e03f.tar.bz2 |
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
-rw-r--r-- | clock.js | 26 |
1 files changed, 15 insertions, 11 deletions
@@ -4,7 +4,7 @@ * @description clock.
* @description-ja とけい。
* @author janus_wel <janus_wel@fb3.so-net.ne.jp>
- * @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;
|