Changeset 17916

Show
Ignore:
Timestamp:
08/20/08 00:14:14 (5 months ago)
Author:
anekos
Message:

スクロール量を自動的に決定するようにした。

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • lang/javascript/vimperator-plugins/trunk/scroll_div.js

    r17907 r17916  
     1// ==VimperatorPlugin== 
     2// @name           Div Scroller 
     3// @description-ja スクロールができる div 要素などでスクロールする 
     4// @license        Creative Commons 2.1 (Attribution + Share Alike) 
     5// @version        0.1 
     6// ==/VimperatorPlugin== 
     7// 
     8//  Mappings: 
     9//    ]d [d 
     10//      スクロール対象を変更 
     11//      ]f [f のようなもの 
     12//    <Leader>j <Leader>k 
     13//      スクロールする 
     14// 
     15 
    116(function () { 
    217 
    3   let re = /auto|scroll/i; 
    4  
     18  // スクロール可能か? 
    519  function isScrollable (e, doc) { 
    6     try { 
    7       let s = doc.defaultView.getComputedStyle(e, ''); 
    8       if (e.scrollHeight <= e.clientHeight) 
    9         return; 
    10       for each (let n in ['overflow', 'overflowY', 'overflowX']) { 
    11         if (s[n] && s[n].match(re)) 
    12           return true; 
    13       } 
    14     } catch (e) { 
    15       liberator.log(e); 
     20    const re = /auto|scroll/i; 
     21    let s = doc.defaultView.getComputedStyle(e, ''); 
     22    if (e.scrollHeight <= e.clientHeight) 
     23      return; 
     24    for each (let n in ['overflow', 'overflowY', 'overflowX']) { 
     25      if (s[n] && s[n].match(re)) 
     26        return true; 
    1627    } 
    1728  } 
     
    2637    indicator.setAttribute("style", style); 
    2738    e.appendChild(indicator); 
    28  
    2939    // remove the frame indicator 
    3040    setTimeout(function () { e.removeChild(indicator); }, 500); 
     
    3545    let result = []; 
    3646    let doc = content.document; 
    37  
    38     // var r = doc.evaluate("//div[contains(@style, 'overflow')]", doc, null, 7, null) 
    39     // for (var i = 0; i < r.snapshotLength; i++) { 
    40     //   r.snapshotItem(i).scrollTop += dy; 
    41     // } 
    42  
    43     var r = doc.evaluate("//div", doc, null, 7, null) 
     47    var r = doc.evaluate("//div|//ul", doc, null, 7, null) 
    4448    for (var i = 0; i < r.snapshotLength; i++) { 
    4549      let e = r.snapshotItem(i); 
     
    4751        result.push(e); 
    4852    } 
    49  
    5053    liberator.log('scrollableElements: ' + result.length); 
    5154    return result; 
     
    7275 
    7376  // スクロールする 
    74   function scroll (dy) { 
     77  function scroll (down) { 
    7578    let elem = currentElement(); 
    7679    if (elem) 
    77       elem.scrollTop += dy; 
     80      elem.scrollTop += Math.max(30, elem.clientHeight - 20) * (down ? 1 : -1); 
    7881    //for each (let elem in scrollableElements()) { 
    7982    //  liberator.log(elem.tagName); 
     
    8386  } 
    8487 
     88 
    8589  liberator.mappings.addUserMap( 
    8690    [liberator.modes.NORMAL],  
    8791    ['<Leader>j'], 
    8892    'Scroll down', 
    89     function () scroll(30) 
     93    function () scroll(true) 
    9094  ); 
    9195 
     
    9498    ['<Leader>k'], 
    9599    'Scroll up', 
    96     function () scroll(-30) 
     100    function () scroll(false) 
    97101  ); 
    98102