<commit_before>define [
  'marionette'
  'aloha'
  #'mathjax'
], (Marionette, Aloha) ->

  AUTOSAVE_INTERVAL = 500 # ms

  return class AlohaEditView extends Marionette.ItemView
    # **NOTE:** This template is not wrapped in an element
    template: () -> throw 'BUG: You need to specify a template, modelKey'
    modelKey: null
    saveInterval: null
    @activateAloha = false

    templateHelpers: () ->
      return {isLoaded: @isLoaded}

    initialize: () ->
      @isLoaded = false

      @model.load().done () =>
        @isLoaded = true

        @activateAloha = true
        @render()

        #@listenTo @model, "change:#{@modelKey}", (model, value, options) =>
          #return if options.internalAlohaUpdate
          #@activateAloha = true
          #@render()

    # Stop auto-setting when the view closes
    onClose: () ->
      clearInterval(@saveInterval)
      @saveInterval = null

    onRender: () ->
      # update model after the user has stopped making changes

      #if @model.attributes.body
      updateModel = =>
        alohaId = @$el.attr('id')
        alohaEditable = Aloha.getEditableById(alohaId)
      
        if alohaEditable
          editableBody = alohaEditable.getContents()
          editableBody = editableBody.trim() # Trim for idempotence
          # Change the contents but do not update the Aloha editable area
          @model.set(@modelKey, editableBody, {internalAlohaUpdate: true})
      
      @saveInterval = setInterval(updateModel, AUTOSAVE_INTERVAL) if not @saveInterval
     
      if @activateAloha
        @activateAloha = false
        # Once Aloha has finished loading enable
        @$el.addClass('disabled')
        
        Aloha.ready =>
        
          #@$el.mahalo()
          setTimeout((=>@$el.aloha()), 100)
        
          # Wait until Aloha is started before loading MathJax.
          MathJax?.Hub.Configured()
        
          # reenable everything
          @$el.removeClass('disabled')<commit_msg>Revert "fix adding new content"<commit_after>define [
  'marionette'
  'aloha'
  #'mathjax'
], (Marionette, Aloha) ->

  AUTOSAVE_INTERVAL = 500 # ms

  return class AlohaEditView extends Marionette.ItemView
    # **NOTE:** This template is not wrapped in an element
    template: () -> throw 'BUG: You need to specify a template, modelKey'
    modelKey: null
    saveInterval: null

    templateHelpers: () ->
      return {isLoaded: @isLoaded}

    initialize: () ->
      @isLoaded = false

      @model.load().done () =>
        @isLoaded = true
        @render()

        @listenTo @model, "change:#{@modelKey}", (model, value, options) =>
          return if options.internalAlohaUpdate
          @render()

    # Stop auto-setting when the view closes
    onClose: () ->
      clearInterval(@saveInterval)
      @saveInterval = null

    onRender: () ->
      # update model after the user has stopped making changes

      if @model.attributes.body
        updateModel = =>
          alohaId = @$el.attr('id')
          alohaEditable = Aloha.getEditableById(alohaId)
       
          if alohaEditable
            editableBody = alohaEditable.getContents()
            editableBody = editableBody.trim() # Trim for idempotence
            # Change the contents but do not update the Aloha editable area
            @model.set(@modelKey, editableBody, {internalAlohaUpdate: true})
       
        @saveInterval = setInterval(updateModel, AUTOSAVE_INTERVAL) if not @saveInterval
       
       
        # Once Aloha has finished loading enable
        @$el.addClass('disabled')
       
        Aloha.ready =>
       
          @$el.mahalo?()
          @$el.aloha()
       
          # Wait until Aloha is started before loading MathJax.
          MathJax?.Hub.Configured()
       
          # reenable everything
          @$el.removeClass('disabled')
{'fraction_non_alphanumeric': 0.10387919812548815, 'fraction_numerical': 0.002343139807341838, 'mean_word_length': 2.2150627615062763, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 24, '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': '928546', 'n_tokens_mistral': 1157, 'n_tokens_neox': 1084, 'n_words': 288}