<commit_before>class KDInputViewWithPreview extends KDInputView

  constructor:(options,data)->

    options.preview               or= {}
    options.preview.autoUpdate    ?= yes
    options.preview.language      or= "markdown"
    options.preview.showInitially ?= yes

    options.keyup ?= (event)=>
      if @options.preview.autoUpdate and @showPreview then @generatePreview()
      yes

    options.focus ?= (event)=>
      if @options.preview.autoUpdate and @showPreview then @generatePreview()
      yes

    super options,data

    @setClass "kdinputwithpreview"

    @showPreview = options.preview.showInitially or no

  setDomElement:(CssClass="")->
    super CssClass

    # basically, here we can add aynthing like modals, overlays and the liek

    @$().after """<div class='input_preview preview-#{@options.preview.language}'>
        <div class="preview_switch">
          <label for="previewCheckbox#{@getId()}">Preview</label>
          <input name="previewCheckbox#{@getId()}" type="checkbox" class="preview_checkbox" />
        </div>
        <div class="preview_content"></div>
      </div>"""

  viewAppended:->
    super

    @$("input.preview_checkbox").on "click",(event)=>
      checkState = @$("input.preview_checkbox").prop("checked") or no

      if checkState
        @generatePreview()
        @$("div.preview_content").removeClass "hidden"
        @$("div.preview_switch").removeClass "content-hidden"
      else
        @$("div.preview_content").addClass "hidden"
        @$("div.preview_switch").addClass "content-hidden"

    unless @showPreview
      @$("div.preview_content").addClass "hidden"
      @$("div.preview_switch").addClass "content-hidden"
      @$("input.preview_checkbox").prop("checked",no)
    else
      @generatePreview()
      @$("input.preview_checkbox").prop("checked",yes)

    @$("label").on "click",=>
      @$("input.preview_checkbox").get(0).click()

  generatePreview:=>
    if @showPreview
      if @options.preview.language is "markdown"
        @$("div.preview_content").html @utils.applyMarkdown @getValue()
        @$("div.preview_content pre").addClass("prettyprint").each (i,element)=>
          hljs.highlightBlock element<commit_msg>added "has-"+language tag to preview for unified styling (e.g. has-markdown as it is used in the CD)<commit_after>class KDInputViewWithPreview extends KDInputView

  constructor:(options,data)->

    options.preview               or= {}
    options.preview.autoUpdate    ?= yes
    options.preview.language      or= "markdown"
    options.preview.showInitially ?= yes

    options.keyup ?= (event)=>
      if @options.preview.autoUpdate and @showPreview then @generatePreview()
      yes

    options.focus ?= (event)=>
      if @options.preview.autoUpdate and @showPreview then @generatePreview()
      yes

    super options,data

    @setClass "kdinputwithpreview"

    @showPreview = options.preview.showInitially or no

  setDomElement:(CssClass="")->
    super CssClass

    # basically, here we can add aynthing like modals, overlays and the liek

    @$().after """<div class='input_preview preview-#{@options.preview.language}'>
        <div class="preview_switch">
          <label for="previewCheckbox#{@getId()}">Preview</label>
          <input name="previewCheckbox#{@getId()}" type="checkbox" class="preview_checkbox" />
        </div>
        <div class="preview_content"></div>
      </div>"""

  viewAppended:->
    super

    @$("input.preview_checkbox").on "click",(event)=>
      checkState = @$("input.preview_checkbox").prop("checked") or no

      if checkState
        @generatePreview()
        @$("div.preview_content").removeClass "hidden"
        @$("div.preview_switch").removeClass "content-hidden"
      else
        @$("div.preview_content").addClass "hidden"
        @$("div.preview_switch").addClass "content-hidden"

    unless @showPreview
      @$("div.preview_content").addClass "hidden"
      @$("div.preview_switch").addClass "content-hidden"
      @$("input.preview_checkbox").prop("checked",no)
    else
      @generatePreview()
      @$("input.preview_checkbox").prop("checked",yes)

    @$("label").on "click",=>
      @$("input.preview_checkbox").get(0).click()

    @$("div.preview_content").addClass("has-"+@options.preview.language)


  generatePreview:=>
    if @showPreview
      if @options.preview.language is "markdown"
        @$("div.preview_content").html @utils.applyMarkdown @getValue()
        @$("div.preview_content pre").addClass("prettyprint").each (i,element)=>
          hljs.highlightBlock element
{'fraction_non_alphanumeric': 0.15462111257117828, 'fraction_numerical': 0.0004380201489268506, 'mean_word_length': 3.353670162059104, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 39, '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': '4111751', 'n_tokens_mistral': 1362, 'n_tokens_neox': 1319, 'n_words': 254}