// Vimperator plugin: 'Walk Input' // Last Change: 2009-01-25 // License: BSD // Version: 1.1 // Maintainer: Takayama Fumihiko // ------------------------------------------------------------ // The focus walks & // // PLUGIN_INFO {{{ let INFO = Takayama Fumihiko BSD

The focus walks <input> & <textarea> element. If you type first, the focus moves to "<input name='search' />". Then if you type once more, the focus moves to "<input name='name' />".

xxx yyy zzz ]]> i_ ]]> <M-i> <A-i>

Move focus forward

i_ ]]> <M-S-i> <A-S-i>

Move focus backward

; // }}} (function () { var xpath = '//input[@type="text" or @type="password" or @type="search" or not(@type)] | //textarea'; var walkinput = function (forward) { var focused = document.commandDispatcher.focusedElement; var current = null; var next = null; var prev = null; var list = []; (function (frame) { var doc = frame.document; if (doc.body.localName.toLowerCase() == 'body') { let r = doc.evaluate(xpath, doc, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null); for (let i = 0, l = r.snapshotLength; i < l; ++i) { let e = r.snapshotItem(i); if (/^none$/i.test(getComputedStyle(e, '').display)) continue; let ef = {element: e, frame: frame}; list.push(ef); if (e == focused) { current = ef; } else if (current && !next) { next = ef; } else if (!current) { prev = ef; } } } for (let i = 0; i < frame.frames.length; i++) arguments.callee(frame.frames[i]); })(content); if (list.length <= 0) return; var elem = forward ? (next || list[0]) : (prev || list[list.length - 1]); if (!current || current.frame != elem.frame) elem.frame.focus(); elem.element.focus(); }; mappings.addUserMap([modes.NORMAL, modes.INSERT], ['', ''], 'Walk Input Fields (Forward)', function () walkinput(true)); mappings.addUserMap([modes.NORMAL, modes.INSERT], ['', ''], 'Walk Input Fields (Backward)', function () walkinput(false)); })();