Changeset 36957

Show
Ignore:
Timestamp:
03/08/10 03:13:37 (3 years ago)
Author:
anekos
Message:

-xpath -frame の修正

Files:
1 modified

Legend:

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

    r36950 r36957  
    4040  <description>feed some defined key events into the Web content</description> 
    4141  <description lang="ja">キーイベントをWebコンテンツ側に送る</description> 
    42   <version>1.7.0</version> 
     42  <version>1.7.1</version> 
    4343  <author mail="anekos@snca.net" homepage="http://d.hatena.ne.jp/nokturnalmortum/">anekos</author> 
    4444  <license>new BSD License (Please read the source code comments of this plugin)</license> 
     
    331331 
    332332  function or (list, func) 
    333     let ([head, tail] = list) 
    334       ((func || v)(head) || (tail && or(tail, func))); 
     333    (list.length && let ([head,] = list) (func(head) || or(list.slice(1), func))); 
    335334 
    336335  function getFrames () { 
     
    339338 
    340339    function get (content) 
    341       (bodyCheck(content) && result.push(content), Array.slice(content.frames).forEach(get)) 
     340      (bodyCheck(content) && result.push(content), Array.slice(content.frames).forEach(get)); 
    342341 
    343342    let result = []; 
     
    398397    try { 
    399398      RegExp(expr); 
     399      return true; 
     400    } catch (e) {} 
     401    return false; 
     402  } 
     403 
     404  function xpathValidator (expr) { 
     405    try { 
     406      document.evaluate(expr, document, null, null, null); 
    400407      return true; 
    401408    } catch (e) {} 
     
    495502  } 
    496503 
     504  function frameCompleter (context, args) { 
     505    return [ 
     506      [i, frame.document.location] 
     507      for each ([i, frame] in Iterator(getFrames())) 
     508    ]; 
     509  } 
     510 
    497511 
    498512 
     
    517531              let win = document.commandDispatcher.focusedWindow; 
    518532              let frames = getFrames(); 
     533 
    519534              let elem = body(win); 
    520535 
     
    524539              } 
    525540 
    526               if (args['-xpath']) 
    527                 elem = or(frames, function (f) fromXPath(f, args['-xpath'])) || elem; 
     541              if (args['-xpath']) { 
     542                elem = or(frames, function (f) fromXPath(f.document, args['-xpath'])) || elem; 
     543              } 
    528544 
    529545              feed(rhs, args['-events'] || ['keypress'], elem); 
     
    566582          [['-urls', '-u'], commands.OPTION_STRING, regexpValidator, urlCompleter({currentURL: true})], 
    567583          [['-desc', '-description'], commands.OPTION_STRING], 
    568           [['-frame', '-f'], commands.OPTION_INT], 
     584          [['-frame', '-f'], commands.OPTION_INT, null, frameCompleter], 
     585          [['-xpath', '-x'], commands.OPTION_STRING, xpathValidator], 
    569586          [ 
    570587            ['-events', '-e'],