Changeset 36881

Show
Ignore:
Timestamp:
03/01/10 21:22:31 (3 years ago)
Author:
anekos
Message:

XPath 指定対応

Files:
1 modified

Legend:

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

    r36880 r36881  
    134134  }; 
    135135 
     136  function id (v) 
     137    v; 
     138 
     139  function or (list, func) 
     140    let ([head, tail] = list) 
     141      ((func || v)(head) || (tail && or(tail, func))); 
     142 
    136143  function getFrames () { 
    137144    function bodyCheck (content) 
     
    144151    get(content); 
    145152    return result; 
     153  } 
     154 
     155  function fromXPath (doc, xpath) { 
     156    let result = util.evaluateXPath(xpath, doc); 
     157    return result.snapshotLength && result.snapshotItem(0); 
    146158  } 
    147159 
     
    197209            args['description'] || 'by feedSomeKeys_3.js', 
    198210            function () { 
     211              let win = document.commandDispatcher.focusedWindow; 
    199212              let frames = getFrames(); 
    200               let elem = document.commandDispatcher.focusedWindow; 
     213              let elem = win; 
    201214 
    202215              if (typeof args['-frame'] !== 'undefined') { 
    203216                frames = [frames[args['-frame']]]; 
    204217                elem = frames[0]; 
     218              } 
     219 
     220              if (args['-xpath']) 
     221                elem = or(frames, function (f) fromXPath(args['-xpath'])); 
     222 
     223              if (!elem) { 
     224                liberator.log('feedSomeKeys_3: Not found target element'); 
     225                elem = win; 
    205226              } 
    206227