<commit_before>$ = require('jquery')
_ = require('lodash')

IframeResizer = require('./iframe_resizer.coffee')

class Iframe
  constructor: (@elem)->
    @id = Math.floor((1 + Math.random()) * 0x10000).toString(16).substring(1)
    config = $(@elem).data('configuration')
    @configuration = if typeof config == 'string'
      window[config] || {}
    else
      config

    if _.isEmpty(@configuration)
      @configuration.json_config = config
    @configuration.parentLocationHash = window.location.hash
    @configuration.embedCode = @elem.outerHTML

    scriptPath = $(@elem).attr('src').match(/(^.*\/)/)[0].replace(/javascripts\/$/, '').replace(/\/$/, '')
    @url = "#{scriptPath}/podigee-podcast-player.html?id=#{@id}&iframeMode=script"

    @buildIframe()
    @setupListeners()
    @replaceElem()
    @injectConfiguration() if @configuration

  buildIframe: ->
    @iframe = document.createElement('iframe')
    @iframe.id = @id
    @iframe.scrolling = 'no'
    @iframe.src = @url
    @iframe.style.border = '0'
    @iframe.style.overflowY = 'hidden'
    @iframe.style.transition = 'height 100ms linear'
    @iframe.width = "100%"
    @iframe

  setupListeners: ->
    IframeResizer.listen('resizePlayer', $(@iframe))

  replaceElem: ->
    $(@iframe).addClass($(@elem).attr('class'))
    @elem.parentNode.replaceChild(@iframe, @elem)

  injectConfiguration: ->
    $(window).on 'message', (event) =>
      eventData = event.data || event.originalEvent.data
      return unless eventData == 'sendConfig'

      config = if @configuration.constructor == String
        @configuration
      else
        JSON.stringify(@configuration)
      @iframe.contentWindow.postMessage(config, '*')

class Embed<commit_msg>load iframe from http when site is http<commit_after>$ = require('jquery')
_ = require('lodash')

IframeResizer = require('./iframe_resizer.coffee')

class Iframe
  constructor: (@elem)->
    @id = Math.floor((1 + Math.random()) * 0x10000).toString(16).substring(1)
    config = $(@elem).data('configuration')
    @configuration = if typeof config == 'string'
      window[config] || {}
    else
      config

    if _.isEmpty(@configuration)
      @configuration.json_config = config
    @configuration.parentLocationHash = window.location.hash
    @configuration.embedCode = @elem.outerHTML

    @url = "#{@origin()}/podigee-podcast-player.html?id=#{@id}&iframeMode=script"

    @buildIframe()
    @setupListeners()
    @replaceElem()
    @injectConfiguration() if @configuration

  origin: () ->
    scriptSrc = $(@elem).attr('src')
    unless window.location.protocol.match(/^https/)
      scriptSrc = scriptSrc.replace(/^https/, 'http')
    scriptSrc.match(/(^.*\/)/)[0].replace(/javascripts\/$/, '').replace(/\/$/, '')

  buildIframe: ->
    @iframe = document.createElement('iframe')
    @iframe.id = @id
    @iframe.scrolling = 'no'
    @iframe.src = @url
    @iframe.style.border = '0'
    @iframe.style.overflowY = 'hidden'
    @iframe.style.transition = 'height 100ms linear'
    @iframe.width = "100%"
    @iframe

  setupListeners: ->
    IframeResizer.listen('resizePlayer', $(@iframe))

  replaceElem: ->
    $(@iframe).addClass($(@elem).attr('class'))
    @elem.parentNode.replaceChild(@iframe, @elem)

  injectConfiguration: ->
    $(window).on 'message', (event) =>
      eventData = event.data || event.originalEvent.data
      return unless eventData == 'sendConfig'

      config = if @configuration.constructor == String
        @configuration
      else
        JSON.stringify(@configuration)
      @iframe.contentWindow.postMessage(config, '*')

class Embed
{'fraction_non_alphanumeric': 0.170508192168842, 'fraction_numerical': 0.009997222993612885, 'mean_word_length': 3.4800995024875623, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 16, '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': '6932657', 'n_tokens_mistral': 1151, 'n_tokens_neox': 1074, 'n_words': 193}