Changeset 34875

Show
Ignore:
Timestamp:
08/15/09 11:03:06 (4 years ago)
Author:
anekos
Message:

微妙にやり方を変えてみる

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • lang/javascript/vimperator-plugins/trunk/auto-focus-frame.js

    r34522 r34875  
    3939  <description>Automatically focus to largest frame.</description> 
    4040  <description lang="ja">最も大きなフレームに自動的にフォーカスする。</description> 
    41   <version>1.0.6</version> 
     41  <version>1.0.7</version> 
    4242  <author mail="anekos@snca.net" homepage="http://d.hatena.ne.jp/nokturnalmortum/">anekos</author> 
    4343  <license>new BSD License (Please read the source code comments of this plugin)</license> 
     
    5353    == Usage == 
    5454      インストールするだけ 
     55      一番面積の大きいフレームをフォーカスします 
    5556  ]]></detail> 
    5657</VimperatorPlugin>; 
     
    5960(function () { 
    6061 
    61   autocommands.add( 
    62     'DOMLoad', 
    63     '.*', 
    64     function () { 
    65       function doFocus () { 
    66         let [maxSize, maxFrame] = [-1, null]; 
    67         for (let frame in util.Array.itervalues(content.frames)) { 
    68           try { 
    69             if (!(frame.frameElement instanceof HTMLFrameElement)) 
    70               continue; 
    71             if (frame.scrollMaxX <= 0 && frame.scrollMaxY <= 0) 
    72               continue; 
    73             let size = frame.innerWidth * frame.innerHeight; 
    74             if (maxSize < size) { 
    75               maxSize = size; 
    76               maxFrame = frame; 
    77             } 
    78           } catch (e) { 
    79             liberator.log(e) 
     62  function onLoad () { 
     63    function doFocus () { 
     64      let [maxSize, maxFrame] = [-1, null]; 
     65      for (let frame in util.Array.itervalues(content.frames)) { 
     66        try { 
     67          if (!(frame.frameElement instanceof HTMLFrameElement)) 
    8068            continue; 
     69          if (frame.scrollMaxX <= 0 && frame.scrollMaxY <= 0) 
     70            continue; 
     71          let size = frame.innerWidth * frame.innerHeight; 
     72          if (maxSize < size) { 
     73            maxSize = size; 
     74            maxFrame = frame; 
    8175          } 
     76        } catch (e) { 
     77          liberator.log(e) 
     78          continue; 
    8279        } 
    83         if (maxFrame) 
    84           maxFrame.focus(); 
    8580      } 
     81      if (maxFrame) 
     82        maxFrame.focus(); 
     83    } 
    8684 
    87  
    88       if (!(window.content.document instanceof HTMLDocument)) 
    89           return; 
    90       if (content.frames.length <= 1) 
     85    if (!(window.content.document instanceof HTMLDocument)) 
    9186        return; 
    9287 
    93       let nframes = content.frames.length; 
    94       for (let frame in util.Array.itervalues(content.frames)) { 
    95         if (frame.frameElement instanceof HTMLFrameElement) { 
     88    if (content.frames.length <= 1) 
     89      return; 
     90 
     91    let nframes = content.frames.length; 
     92 
     93    function callDoFocus () { 
     94      if (!--nframes) 
     95        doFocus(); 
     96    } 
     97 
     98    for (let frame in util.Array.itervalues(content.frames)) { 
     99      if (frame.frameElement instanceof HTMLFrameElement) { 
     100        if (frame.body) { 
     101          callDoFocus(); 
     102        } else { 
    96103          frame.addEventListener( 
    97104            'DOMContentLoaded', 
    98105            function () { 
    99106              frame.removeEventListener('DOMContentLoaded', arguments.callee, true); 
    100               if (!--nframes) 
    101                 doFocus(); 
     107              callDoFocus(); 
    102108            }, 
    103109            true 
     
    105111        } 
    106112      } 
     113    } 
     114  } 
    107115 
    108     } 
    109   ); 
     116  autocommands.add('DOMLoad', '.*', onLoad); 
    110117 
    111118})();