<commit_before>#= require ./../services/panes
#= require ./../services/url
#= require ./../services/settings
#= require ./../services/session
#= require ./../services/notifier


module = angular.module("plunker.panes")

module.requires.push "plunker.url"
module.requires.push "plunker.session"
module.requires.push "plunker.settings"
module.requires.push "plunker.notifier"


module.service "previewer", ["$http", "$timeout", "url", "settings", "notifier", ($http, $timeout, url, settings, notifier) ->
]

module.run [ "$q", "$document", "$timeout", "url", "panes", "session", "settings", "notifier", ($q, $document, $timeout, url, panes, session, settings, notifier) ->
  
  genid = (len = 16, prefix = "", keyspace = "<KEY>") ->
    prefix += keyspace.charAt(Math.floor(Math.random() * keyspace.length)) while len-- > 0
    prefix
      
  panes.add
    id: "preview"
    icon: "eye-open"
    order: 1
    title: "Live Preview"
    description: """
      See a live preview of your code on the web in either a pane or as a pop-out window.
    """
    size: "50%"
    template: """
      <div class="plunker-previewer" ng-switch on="mode">
        <div ng-switch-when="embedded">
          <div class="plunker-previewer-ops">
            <div class="btn-toolbar">
              <div class="btn-group">
                <button id="refresh-preview" ng-click="refresh()" class="btn btn-mini btn-success" title="Manually trigger a refresh of the preview"><i class="icon-refresh icon-white"></i></button>
                <button id="expand-preview" ng-click="expand()" class="btn btn-mini btn-primary" title="Launch the preview in a separate window"><i class="icon-fullscreen icon-white"></i></button>
              </div>
            </div>
          </div>
          <iframe name="plunkerPreviewTarget" src="about:blank" class="plunker-previewer-iframe" frameborder="0" width="100%" height="100%" scrolling="auto"></iframe>
        </div>
        <div ng-switch-when="windowed">
          <div class="well">
            <h4>Previeweing in windowed mode</h4>
            <p>You've switched to previewing your work in windowed mode. This can be useful for using the developer tools without having to navigate
              down through the iframe that is used for the in-window preview.</p>
            <p>You can return to the in-window preview at any time simply by clicking below.</p>
            <p>
              <button class="btn btn-success" ng-click="refresh()">
                <i class="icon-refresh"></i>
                Refresh
              </button>
              <button class="btn btn-danger" ng-click="contract()">
                <i class="icon-remove"></i>
                Close
              </button>
            </p>
          </div>
        </div>
      </div>
    """
    link: ($scope, $el, attrs) ->
      pane = @
      iframe = $("iframe.plunker-previewer-iframe", $el)[0]
      childWindow = null
      
      $scope.previewUrl ||= "#{url.run}/#{genid()}/" # Create a random new preview id
      $scope.iframeUrl = "about:blank" # Initial url until a windowed -> embedded switch
      $scope.session = session
      $scope.mode = "disabled"
      
      $scope.expand = -> $scope.mode = "windowed"
      $scope.contract = -> $scope.mode = if pane.active then "embedded" else "disabled"
      
      $scope.refresh = -> $timeout ->
        return if $scope.mode is "disabled"
        
        form = document.createElement("form")
        form.style.display = "none"
        form.setAttribute "method", "post"
        form.setAttribute "action", $scope.previewUrl
        form.setAttribute "target", "plunkerPreviewTarget"
        
        for filename, file of session.toJSON().files
          field = document.createElement("input")
          field.setAttribute "type", "hidden"
          field.setAttribute "name", "files[#{filename}][content]"
          field.setAttribute "value", file.content
          
          form.appendChild(field)
        
        document.body.appendChild(form)
        
        form.submit()
        
        document.body.removeChild(form)
      
      $scope.$watch "mode", (mode, old_mode) ->
        switch mode
          when "embedded"
            childWindow?.close()
            childWindow = null
          
            $timeout -> $scope.refresh() # Refresh on next tick to make sure DOM udpated first
          when "windowed"
            childWindow = window.open "about:blank", "plunkerPreviewTarget", "resizable=yes,scrollbars=yes,status=yes,toolbar=yes"
            $timeout -> $scope.refresh() # Refresh on next tick to make sure DOM udpated first
            
      
      $scope.$watch "pane.active", (active) ->
        if !active and $scope.mode is "embedded" then $scope.mode = "disabled"
        if active and $scope.mode is "disabled" then $timeout ->
          $scope.mode = "embedded"
        
      $scope.$watch "session.updated_at", ->
        $scope.refresh() if settings.previewer.auto_refresh and (pane.active or $scope.mode is "windowed")
      
      setInterval ->
        if $scope.mode is "windowed" and childWindow?.closed
          $scope.$apply ->
            $scope.contract()
            childWindow = null
      , 1000
]<commit_msg>[hack] avoid  re: angular/angular.js#2491, angular/angular.js#1522. Re: filearts/plunker#49<commit_after>#= require ./../services/panes
#= require ./../services/url
#= require ./../services/settings
#= require ./../services/session
#= require ./../services/notifier


