aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorJez Ng2012-08-19 00:50:05 -0700
committerJez Ng2012-08-19 00:50:05 -0700
commit218b986d46f59ee843b611b881a8dfad037a8446 (patch)
tree528e9b7eafe3e7f97c78f9921d120980931f8200 /lib
parent8b7b779717a1984eaba3c250acfad6ac3c592423 (diff)
downloadvimium-218b986d46f59ee843b611b881a8dfad037a8446.tar.bz2
Use more idiomatic CS.
Diffstat (limited to 'lib')
-rw-r--r--lib/dom_utils.coffee25
1 files changed, 11 insertions, 14 deletions
diff --git a/lib/dom_utils.coffee b/lib/dom_utils.coffee
index c0efd344..924afbbe 100644
--- a/lib/dom_utils.coffee
+++ b/lib/dom_utils.coffee
@@ -2,11 +2,10 @@ DomUtils =
#
# Runs :callback if the DOM has loaded, otherwise runs it on load
#
- documentReady: (->
+ documentReady: do ->
loaded = false
window.addEventListener("DOMContentLoaded", -> loaded = true)
(callback) -> if loaded then callback() else window.addEventListener("DOMContentLoaded", callback)
- )()
#
# Remove an element from its DOM tree.
@@ -35,14 +34,13 @@ DomUtils =
getVisibleClientRect: (element) ->
# Note: this call will be expensive if we modify the DOM in between calls.
clientRects = element.getClientRects()
- clientRectsLength = clientRects.length
- for i in [0...clientRectsLength]
- if (clientRects[i].top < -2 || clientRects[i].top >= window.innerHeight - 4 ||
- clientRects[i].left < -2 || clientRects[i].left >= window.innerWidth - 4)
+ for clientRect in clientRects
+ if (clientRect.top < -2 || clientRect.top >= window.innerHeight - 4 ||
+ clientRect.left < -2 || clientRect.left >= window.innerWidth - 4)
continue
- if (clientRects[i].width < 3 || clientRects[i].height < 3)
+ if (clientRect.width < 3 || clientRect.height < 3)
continue
# eliminate invisible elements (see test_harnesses/visibility_test.html)
@@ -51,19 +49,18 @@ DomUtils =
computedStyle.getPropertyValue('display') == 'none')
continue
- return clientRects[i]
+ return clientRect
- for i in [0...clientRectsLength]
+ for clientRect in clientRects
# If the link has zero dimensions, it may be wrapping visible
# but floated elements. Check for this.
- if (clientRects[i].width == 0 || clientRects[i].height == 0)
- childrenCount = element.children.length
- for j in [0...childrenCount]
- computedStyle = window.getComputedStyle(element.children[j], null)
+ if (clientRect.width == 0 || clientRect.height == 0)
+ for child in element.children
+ computedStyle = window.getComputedStyle(child, null)
# Ignore child elements which are not floated and not absolutely positioned for parent elements with zero width/height
if (computedStyle.getPropertyValue('float') == 'none' && computedStyle.getPropertyValue('position') != 'absolute')
continue
- childClientRect = this.getVisibleClientRect(element.children[j])
+ childClientRect = @getVisibleClientRect(child)
if (childClientRect == null)
continue
return childClientRect