diff options
author | damegane | 2008-08-08 15:15:04 +0000 |
---|---|---|
committer | damegane | 2008-08-08 15:15:04 +0000 |
commit | 27f6ae2db9dc327c6627c42d4871df0f0f0aaff9 (patch) | |
tree | 05e2df99dfb76255036479cbcd0123e60d97c1d6 /autofocus_canceller.js | |
parent | 43c5f3df82a43f77ecfa232a88b4bd6bdda6ea7c (diff) | |
download | vimperator-plugins-27f6ae2db9dc327c6627c42d4871df0f0f0aaff9.tar.bz2 |
initial release: onloadの自動フォーカスを無効にしたいplugin
git-svn-id: http://svn.coderepos.org/share/lang/javascript/vimperator-plugins/trunk@17275 d0d07461-0603-4401-acd4-de1884942a52
Diffstat (limited to 'autofocus_canceller.js')
-rw-r--r-- | autofocus_canceller.js | 88 |
1 files changed, 88 insertions, 0 deletions
diff --git a/autofocus_canceller.js b/autofocus_canceller.js new file mode 100644 index 0000000..3ffa563 --- /dev/null +++ b/autofocus_canceller.js @@ -0,0 +1,88 @@ +// Vimperator Plugin: Auto-Focus Canceller +// Version: 0.1 + +(function(){ + +const DEBUG = false; +var org_focus = {}; + +function disable_focus(){ + var doc = content.document; + + var input = doc.getElementsByTagName("input"); + if(input.length > 0){ + input = input[0]; + org_focus.input = input.wrappedJSObject.__proto__.focus; + input.wrappedJSObject.__proto__.focus = function(){}; + } + + var textarea = doc.getElementsByTagName("textarea"); + if(textarea.length > 0){ + textarea = textarea[0]; + org_focus.textarea = textarea.wrappedJSObject.__proto__.focus; + textarea.wrappedJSObject.__proto__.focus = function(){}; + } +} + +function enable_focus(){ + var doc = content.document; + + if(org_focus.input){ + var input = doc.getElementsByTagName("input"); + if(input.length > 0){ + input = input[0]; + input.wrappedJSObject.__proto__.focus = org_focus.input; + } + } + + if(org_focus.textarea){ + var textarea = doc.getElementsByTagName("textarea"); + if(textarea.length > 0){ + textarea = textarea[0]; + textarea.wrappedJSObject.__proto__.focus = org_focus.textarea; + } + } + + org_focus = {}; +} + +liberator.autocommands.add("PageLoad", + ".*", + ":autofocuscanceller" +); + +liberator.commands.addUserCommand( + ["autofocuscanceller"], + "", + function(){ + disable_focus(); + content.window.addEventListener("load", function(){ + setTimeout(function(){ + enable_focus(); + }, 1000); + }, false); + }, + null, true +); + +if(DEBUG){ + liberator.commands.addUserCommand( + ["disablefocus"], + "", + function(){ + disable_focus(); + }, + null, true + ); + + liberator.commands.addUserCommand( + ["enablefocus"], + "", + function(){ + enable_focus(); + }, + null, true + ); +} + +})(); |