aboutsummaryrefslogtreecommitdiffstats
path: root/auto-focus-frame.js
diff options
context:
space:
mode:
authoranekos2009-08-15 02:03:06 +0000
committeranekos2009-08-15 02:03:06 +0000
commit954539636920a3105ec410701619337a5b06aef7 (patch)
tree43fd91a0cc70ce4dfadb703bf29e53f74ecc63eb /auto-focus-frame.js
parent6a889c28bf3bed4a9c1578c6572bbfd175be6cdf (diff)
downloadvimperator-plugins-954539636920a3105ec410701619337a5b06aef7.tar.bz2
微妙にやり方を変えてみる
git-svn-id: http://svn.coderepos.org/share/lang/javascript/vimperator-plugins/trunk@34875 d0d07461-0603-4401-acd4-de1884942a52
Diffstat (limited to 'auto-focus-frame.js')
-rw-r--r--auto-focus-frame.js73
1 files changed, 40 insertions, 33 deletions
diff --git a/auto-focus-frame.js b/auto-focus-frame.js
index 0a71f7c..3ea65ee 100644
--- a/auto-focus-frame.js
+++ b/auto-focus-frame.js
@@ -38,7 +38,7 @@ let PLUGIN_INFO =
<name>Auto focus frame</name>
<description>Automatically focus to largest frame.</description>
<description lang="ja">最も大きなフレームに自動的にフォーカスする。</description>
- <version>1.0.6</version>
+ <version>1.0.7</version>
<author mail="anekos@snca.net" homepage="http://d.hatena.ne.jp/nokturnalmortum/">anekos</author>
<license>new BSD License (Please read the source code comments of this plugin)</license>
<license lang="ja">修正BSDライセンス (ソースコードのコメントを参照してください)</license>
@@ -52,61 +52,68 @@ let PLUGIN_INFO =
<detail lang="ja"><![CDATA[
== Usage ==
インストールするだけ
+ 一番面積の大きいフレームをフォーカスします
]]></detail>
</VimperatorPlugin>;
// }}}
(function () {
- autocommands.add(
- 'DOMLoad',
- '.*',
- function () {
- function doFocus () {
- let [maxSize, maxFrame] = [-1, null];
- for (let frame in util.Array.itervalues(content.frames)) {
- try {
- if (!(frame.frameElement instanceof HTMLFrameElement))
- continue;
- if (frame.scrollMaxX <= 0 && frame.scrollMaxY <= 0)
- continue;
- let size = frame.innerWidth * frame.innerHeight;
- if (maxSize < size) {
- maxSize = size;
- maxFrame = frame;
- }
- } catch (e) {
- liberator.log(e)
+ function onLoad () {
+ function doFocus () {
+ let [maxSize, maxFrame] = [-1, null];
+ for (let frame in util.Array.itervalues(content.frames)) {
+ try {
+ if (!(frame.frameElement instanceof HTMLFrameElement))
+ continue;
+ if (frame.scrollMaxX <= 0 && frame.scrollMaxY <= 0)
continue;
+ let size = frame.innerWidth * frame.innerHeight;
+ if (maxSize < size) {
+ maxSize = size;
+ maxFrame = frame;
}
+ } catch (e) {
+ liberator.log(e)
+ continue;
}
- if (maxFrame)
- maxFrame.focus();
}
+ if (maxFrame)
+ maxFrame.focus();
+ }
-
- if (!(window.content.document instanceof HTMLDocument))
- return;
- if (content.frames.length <= 1)
+ if (!(window.content.document instanceof HTMLDocument))
return;
- let nframes = content.frames.length;
- for (let frame in util.Array.itervalues(content.frames)) {
- if (frame.frameElement instanceof HTMLFrameElement) {
+ if (content.frames.length <= 1)
+ return;
+
+ let nframes = content.frames.length;
+
+ function callDoFocus () {
+ if (!--nframes)
+ doFocus();
+ }
+
+ for (let frame in util.Array.itervalues(content.frames)) {
+ if (frame.frameElement instanceof HTMLFrameElement) {
+ if (frame.body) {
+ callDoFocus();
+ } else {
frame.addEventListener(
'DOMContentLoaded',
function () {
frame.removeEventListener('DOMContentLoaded', arguments.callee, true);
- if (!--nframes)
- doFocus();
+ callDoFocus();
},
true
);
}
}
-
}
- );
+ }
+
+ autocommands.add('DOMLoad', '.*', onLoad);
})();