module = angular.module("plunker.panes")

module.requires.push "plunker.url"
module.requires.push "plunker.session"
module.requires.push "plunker.settings"
module.requires.push "plunker.notifier"


module.service "previewer", ["$http", "$timeout", "url", "settings", "notifier", ($http, $timeout, url, settings, notifier) ->
]

module.run [ "$q", "$document", "$timeout", "url", "panes", "session", "settings", "notifier", ($q, $document, $timeout, url, panes, session, settings, notifier) ->
  
  genid = (len = 16, prefix = "", keyspace = "<KEY>") ->
    prefix += keyspace.charAt(Math.floor(Math.random() * keyspace.length)) while len-- > 0
    prefix
      
  panes.add
    id: "preview"
    icon: "eye-open"
    order: 1
    title: "Live Preview"
    description: """
      See a live preview of your code on the web in either a pane or as a pop-out window.
    """
    size: "50%"
    template: """
      <div class="plunker-previewer" ng-switch on="mode">
        <div ng-switch-when="embedded">
          <div class="plunker-previewer-ops">
            <div class="btn-toolbar">
              <div class="btn-group">
                <button id="refresh-preview" ng-click="refresh()" class="btn btn-mini btn-success" title="Manually trigger a refresh of the preview"><i class="icon-refresh icon-white"></i></button>
                <button id="expand-preview" ng-click="expand()" class="btn btn-mini btn-primary" title="Launch the preview in a separate window"><i class="icon-fullscreen icon-white"></i></button>
              </div>
            </div>
          </div>
          <iframe name="plunkerPreviewTarget" src="about:blank" class="plunker-previewer-iframe" frameborder="0" width="100%" height="100%" scrolling="auto"></iframe>
        </div>
        <div ng-switch-when="windowed">
          <div class="well">
            <h4>Previeweing in windowed mode</h4>
            <p>You've switched to previewing your work in windowed mode. This can be useful for using the developer tools without having to navigate
              down through the iframe that is used for the in-window preview.</p>
            <p>You can return to the in-window preview at any time simply by clicking below.</p>
            <p>
              <button class="btn btn-success" ng-click="refresh()">
                <i class="icon-refresh"></i>
                Refresh
              </button>
              <button class="btn btn-danger" ng-click="contract()">
                <i class="icon-remove"></i>
                Close
              </button>
            </p>
          </div>
        </div>
      </div>
    """
    link: ($scope, $el, attrs) ->
      pane = @
      iframe = $("iframe.plunker-previewer-iframe", $el)[0]
      childWindow = null
      
      $scope.previewUrl ||= "#{url.run}/#{genid()}/" # Create a random new preview id
      $scope.iframeUrl = "about:blank" # Initial url until a windowed -> embedded switch
      $scope.session = session
      $scope.mode = "disabled"
      
      $scope.expand = -> $scope.mode = "windowed"
      $scope.contract = -> $scope.mode = if pane.active then "embedded" else "disabled"
      
      $scope.refresh = ->
        return if $scope.mode is "disabled"
        
        form = document.createElement("form")
        form.style.display = "none"
        form.setAttribute "method", "post"
        form.setAttribute "action", $scope.previewUrl
        form.setAttribute "target", "plunkerPreviewTarget"
        
        for filename, file of session.toJSON().files
          field = document.createElement("input")
          field.setAttribute "type", "hidden"
          field.setAttribute "name", "files[#{filename}][content]"
          field.setAttribute "value", file.content
          
          form.appendChild(field)
        
        document.body.appendChild(form)
        
        form.submit()
        
        document.body.removeChild(form)
      
      $scope.$watch "mode", (mode, old_mode) ->
        switch mode
          when "embedded"
            childWindow?.close()
            childWindow = null
          when "windowed"
            childWindow = window.open "about:blank", "plunkerPreviewTarget", "resizable=yes,scrollbars=yes,status=yes,toolbar=yes"
          else
            return # Return to prevent refresh
        
        # Refresh on next tick to make sure DOM udpated first
        setTimeout -> $scope.$apply -> $scope.refresh()
            
      
      $scope.$watch "pane.active", (active) ->
        if !active and $scope.mode is "embedded" then $scope.mode = "disabled"
        if active and $scope.mode is "disabled" then setTimeout -> $scope.$apply ->
          $scope.mode = "embedded"
        
      $scope.$watch "session.updated_at", ->
        $scope.refresh() if settings.previewer.auto_refresh and (pane.active or $scope.mode is "windowed")
    
      @startInterval($scope)
      
    startInterval: ($scope) ->
      setInterval ->
        if $scope.mode is "windowed" and childWindow?.closed
          $scope.$apply ->
            $scope.contract()
            childWindow = null
      , 1000
]
{'fraction_non_alphanumeric': 0.14415094339622642, 'fraction_numerical': 0.0047169811320754715, 'mean_word_length': 2.259840098400984, 'pattern_counts': {'":': 0, '<': 85, '<?xml version=': 0, '>': 122, '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': '1663559', 'n_tokens_mistral': 3103, 'n_tokens_neox': 3006, 'n_words': 794}