Changeset 17931

Show
Ignore:
Timestamp:
08/20/08 18:15:46 (5 years ago)
Author:
anekos
Message:

]d [d 時に対象の要素を青くするようにした。

Files:
1 modified

Legend:

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

    r17916 r17931  
    1313//      スクロールする 
    1414// 
     15//  TODO: 
     16//    フレーム対応 
    1517 
    1618(function () { 
    1719 
    1820  // スクロール可能か? 
    19   function isScrollable (e, doc) { 
     21  function isScrollable (elem) { 
    2022    const re = /auto|scroll/i; 
    21     let s = doc.defaultView.getComputedStyle(e, ''); 
    22     if (e.scrollHeight <= e.clientHeight) 
     23    let s = elem.ownerDocument.defaultView.getComputedStyle(elem, ''); 
     24    if (elem.scrollHeight <= elem.clientHeight) 
    2325      return; 
    2426    for each (let n in ['overflow', 'overflowY', 'overflowX']) { 
     
    2830  } 
    2931 
    30   // FIXME 
    31   function flashElement (e, doc) { 
    32     var indicator = doc.createElement("div"); 
    33     indicator.id = "liberator-frame-indicator"; 
    34     // NOTE: need to set a high z-index - it's a crapshoot! 
    35     var style = "background-color: red; opacity: 0.5; z-index: 999;" + 
    36                 "position: fixed; top: 0; bottom: 0; left: 0; right: 0;"; 
     32  // 光らせる 
     33  function flashElement (elem) { 
     34    let indicator = elem.ownerDocument.createElement("div"); 
     35    let rect = elem.getBoundingClientRect(); 
     36    indicator.id = "nyantoro-element-indicator"; 
     37    let style = "background-color: blue; opacity: 0.5; z-index: 999;" + 
     38                "position: fixed; " +  
     39                "top: " + rect.top + "px;" + 
     40                "height:" + elem.clientHeight + "px;"+ 
     41                "left: " + rect.left + "px;" + 
     42                "width: " + elem.clientWidth + "px"; 
    3743    indicator.setAttribute("style", style); 
    38     e.appendChild(indicator); 
    39     // remove the frame indicator 
    40     setTimeout(function () { e.removeChild(indicator); }, 500); 
     44    elem.appendChild(indicator); 
     45    setTimeout(function () elem.removeChild(indicator), 500); 
    4146  } 
    4247 
     
    4550    let result = []; 
    4651    let doc = content.document; 
    47     var r = doc.evaluate("//div|//ul", doc, null, 7, null) 
    48     for (var i = 0; i < r.snapshotLength; i++) { 
    49       let e = r.snapshotItem(i); 
    50       if (isScrollable(e, doc)) 
    51         result.push(e); 
     52    let r = doc.evaluate("//div|//ul", doc, null, 7, null) 
     53    for (let i = 0; i < r.snapshotLength; i++) { 
     54      let elem = r.snapshotItem(i); 
     55      if (isScrollable(elem)) 
     56        result.push(elem); 
    5257    } 
    53     liberator.log('scrollableElements: ' + result.length); 
    5458    return result; 
    5559  } 
     
    5761  // スクロール対象を変更 
    5862  function shiftScrollElement (n) { 
    59     let idx = content.document.__div_scroller_index || 0; 
     63    let doc = content.document; 
     64    let idx = doc.__div_scroller_index || 0; 
    6065    let es = scrollableElements(); 
     66    if (es.length <= 0) 
     67      liberator.echoerr('scrollable element not found'); 
    6168    idx += (n || 1); 
    6269    if (idx < 0) 
     
    6572      idx = 0; 
    6673    content.document.__div_scroller_index = idx; 
     74    flashElement(es[idx]); 
    6775  } 
    6876 
     
    7987    if (elem) 
    8088      elem.scrollTop += Math.max(30, elem.clientHeight - 20) * (down ? 1 : -1); 
    81     //for each (let elem in scrollableElements()) { 
    82     //  liberator.log(elem.tagName); 
    83     //  liberator.log(elem.id); 
    84     //  elem.scrollTop += dy; 
    85     //} 
    8689  } 
    8790