<commit_before>imagesLoaded = require 'imagesloaded'

module.exports = class Backdrop
  constructor: ({ @$el, @$window, @$body }) ->
    # Wait for images to load before scaling
    @$el.imagesLoaded =>
      @scale()

  scale: ->
    [width, height] = dimensions = @dimensions()

    @$el
      .addClass('is-ready')
      .css
        transform: "scale(#{@factor(dimensions)})"
        marginTop: -(height / 2)
        marginLeft: -(width / 2)

  dimensions: ->
    if @$el.is ':visible'
      [@$el.outerWidth(), @$el.outerHeight()]
    else
      $clone = @$el.clone()
      $clone.css 'visibility', 'hidden'
      @$body.append $clone
      dimensions = [$clone.outerWidth(), $clone.outerHeight()]
      $clone.remove()
      dimensions

  factor: ([width, height]) ->
    ratio = width / height
    viewportRatio = @$window.width() / @$window.height()
    direction = if viewportRatio > ratio then 'width' else 'height'
    factor = @$window[direction]() / @$el[direction]()
    Math.ceil(factor * 100) / 100<commit_msg>Fix bug with off screen images<commit_after>imagesLoaded = require 'imagesloaded'

module.exports = class Backdrop
  constructor: ({ @$el, @$window, @$body }) ->
    # Wait for images to load before scaling
    @$el.imagesLoaded => @scale()

  scale: ->
    { width, height } = dimensions = @dimensions()

    @$el
      .addClass('is-ready')
      .css
        transform: "scale(#{@factor(dimensions)})"
        marginTop: -(height / 2)
        marginLeft: -(width / 2)

  dimensions: ->
    if @$el.is ':visible'
      width: @$el.outerWidth(), height: @$el.outerHeight()
    else
      $clone = @$el.clone()
      $clone.css 'visibility', 'hidden'
      @$body.append $clone
      dimensions = width: $clone.outerWidth(), height: $clone.outerHeight()
      $clone.remove()
      dimensions

  factor: (dimensions) ->
    { width, height } = dimensions
    ratio = width / height
    viewportRatio = @$window.width() / @$window.height()
    direction = if viewportRatio > ratio then 'width' else 'height'
    factor = @$window[direction]() / dimensions[direction]
    Math.ceil(factor * 100) / 100
{'fraction_non_alphanumeric': 0.16423529411764706, 'fraction_numerical': 0.0075294117647058826, 'mean_word_length': 2.803220035778175, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1674157', 'n_tokens_mistral': 688, 'n_tokens_neox': 658, 'n_words': 164}