<commit_before>define (require) ->
  $ = require('jquery')
  Mathjax = require('mathjax')
  router = require('cs!router')
  EditableView = require('cs!helpers/backbone/views/editable')
  template = require('hbs!./body-template')
  require('less!./body')

  return class MediaBodyView extends EditableView
    media: 'page'

    template: template
    templateHelpers:
      status: () -> @owner.get('status')
      loaded: () ->
        if @model
          return @model.get('loaded')
        @owner.get('loaded')

    editable:
      '.media-body':
        value: () -> 'content'
        type: 'aloha'

    events:
      'click a': 'changePage'
      'click [data-type="solution"] > .ui-toggle-wrapper > .ui-toggle': 'toggleSolution'
      'click .solution              > .ui-toggle-wrapper > .ui-toggle': 'toggleSolution'

    initialize: () ->
      super()

      @owner = @model
      @setupModelListener()

    setupModelListener: () ->
      @stopListening()
      @model = @owner.asPage()

      @listenTo(@owner, 'change:currentPage', @updateModelListener)
      @listenTo(@model, 'change:active change:loaded', @updateModelListener) if @model

    updateModelListener: () ->
      @setupModelListener()
      @render()

    # Perform mutations to the HTML before loading it on to the page for better performance
    renderDom: () ->
      $temp = $('<div>').html(@getTemplate())

      if @owner.get('loaded') and @model?.get('loaded') and @model?.get('active')
        # Converts a TERP link to an OST-hosted iframe
        $temp.find('a[href*="#terp-"]').each () ->
          terpCode = $(this).attr('href').match(/#terp\-(.*)/)[1]
          $(this).replaceWith("<iframe class='terp'
                                       src='https://stormy-wave-8747.herokuapp.com/terp/#{terpCode}/quiz_start'
                                       height='600px' width='800px' frameborder='0' seamless='seamless'>
                               </iframe>")

        # Remove the module title and abstract TODO: check if it is still necessary
        $temp.children('[data-type="title"]').remove()<commit_msg>switched TERP from herkou demo to live OST, added anchor for quick navigation to the TERP iframe<commit_after>define (require) ->
  $ = require('jquery')
  Mathjax = require('mathjax')
  router = require('cs!router')
  EditableView = require('cs!helpers/backbone/views/editable')
  template = require('hbs!./body-template')
  require('less!./body')

  return class MediaBodyView extends EditableView
    media: 'page'

    template: template
    templateHelpers:
      status: () -> @owner.get('status')
      loaded: () ->
        if @model
          return @model.get('loaded')
        @owner.get('loaded')

    editable:
      '.media-body':
        value: () -> 'content'
        type: 'aloha'

    events:
      'click a': 'changePage'
      'click [data-type="solution"] > .ui-toggle-wrapper > .ui-toggle': 'toggleSolution'
      'click .solution              > .ui-toggle-wrapper > .ui-toggle': 'toggleSolution'

    initialize: () ->
      super()

      @owner = @model
      @setupModelListener()

    setupModelListener: () ->
      @stopListening()
      @model = @owner.asPage()

      @listenTo(@owner, 'change:currentPage', @updateModelListener)
      @listenTo(@model, 'change:active change:loaded', @updateModelListener) if @model

    updateModelListener: () ->
      @setupModelListener()
      @render()

    # Perform mutations to the HTML before loading it on to the page for better performance
    renderDom: () ->
      $temp = $('<div>').html(@getTemplate())

      if @owner.get('loaded') and @model?.get('loaded') and @model?.get('active')
        # Converts a TERP link to an OST-hosted iframe
        $temp.find('a[href*="#terp-"]').each () ->
          terpCode = $(this).attr('href').match(/#terp\-(.*)/)[1]
          $(this).replaceWith("<a class='terp-anchor' name='terp-#{terpCode}'></a>
                               <iframe class='terp'
                                       src='https://openstaxtutor.org/terp/#{terpCode}/quiz_start'
                                       height='600px' width='800px' frameborder='0' seamless='seamless'>
                               </iframe>")

        # Remove the module title and abstract TODO: check if it is still necessary
        $temp.children('[data-type="title"]').remove()
{'fraction_non_alphanumeric': 0.15983512708953515, 'fraction_numerical': 0.004579803068468056, 'mean_word_length': 2.442080378250591, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 37, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7578222', 'n_tokens_mistral': 1319, 'n_tokens_neox': 1259, 'n_words': 274}