Show
Ignore:
Timestamp:
12/01/08 07:17:10 (6 weeks ago)
Author:
drry
Message:
  • fixed a regex.
  • et cetera.
Files:
1 modified

Legend:

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

    r25470 r25492  
    1 /* 
     1/** 
    22 * ==VimperatorPlugin== 
    33 * @name toggler 
     
    4141Toggler.prototype = { 
    4242        next: function(notUpdate){ 
    43                 let index = this.index + 1; 
     43                var index = this.index + 1; 
    4444                if (index >= this.cmds.length) index = 0; 
    4545                if (!notUpdate) this.index = index; 
     
    4747        }, 
    4848        previous: function(notUpdate){ 
    49                 let index = this.index - 1; 
     49                var index = this.index - 1; 
    5050                if (index < 0) index = this.cmds.length -1; 
    5151                if (!notUpdate) this.index = index; 
     
    5353        }, 
    5454        list: function(){ 
    55                 var data = []; 
    56                 for (var i = 0; i<this.cmds.length; i++){ 
    57                         data.push([i==this.index ? "*":"", this.cmds[i]]); 
    58                 } 
     55                var data = this.cmds.map(function(cmd, i){ 
     56                        return [i==this.index ? "*" : "", cmd]; 
     57                }); 
    5958                liberator.echo(template.table(this.name, data), true); 
    6059        } 
     
    7675        }, 
    7776        toggle: function(name, isPrevious){ 
    78                 let toggler = this.get(name); 
     77                var toggler = this.get(name); 
    7978                if (!toggler) return; 
    80                 let cmd = isPrevious ? toggler.previous() : toggler.next(); 
     79                var cmd = isPrevious ? toggler.previous() : toggler.next(); 
    8180                if (cmd instanceof Array){ 
    82                         cmd.forEach(function(str){ 
    83                                 liberator.execute(str); 
    84                         }); 
     81                        cmd.forEach(liberator.execute); 
    8582                } else if (typeof cmd == "function"){ 
    8683                        cmd(); 
     
    9491                        return; 
    9592                } 
    96                 for (let i in settings){ 
    97                         settings[i].list(); 
     93                for each (let setting in settings){ 
     94                        setting.list(); 
    9895                } 
    9996        } 
    10097}; 
    10198 
    102 commands.addUserCommand(['toggle'],'setting toggler', 
     99commands.addUserCommand(["toggle"],"setting toggler", 
    103100        function(args){ 
    104101                if (args["-list"] || args.length == 0){ 
     
    106103                                liberator.plugins.toggler.list(); 
    107104                        else 
    108                                 args.forEach(function(name) liberator.plugins.toggler.list(name)); 
     105                                args.forEach(liberator.plugins.toggler.list); 
    109106                        return; 
    110107                } 
     
    119116                ], 
    120117                completer: function(context,args){ 
    121                         let filter = context.filter.split(/\s+/).pop(); 
    122                         let reg = new RegExp(filter ? "^" + flter : ".*", "i"); 
     118                        var filter = context.filter.split(/\s+/).pop(); 
     119                        var reg = new RegExp(filter ? "^" + flter : ""); 
    123120                        context.title= ["Name", args.bang ? "Previous" : "Next"]; 
    124                         let list = []; 
     121                        var list = []; 
    125122                        for (let i in settings){ 
    126123                                let toggler = settings[i]; 
    127                                 if (reg.test(i) && !args.some(function(arg) arg==i)) 
     124                                if (reg.test(i.toLowerCase()) && !args.some(function(arg) arg==i)) 
    128125                                        list.push([i, args.bang ? toggler.previous(true) : toggler.next(true)]); 
    129126                        }