From 45fcaf20e6af831c736dab9a9b8d18810457fdd5 Mon Sep 17 00:00:00 2001 From: drry Date: Fri, 26 Sep 2008 07:04:29 +0000 Subject: * Array に対する `for each` を排除しました。 * ほか。 git-svn-id: http://svn.coderepos.org/share/lang/javascript/vimperator-plugins/trunk@19953 d0d07461-0603-4401-acd4-de1884942a52 --- scroll_div.js | 38 ++++++++++++++++++-------------------- 1 file changed, 18 insertions(+), 20 deletions(-) (limited to 'scroll_div.js') diff --git a/scroll_div.js b/scroll_div.js index 29b30b7..90542a3 100644 --- a/scroll_div.js +++ b/scroll_div.js @@ -22,25 +22,23 @@ const re = /auto|scroll/i; let s = elem.ownerDocument.defaultView.getComputedStyle(elem, ''); if (elem.scrollHeight <= elem.clientHeight) - return; - for each (let n in ['overflow', 'overflowY', 'overflowX']) { - if (s[n] && s[n].match(re)) - return true; - } + return false; + return ['overflow', 'overflowY', 'overflowX'].some(function (n) + s[n] && re.test(s[n])); } // 光らせる function flashElement (elem) { - let indicator = elem.ownerDocument.createElement("div"); + let indicator = elem.ownerDocument.createElement('div'); let rect = elem.getBoundingClientRect(); - indicator.id = "nyantoro-element-indicator"; - let style = "background-color: blue; opacity: 0.5; z-index: 999;" + - "position: fixed; " + - "top: " + rect.top + "px;" + - "height:" + elem.clientHeight + "px;"+ - "left: " + rect.left + "px;" + - "width: " + elem.clientWidth + "px"; - indicator.setAttribute("style", style); + indicator.id = 'nyantoro-element-indicator'; + let style = 'background-color: blue; opacity: 0.5; z-index: 999;' + + 'position: fixed; ' + + 'top: ' + rect.top + 'px;' + + 'height:' + elem.clientHeight + 'px;'+ + 'left: ' + rect.left + 'px;' + + 'width: ' + elem.clientWidth + 'px'; + indicator.setAttribute('style', style); elem.appendChild(indicator); setTimeout(function () elem.removeChild(indicator), 500); } @@ -49,8 +47,8 @@ function scrollableElements () { let result = []; let doc = content.document; - let r = doc.evaluate("//div|//ul", doc, null, 7, null) - for (let i = 0; i < r.snapshotLength; i++) { + let r = doc.evaluate('//div|//ul', doc, null, 7, null) + for (let i = 0, l = r.snapshotLength; i < l; i++) { let elem = r.snapshotItem(i); if (isScrollable(elem)) result.push(elem); @@ -90,28 +88,28 @@ liberator.mappings.addUserMap( - [liberator.modes.NORMAL], + [liberator.modes.NORMAL], ['j'], 'Scroll down', function () scroll(true) ); liberator.mappings.addUserMap( - [liberator.modes.NORMAL], + [liberator.modes.NORMAL], ['k'], 'Scroll up', function () scroll(false) ); liberator.mappings.addUserMap( - [liberator.modes.NORMAL], + [liberator.modes.NORMAL], [']d'], 'Shift Scroll Element', function () shiftScrollElement(1) ); liberator.mappings.addUserMap( - [liberator.modes.NORMAL], + [liberator.modes.NORMAL], ['[d'], 'Shift Scroll Element', function () shiftScrollElement(-1) -- cgit v1.2.3