diff options
author | anekos | 2008-08-19 15:14:14 +0000 |
---|---|---|
committer | anekos | 2008-08-19 15:14:14 +0000 |
commit | 95526e63cd38a3ecc47123d575760266244f794d (patch) | |
tree | c2699c02c0ecb9b4d5c64b4f0d503aa14acd99a3 /scroll_div.js | |
parent | 736f14537db10911c2aaa76997377c5d3f182445 (diff) | |
download | vimperator-plugins-95526e63cd38a3ecc47123d575760266244f794d.tar.bz2 |
スクロール量を自動的に決定するようにした。
git-svn-id: http://svn.coderepos.org/share/lang/javascript/vimperator-plugins/trunk@17916 d0d07461-0603-4401-acd4-de1884942a52
Diffstat (limited to 'scroll_div.js')
-rw-r--r-- | scroll_div.js | 54 |
1 files changed, 29 insertions, 25 deletions
diff --git a/scroll_div.js b/scroll_div.js index 7d71310..c390aec 100644 --- a/scroll_div.js +++ b/scroll_div.js @@ -1,18 +1,29 @@ -(function () { +// ==VimperatorPlugin== +// @name Div Scroller +// @description-ja スクロールができる div 要素などでスクロールする +// @license Creative Commons 2.1 (Attribution + Share Alike) +// @version 0.1 +// ==/VimperatorPlugin== +// +// Mappings: +// ]d [d +// スクロール対象を変更 +// ]f [f のようなもの +// <Leader>j <Leader>k +// スクロールする +// - let re = /auto|scroll/i; +(function () { + // スクロール可能か? function isScrollable (e, doc) { - try { - let s = doc.defaultView.getComputedStyle(e, ''); - if (e.scrollHeight <= e.clientHeight) - return; - for each (let n in ['overflow', 'overflowY', 'overflowX']) { - if (s[n] && s[n].match(re)) - return true; - } - } catch (e) { - liberator.log(e); + const re = /auto|scroll/i; + let s = doc.defaultView.getComputedStyle(e, ''); + if (e.scrollHeight <= e.clientHeight) + return; + for each (let n in ['overflow', 'overflowY', 'overflowX']) { + if (s[n] && s[n].match(re)) + return true; } } @@ -25,7 +36,6 @@ "position: fixed; top: 0; bottom: 0; left: 0; right: 0;"; indicator.setAttribute("style", style); e.appendChild(indicator); - // remove the frame indicator setTimeout(function () { e.removeChild(indicator); }, 500); } @@ -34,19 +44,12 @@ function scrollableElements () { let result = []; let doc = content.document; - - // var r = doc.evaluate("//div[contains(@style, 'overflow')]", doc, null, 7, null) - // for (var i = 0; i < r.snapshotLength; i++) { - // r.snapshotItem(i).scrollTop += dy; - // } - - var r = doc.evaluate("//div", doc, null, 7, null) + var r = doc.evaluate("//div|//ul", doc, null, 7, null) for (var i = 0; i < r.snapshotLength; i++) { let e = r.snapshotItem(i); if (isScrollable(e, doc)) result.push(e); } - liberator.log('scrollableElements: ' + result.length); return result; } @@ -71,10 +74,10 @@ } // スクロールする - function scroll (dy) { + function scroll (down) { let elem = currentElement(); if (elem) - elem.scrollTop += dy; + elem.scrollTop += Math.max(30, elem.clientHeight - 20) * (down ? 1 : -1); //for each (let elem in scrollableElements()) { // liberator.log(elem.tagName); // liberator.log(elem.id); @@ -82,18 +85,19 @@ //} } + liberator.mappings.addUserMap( [liberator.modes.NORMAL], ['<Leader>j'], 'Scroll down', - function () scroll(30) + function () scroll(true) ); liberator.mappings.addUserMap( [liberator.modes.NORMAL], ['<Leader>k'], 'Scroll up', - function () scroll(-30) + function () scroll(false) ); liberator.mappings.addUserMap( |