Changeset 34522

Show
Ignore:
Timestamp:
07/22/09 06:10:09 (4 years ago)
Author:
anekos
Message:

フレームのロードが遅いときに正常に動作しないのを修正

Files:
1 modified

Legend:

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

    r32501 r34522  
    3939  <description>Automatically focus to largest frame.</description> 
    4040  <description lang="ja">最も大きなフレームに自動的にフォーカスする。</description> 
    41   <version>1.0.5</version> 
     41  <version>1.0.6</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> 
     
    4545  <updateURL>http://svn.coderepos.org/share/lang/javascript/vimperator-plugins/trunk/auto-focus-frame.js</updateURL> 
    4646  <minVersion>2.0</minVersion> 
    47   <maxVersion>2.1pre</maxVersion> 
     47  <maxVersion>2.2pre</maxVersion> 
    4848  <detail><![CDATA[ 
    4949    == Usage == 
     
    6363    '.*', 
    6464    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) 
     80            continue; 
     81          } 
     82        } 
     83        if (maxFrame) 
     84          maxFrame.focus(); 
     85      } 
     86 
     87 
    6588      if (!(window.content.document instanceof HTMLDocument)) 
    6689          return; 
    6790      if (content.frames.length <= 1) 
    6891        return; 
    69       let [maxSize, maxFrame] = [-1, null]; 
     92 
     93      let nframes = content.frames.length; 
    7094      for (let frame in util.Array.itervalues(content.frames)) { 
    71         try { 
    72           if (!(frame.frameElement instanceof HTMLFrameElement)) 
    73             continue; 
    74           if (frame.scrollMaxX <= 0 && frame.scrollMaxY <= 0) 
    75               continue; 
    76           let size = frame.innerWidth * frame.innerHeight; 
    77           if (maxSize < size) { 
    78             maxSize = size; 
    79             maxFrame = frame; 
    80           } 
    81         } catch (e) { 
    82           liberator.log(e) 
    83           continue; 
     95        if (frame.frameElement instanceof HTMLFrameElement) { 
     96          frame.addEventListener( 
     97            'DOMContentLoaded', 
     98            function () { 
     99              frame.removeEventListener('DOMContentLoaded', arguments.callee, true); 
     100              if (!--nframes) 
     101                doFocus(); 
     102            }, 
     103            true 
     104          ); 
    84105        } 
    85106      } 
    86       if (maxFrame) 
    87         maxFrame.focus(); 
     107 
    88108    } 
    89109  );