     @$contents.length and @$contents.is(':visible')
 
   makeBox: ->
-    bbox = @_computeBoundingBox()
-    @$box = $("<div class='xray-specimen #{@constructor.name}'>").css
-      top    : bbox.top
-      left   : bbox.left
-      width  : bbox.width
-      height : bbox.height
-    # If the element is fixed, inherit its position for the bounding box.
+    @bounds = util.computeBoundingBox(@$contents)
+    @$box = $("<div class='xray-specimen #{@constructor.name}'>").css(@bounds)
+
+    # If the element is fixed, override the computed position with the fixed one.
     if @$contents.css('position') == 'fixed'
       @$box.css
         position : 'fixed'
         top      : @$contents.css('top')
         left     : @$contents.css('left')
-    @$box.click =>
-      Xray.open @path
+
+    @$box.click => Xray.open @path
     @$box.append @makeLabel
 
   makeLabel: =>
-    $("<div class='xray-specimen-handle #{@constructor.name}'>").append(@name).click =>
-      Xray.open @path
-
-  _computeBoundingBox: ($contents = @$contents) ->
-    @bbox = {}
-
-    # Edge case: the container may not wrap its children, for example if they
-    # are floated and no clearfix is present.
-    if $contents.length == 1 and $contents.height() <= 0
-      return @_computeBoundingBox($contents.children())
-
-    boxFrame =
-      top    : Number.MAX_VALUE
-      left   : Number.MAX_VALUE
-      right  : 0
-      bottom : 0
-
-    # `$contents` is a jQuery object that normally wraps one parent element,
-    # but occassionally we're wrapping multiple sibling elements (think about
-    # a partial with no direct container element), so we iterate over it just
-    # in case.
-    for el in $contents
-      $el = $(el)
-      continue unless $el.is(':visible')
-      frame = $el.offset()
-      frame.right  = frame.left + $el.outerWidth()
-      frame.bottom = frame.top + $el.outerHeight()
-      boxFrame.top    = frame.top if frame.top < boxFrame.top
-      boxFrame.left   = frame.left if frame.left < boxFrame.left
-      boxFrame.right  = frame.right if frame.right > boxFrame.right
-      boxFrame.bottom = frame.bottom if frame.bottom > boxFrame.bottom
-    @bbox =
-      left   : boxFrame.left
-      top    : boxFrame.top
-      width  : boxFrame.right - boxFrame.left
-      height : boxFrame.bottom - boxFrame.top
-    return @bbox
+    $("<div class='xray-specimen-handle #{@constructor.name}'>").append(@name)
 
 
 # Wraps elements that constitute a Javascript "view" object, e.g.
-# Backbone.View
+# Backbone.View.
 class Xray.ViewSpecimen extends Xray.Specimen
   @all = []
 

window.Xray = {}
return unless $ = window.jQuery

# Benchmark a piece of code
bm = (name, fn) ->
  time = new Date
  result = fn()
  # console.log "#{name} : #{new Date() - time}ms"
  result

# Max CSS z-index. The overlay and xray bar use this.
MAX_ZINDEX = 2147483647

# Initialize Xray
Xray.init = ->
  return if Xray.initialized
  Xray.initialized = true


    @$settings.show()


# Utility methods.
util =
  # Computes the bounding box of a jQuery set, which may be many sibling
  # elements with no parent in the set.
  computeBoundingBox: ($contents) ->
    # Edge case: the container may not physically wrap its children, for
    # example if they are floated and no clearfix is present.
    if $contents.length == 1 and $contents.height() <= 0
      return util._computeBoundingBox($contents.children())

    boxFrame =
      top    : Number.POSITIVE_INFINITY
      left   : Number.POSITIVE_INFINITY
      right  : Number.NEGATIVE_INFINITY
      bottom : Number.NEGATIVE_INFINITY

    for el in $contents
      $el = $(el)
      continue unless $el.is(':visible')
      frame = $el.offset()
      frame.right  = frame.left + $el.outerWidth()
      frame.bottom = frame.top + $el.outerHeight()
      boxFrame.top    = frame.top if frame.top < boxFrame.top
      boxFrame.left   = frame.left if frame.left < boxFrame.left
      boxFrame.right  = frame.right if frame.right > boxFrame.right
      boxFrame.bottom = frame.bottom if frame.bottom > boxFrame.bottom

    return {
      left   : boxFrame.left
      top    : boxFrame.top
      width  : boxFrame.right - boxFrame.left
      height : boxFrame.bottom - boxFrame.top
    }

  # Benchmark a piece of code
  bm: (name, fn) ->
    time = new Date
    result = fn()
    # console.log "#{name} : #{new Date() - time}ms"
    result
