From be5ba884146a0d8d6e4679f5d1245c7ea6754554 Mon Sep 17 00:00:00 2001 From: anekos Date: Sat, 15 Aug 2009 03:04:41 +0000 Subject: autocmd を使わないようにしてみた git-svn-id: http://svn.coderepos.org/share/lang/javascript/vimperator-plugins/trunk@34876 d0d07461-0603-4401-acd4-de1884942a52 --- auto-focus-frame.js | 73 +++++++++++++++++------------------------------------ 1 file changed, 23 insertions(+), 50 deletions(-) (limited to 'auto-focus-frame.js') diff --git a/auto-focus-frame.js b/auto-focus-frame.js index 3ea65ee..aa747a9 100644 --- a/auto-focus-frame.js +++ b/auto-focus-frame.js @@ -38,7 +38,7 @@ let PLUGIN_INFO = Auto focus frame Automatically focus to largest frame. 最も大きなフレームに自動的にフォーカスする。 - 1.0.7 + 1.0.8 anekos new BSD License (Please read the source code comments of this plugin) 修正BSDライセンス (ソースコードのコメントを参照してください) @@ -60,60 +60,33 @@ let PLUGIN_INFO = (function () { 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 (!(window.content.document instanceof HTMLDocument)) - return; + liberator.log('auto-focus-frame.js - onLoad'); - if (content.frames.length <= 1) + if (!(window.content.document instanceof HTMLDocument) || (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); - callDoFocus(); - }, - true - ); - } - } - } + liberator.log('auto-focus-frame.js - onLoad'); + + let targetFrames = [ + frame + for (frame in util.Array.itervalues(content.frames)) + if (frame.frameElement instanceof HTMLFrameElement) + ]; + + let [maxSize, maxFrame] = [-1, null]; + targetFrames.forEach(function(frame) { + if (frame.scrollMaxX <= 0 && frame.scrollMaxY <= 0) + return; + let size = frame.innerWidth * frame.innerHeight; + if (maxSize < size) + [maxSize, maxFrame] = [size, frame]; + }); + if (maxFrame) + maxFrame.focus(); } - autocommands.add('DOMLoad', '.*', onLoad); + tabs.getBrowser().addEventListener("DOMContentLoaded", onLoad, true); + })(); -- cgit v1.2.3