Show
Ignore:
Timestamp:
11/29/08 12:38:06 (6 weeks ago)
Author:
janus_wel
Message:

the process to convert type from string to boolean cut off to function stringToBoolean().

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • lang/javascript/vimperator-plugins/trunk/clock.js

    r25296 r25326  
    55 * @description-ja  とけい。 
    66 * @author          janus_wel <janus_wel@fb3.so-net.ne.jp> 
    7  * @version         0.12 
     7 * @version         0.13 
    88 * @minversion      2.0pre 
    99 * @maxversion      2.0pre 
     
    5454const format   = liberator.globalVariables.clock_format   || '[%t]'; 
    5555const position = liberator.globalVariables.clock_position || 'liberator-commandline-command'; 
    56 let atemp      = liberator.globalVariables.clock_after; 
    57 const after =   (atemp === undefined)             ? true 
    58               : (atemp.toLowerCase() === 'false') ? false 
    59               : (/^\d+$/.test(atemp))             ? parseInt(atemp, 10) 
    60               :                                     true; 
     56const after    = stringToBoolean(liberator.globalVariables.clock_after, true); 
    6157 
    6258// class definitions 
     
    228224clock.generate(); 
    229225 
    230 // appendChild 
     226// insert 
    231227after 
    232228    ? insertNodeAfterSpecified(clock.instance, insertBase) 
     
    235231// register command 
    236232[ 
    237     [['clockhide'],   'hide clock',   function () clock.hide(), ], 
     233    [['clockhide'],   'hide clock',   function () clock.hide(),   ], 
    238234    [['clockappear'], 'clock appear', function () clock.appear(), ], 
    239     [['clockstart'],  'start clock',  function () clock.start(), ], 
    240     [['clockstop'],   'stop clock',   function () clock.stop(), ], 
    241 ].forEach( function ([names, desc, func]) commands.addUserCommand(names, desc, func, {}) ); 
     235    [['clockstart'],  'start clock',  function () clock.start(),  ], 
     236    [['clockstop'],   'stop clock',   function () clock.stop(),   ], 
     237].forEach( function ([n, d, f]) commands.addUserCommand(n, d, f, {}) ); 
    242238 
    243239 
     
    282278    } 
    283279} 
     280 
     281// type conversion 
     282function stringToBoolean(str, defaultValue) { 
     283return !str                          ? (defaultValue ? true : false) 
     284     : str.toLowerCase() === 'false' ? false 
     285     : /^\d+$/.test(str)             ? (parseInt(str) ? true : false) 
     286     :                                 true; 
     287} 
    284288} )(); 
    285289