<commit_before>class CodeBinActivityItemView extends ActivityItemChild

  constructor:(options, data)->
    options = $.extend
      cssClass    : "activity-item codebin"
      tooltip     :
        title     : "Code Bin"
        offset    : 3
        selector  : "span.type-icon"
    ,options
    super options,data

    @codeBinContainer = new KDTabView
      cssClass: "code-bin-container"

    @codeBinResultPane = new KDTabPaneView
      name:"Code Share"


    @codeBinHTMLPane = new KDTabPaneView
      name:"HTML"

    @codeBinCSSPane = new KDTabPaneView
      name:"CSS"

    @codeBinJSPane = new KDTabPaneView
      name:"JavaScript"

    codeBinHTMLData = @getData().attachments[0]
    codeBinCSSData = @getData().attachments[1]
    codeBinJSData = @getData().attachments[2]

    codeBinHTMLData.title = @getData().title
    codeBinCSSData.title = @getData().title
    codeBinJSData.title = @getData().title

    @codeBinHTMLView = new CodeBinSnippetView {}, codeBinHTMLData
    @codeBinCSSView = new CodeBinSnippetView {}, codeBinCSSData
    @codeBinJSView = new CodeBinSnippetView {}, codeBinJSData

    @codeBinResultView = new CodeBinResultView {}, data
    @codeBinResultView.hide()

    @codeBinResultButton = new KDButtonView
      title: "Run Code Share"
      cssClass:"clean-gray result-button"
      click:=>
        @codeBinResultButton.setTitle "Reset Code Share"
        @codeBinResultView.show()
        @resultBanner.hide()
        @codeBinCloseButton.show()
        @codeBinResultView.emit "CodeBinSourceHasChanges", @getData()
        @codeBinContainer.showPane @codeBinResultPane

    @codeBinCloseButton = new KDButtonView
      title: "Stop and Close Code Share"
      cssClass:"clean-gray hidden"
      click:=>
        @codeBinResultView.hide()
        # @codeBinResultView.stopResultFrame()
        @codeBinResultView.resetResultFrame()
        @codeBinResultButton.setTitle "Run Code Share"
        @resultBanner.show()
        @codeBinCloseButton.hide()


    @codeBinForkButton = new KDButtonView
      title: "Fork this Code Share"
      cssClass:"clean-gray fork-button"
      click:=>
        @getSingleton('mainController').emit 'ContentDisplayItemForkLinkClicked', data


    @resultBanner = new KDCustomHTMLView
      tagName : "div"
      cssClass : "result-banner"
      partial : ""

    @resultBannerButton = new KDCustomHTMLView
      name : "resultBannerButton"
      tagName:"a"
      attributes:
        href:"#"
      partial : "Click here to see this Code Share!"
      cssClass : "result-banner-button"
      click:=>
        @codeBinResultButton.setTitle "Reset Code Share"
        @codeBinResultView.show()
        @resultBanner.hide()
        @codeBinCloseButton.show()
        @codeBinResultView.emit "CodeBinSourceHasChanges", @getData()


    @resultBanner.addSubView @resultBannerButton

    @codeBinResultPane.addSubView @resultBanner

    @codeBinResultPane.addSubView @codeBinResultView
    @codeBinHTMLPane.addSubView @codeBinHTMLView
    @codeBinCSSPane.addSubView @codeBinCSSView
    @codeBinJSPane.addSubView @codeBinJSView


    @codeBinContainer.addPane @codeBinResultPane
    @codeBinContainer.addPane @codeBinHTMLPane
    @codeBinContainer.addPane @codeBinCSSPane
    @codeBinContainer.addPane @codeBinJSPane

    @codeBinResultPane.hideTabCloseIcon()
    @codeBinHTMLPane.hideTabCloseIcon()
    @codeBinCSSPane.hideTabCloseIcon()
    @codeBinJSPane.hideTabCloseIcon()

    # hover switching enabled by default
    @codeBinContainer.$(".kdtabhandle").hover (event)->
      $(event.target).closest(".kdtabhandle").click()
    , noop

    @codeBinContainer.showPane @codeBinResultPane

    setTimeout =>
      @codeBinResultButton.setTitle "Reset Code Share"
      @codeBinResultView.show()
      @resultBanner.hide()
      @codeBinCloseButton.show()
      @codeBinResultView.emit "CodeBinSourceHasChanges", @getData()
      # setTimeout =>
      #   @codeBinResultView.stopResultFrame()
      # , 10000
    , 1000

  render:->
    super()

    codeBinHTMLData = @getData().attachments[0]
    codeBinCSSData = @getData().attachments[1]
    codeBinJSData = @getData().attachments[2]

    codeBinHTMLData.title = @getData().title
    codeBinCSSData.title = @getData().title
    codeBinJSData.title = @getData().title

    @codeBinHTMLView.setData codeBinHTMLData
    @codeBinCSSView.setData codeBinCSSData
    @codeBinJSView.setData codeBinJSData

    @codeBinHTMLView.render()
    @codeBinCSSView.render()
    @codeBinJSView.render()

  click:(event)->
    super
    if $(event.target).is(".activity-item-right-col h3")
      appManager.tell "Activity", "createContentDisplay", @getData()

  viewAppended: ->
    return if @getData().constructor is bongo.api.CCodeBinActivity
    super()
    @setTemplate @pistachio()
    @template.update()

    maxHeight = 30
    views = [@codeBinJSView,@codeBinCSSView,@codeBinHTMLView]

    for view in views
      if view.getHeight()>maxHeight
        maxHeight = view.getHeight()

    @$("pre.subview").css height:maxHeight


  pistachio:->

    """
    {{> @settingsButton}}
    <span class="avatar">{{> @avatar}}</span><commit_msg>added (workaround) load-on-scroll-to-visible-area (it would be good for KViews to fire an event once they enter the visible screen)<commit_after>class CodeBinActivityItemView extends ActivityItemChild

  constructor:(options, data)->
    options = $.extend
      cssClass    : "activity-item codebin"
      tooltip     :
        title     : "Code Bin"
        offset    : 3
        selector  : "span.type-icon"
    ,options
    super options,data

    @codeBinContainer = new KDTabView
      cssClass: "code-bin-container"

    @codeBinResultPane = new KDTabPaneView
      name:"Code Share"


    @codeBinHTMLPane = new KDTabPaneView
      name:"HTML"

    @codeBinCSSPane = new KDTabPaneView
      name:"CSS"

    @codeBinJSPane = new KDTabPaneView
      name:"JavaScript"

    codeBinHTMLData = @getData().attachments[0]
    codeBinCSSData = @getData().attachments[1]
    codeBinJSData = @getData().attachments[2]

    codeBinHTMLData.title = @getData().title
    codeBinCSSData.title = @getData().title
    codeBinJSData.title = @getData().title

    @codeBinHTMLView = new CodeBinSnippetView {}, codeBinHTMLData
    @codeBinCSSView = new CodeBinSnippetView {}, codeBinCSSData
    @codeBinJSView = new CodeBinSnippetView {}, codeBinJSData

    @codeBinResultView = new CodeBinResultView {}, data
    @codeBinResultView.hide()

    @codeBinResultButton = new KDButtonView
      title: "Run Code Share"
      cssClass:"clean-gray result-button"
      click:=>
        @codeBinResultButton.setTitle "Reset Code Share"
        @codeBinResultView.show()
        @resultBanner.hide()
        @codeBinCloseButton.show()
        @codeBinResultView.emit "CodeBinSourceHasChanges", @getData()
        @codeBinContainer.showPane @codeBinResultPane

    @codeBinCloseButton = new KDButtonView
      title: "Stop and Close Code Share"
      cssClass:"clean-gray hidden"
      click:=>
        @codeBinResultView.hide()
        @codeBinResultView.stopResultFrame()
        @codeBinResultView.resetResultFrame()
        @codeBinResultButton.setTitle "Run Code Share"
        @resultBanner.show()
        @codeBinCloseButton.hide()


    @codeBinForkButton = new KDButtonView
      title: "Fork this Code Share"
      cssClass:"clean-gray fork-button"
      click:=>
        @getSingleton('mainController').emit 'ContentDisplayItemForkLinkClicked', data


    @resultBanner = new KDCustomHTMLView
      tagName : "div"
      cssClass : "result-banner"
      partial : ""

    @resultBannerButton = new KDCustomHTMLView
      name : "resultBannerButton"
      tagName:"a"
      attributes:
        href:"#"
      partial : "Click here to see this Code Share!"
      cssClass : "result-banner-button"
      click:=>
        @codeBinResultButton.setTitle "Reset Code Share"
        @codeBinResultView.show()
        @resultBanner.hide()
        @codeBinCloseButton.show()
        @codeBinResultView.emit "CodeBinSourceHasChanges", @getData()


    @resultBanner.addSubView @resultBannerButton

    @codeBinResultPane.addSubView @resultBanner

    @codeBinResultPane.addSubView @codeBinResultView
    @codeBinHTMLPane.addSubView @codeBinHTMLView
    @codeBinCSSPane.addSubView @codeBinCSSView
    @codeBinJSPane.addSubView @codeBinJSView


    @codeBinContainer.addPane @codeBinResultPane
    @codeBinContainer.addPane @codeBinHTMLPane
    @codeBinContainer.addPane @codeBinCSSPane
    @codeBinContainer.addPane @codeBinJSPane

    @codeBinResultPane.hideTabCloseIcon()
    @codeBinHTMLPane.hideTabCloseIcon()
    @codeBinCSSPane.hideTabCloseIcon()
    @codeBinJSPane.hideTabCloseIcon()

    # hover switching enabled by default
    @codeBinContainer.$(".kdtabhandle").hover (event)->
      $(event.target).closest(".kdtabhandle").click()
    , noop

    @codeBinContainer.showPane @codeBinResultPane

    # setTimeout =>
    #   @codeBinResultButton.setTitle "Reset Code Share"
    #   @codeBinResultView.show()
    #   @resultBanner.hide()
    #   @codeBinCloseButton.show()
    #   @codeBinResultView.emit "CodeBinSourceHasChanges", @getData()
    #   # setTimeout =>
    #   #   @codeBinResultView.stopResultFrame()
    #   # , 10000
    # , 1000


  render:->
    super()

    codeBinHTMLData = @getData().attachments[0]
    codeBinCSSData = @getData().attachments[1]
    codeBinJSData = @getData().attachments[2]

    codeBinHTMLData.title = @getData().title
    codeBinCSSData.title = @getData().title
    codeBinJSData.title = @getData().title

    @codeBinHTMLView.setData codeBinHTMLData
    @codeBinCSSView.setData codeBinCSSData
    @codeBinJSView.setData codeBinJSData

    @codeBinHTMLView.render()
    @codeBinCSSView.render()
    @codeBinJSView.render()

  click:(event)->
    super
    if $(event.target).is(".activity-item-right-col h3")
      appManager.tell "Activity", "createContentDisplay", @getData()

  viewAppended: ->
    return if @getData().constructor is bongo.api.CCodeBinActivity
    super()
    @setTemplate @pistachio()
    @template.update()

    maxHeight = 30
    views = [@codeBinJSView,@codeBinCSSView,@codeBinHTMLView]

    for view in views
      if view.getHeight()>maxHeight
        maxHeight = view.getHeight()

    @$("pre.subview").css height:maxHeight

    initiallyPausedObserver = setInterval =>
      codeBinOffset =@$(".code-bin-source").offset().top
      scrollViewTop = @parent.parent.parent.$().scrollTop()
      scrollviewHeight = @parent.parent.parent.$().innerHeight()+scrollViewTop

      if codeBinOffset+scrollViewTop < scrollviewHeight
        if not @initiallyPaused
          @initiallyPaused = true
          @codeBinResultButton.setTitle "Reset Code Share"
          @codeBinResultView.show()
          @resultBanner.hide()
          @codeBinCloseButton.show()
          @codeBinResultView.emit "CodeBinSourceHasChanges", @getData()
          clearInterval initiallyPausedObserver
    ,500



  pistachio:->

    """
    {{> @settingsButton}}
    <span class="avatar">{{> @avatar}}</span>
{'fraction_non_alphanumeric': 0.10777145951800704, 'fraction_numerical': 0.003700695008574781, 'mean_word_length': 3.2912470952749806, 'pattern_counts': {'":': 0, '<': 8, '<?xml version=': 0, '>': 38, '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': '3527546', 'n_tokens_mistral': 3440, 'n_tokens_neox': 3334, 'n_words': 602}