Changeset 17916
- Timestamp:
- 08/20/08 00:14:14 (5 months ago)
- 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 1 16 (function () { 2 17 3 let re = /auto|scroll/i; 4 18 // スクロール可能か? 5 19 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; 16 27 } 17 28 } … … 26 37 indicator.setAttribute("style", style); 27 38 e.appendChild(indicator); 28 29 39 // remove the frame indicator 30 40 setTimeout(function () { e.removeChild(indicator); }, 500); … … 35 45 let result = []; 36 46 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) 44 48 for (var i = 0; i < r.snapshotLength; i++) { 45 49 let e = r.snapshotItem(i); … … 47 51 result.push(e); 48 52 } 49 50 53 liberator.log('scrollableElements: ' + result.length); 51 54 return result; … … 72 75 73 76 // スクロールする 74 function scroll (d y) {77 function scroll (down) { 75 78 let elem = currentElement(); 76 79 if (elem) 77 elem.scrollTop += dy;80 elem.scrollTop += Math.max(30, elem.clientHeight - 20) * (down ? 1 : -1); 78 81 //for each (let elem in scrollableElements()) { 79 82 // liberator.log(elem.tagName); … … 83 86 } 84 87 88 85 89 liberator.mappings.addUserMap( 86 90 [liberator.modes.NORMAL], 87 91 ['<Leader>j'], 88 92 'Scroll down', 89 function () scroll( 30)93 function () scroll(true) 90 94 ); 91 95 … … 94 98 ['<Leader>k'], 95 99 'Scroll up', 96 function () scroll( -30)100 function () scroll(false) 97 101 ); 98 102
![(please configure the [header_logo] section in trac.ini)](/share/chrome/site/your_project_logo.png)