<commit_before>###
* oriDomi
* fold up the DOM
*
* <NAME>
* (c) 2012
###


root = window
$ = root.$ or false
silent = false
testEl = document.createElement 'div'
prefixList = ['Webkit', 'Moz', 'O', 'ms', 'Khtml']
transitionEnd = 'webkitTransitionEnd transitionend oTransitionEnd MSTransitionEnd KhtmlTransitionEnd'
oriDomiSupport = true


testProp = (prop) ->
  return prop if testEl.style[prop]?
  capProp = prop.charAt(0).toUpperCase() + prop.slice 1
  for prefix in prefixList
    if testEl.style[prefix + capProp]?
      return prefix + capProp
  false

# one dimensional:
extendObj = (target, source) ->
  if source isnt Object source
    !silent and console?.warn 'oriDomi: Must pass an object to extend with'
    return target
  if target isnt Object target
    target = {}
  for prop of source
    if not target[prop]?
      target[prop] = source[prop]

  target


transformProp = testProp 'transform'
transformOriginProp = testProp 'transformOrigin'
transformStyleProp = testProp 'transformStyle'
transitionProp = testProp 'transition'
perspectiveProp = testProp 'perspective'
backfaceProp = testProp 'backfaceVisibility'
gradientProp = testProp 'linearGradient'

if !transformProp or !transitionProp or !perspectiveProp or 
  !backfaceProp or !transformOriginProp or !transformStyleProp
    oriDomiSupport = false
    console?.warn 'oriDomi: Browser does not support CSS 3D tranforms, disabling'


defaults =
  vPanels: 6
  hPanels: 2
  perspective: 1000
  shading: true
  speed: .6
  oriDomiClass: 'oriDomi'
  silent: false
  smoothStart: true
  shadingIntensity: 1
  easingMethod: ''
  newClass: null


class root.OriDomi

  constructor: (@el, @settings = {}) ->
    console.time 'oridomiConstruction'
    if !(@ instanceof OriDomi)
      return new oriDomi @el, @settings
    
    silent = true if @settings.silent
    
    if !@el? or @el.nodeType isnt 1
      return !silent and console?.warn 'oriDomi: First argument must be a DOM element'
    
    {@shading, @shadingIntensity, @vPanels, @hPanels} = @settings
    @$el = $ @el if $
    elStyle = root.getComputedStyle @el

    @width = parseInt(elStyle.width, 10) +
             parseInt(elStyle.paddingLeft, 10) +
             parseInt(elStyle.paddingRight, 10)

    @height = parseInt(elStyle.height, 10) +
              parseInt(elStyle.paddingTop, 10) +
              parseInt(elStyle.paddingBottom, 10)


    @panelWidth = Math.floor(@width / @vPanels) or 1
    @panelHeight = Math.floor(@height / @hPanels) or 1
    
    @axes = ['left', 'right', 'top', 'bottom']
    @lastAnchor = @axes[0]
    @lastAngle = 0
    @panels = {}
    @stages = {}
    stage = document.createElement 'div'
    stage.style.display = 'none'
    stage.style.width = @width + 'px'
    stage.style.height = @height + 'px'
    stage.style.position = 'absolute'
    stage.style.padding = '0'
    stage.style.margin = '0'


    for axis in @axes
      @panels[axis] = []
      @stages[axis] = stage.cloneNode()
      @stages[axis].className = 'oridomi-stage-' + axis

    if @shading
      @shaders = {}
      for axis in @axes
        @shaders[axis] = {}
        if axis is 'left' or axis is 'right'
          @shaders[axis].left = []
          @shaders[axis].right = []
        else
          @shaders[axis].top = []
          @shaders[axis].bottom = []

      shader = document.createElement 'div'
      shader.style[transitionProp] = "opacity #{@settings.speed}s #{@settings.easingMethod}"
      shader.style.position = 'absolute'
      shader.style.width = '100%'
      shader.style.height = '100%'
      shader.style.opacity = '0'
      shader.style.top = '0'
      shader.style.left = '0'

    contentHolder = @el.cloneNode true
    contentHolder.classList.add 'oridomi-content'
    contentHolder.margin = '0'

    hMask = document.createElement 'div'
    hMask.className = 'oridomi-mask-h'
    hMask.style.position = 'absolute'
    hMask.style.overflow = 'hidden'
    hMask.style.height = @panelHeight + 'px'
    hMask.appendChild contentHolder

    if @shading
      topShader = shader.cloneNode()
      topShader.className = 'oridomi-shader-top'
      topShader.style.background = '-webkit-linear-gradient(top, rgba(0, 0, 0, .5) 0%, rgba(255, 255, 255, .35) 100%)'
      bottomShader = shader.cloneNode()
      bottomShader.className = 'oridomi-shader-bottom'
      bottomShader.style.background = '-webkit-linear-gradient(bottom, rgba(0, 0, 0, .5) 0%, rgba(255, 255, 255, .35) 100%)'
      hMask.appendChild topShader
      hMask.appendChild bottomShader

    hPanel = document.createElement 'div'
    hPanel.className = 'oridomi-panel-h'
    hPanel.style.width = '100%'
    hPanel.style.height = @panelHeight + 'px'
    hPanel.style.padding = '0'
    hPanel.style[transformProp] = @_transform [0, @panelHeight]
    hPanel.style[transitionProp] = "all #{@settings.speed}s #{@settings.easingMethod}"
    hPanel.style[transformOriginProp] = 'top'
    hPanel.style[transformStyleProp] = 'preserve-3d'
    hPanel.style[backfaceProp] = 'hidden'
    hPanel.appendChild hMask


    for anchor in ['top', 'bottom']
      for i in [1..@hPanels]
        panel = hPanel.cloneNode true
        content = panel.getElementsByClassName('oridomi-content')[0]

        if anchor is 'top'
          y = -((i - 1) * @panelHeight)
          if i is 1
            panel.style[transformProp] = @_transform [0, 0]
        else
          panel.style[transformOriginProp] = 'bottom'
          y = -((@hPanels * @panelHeight) - (@panelHeight * i))
          if i is 1
            panel.style[transformProp] = @_transform [0, @_getBottomAnchorCoord()]
          else
            panel.style[transformProp] = @_transform [0, -@panelHeight]
          
        content.style[transformProp] = @_transform [0, y]

        if @shading
          @shaders[anchor].top[i - 1] = panel.getElementsByClassName('oridomi-shader-top')[0]
          @shaders[anchor].bottom[i - 1] = panel.getElementsByClassName('oridomi-shader-bottom')[0]

        @panels[anchor][i - 1] = panel

        unless i is 1
          @panels[anchor][i - 2].appendChild panel

      @stages[anchor].appendChild @panels[anchor][0]


    vMask = hMask.cloneNode true
    vMask.className = 'oridomi-mask-v'
    vMask.style.width = @panelWidth + 'px'
    vMask.style.height = '100%'

    if @shading
      leftShader = vMask.getElementsByClassName('oridomi-shader-top')[0]
      leftShader.className = 'oridomi-shader-left'
      leftShader.style.background = '-webkit-linear-gradient(left, rgba(0, 0, 0, .5) 0%, rgba(255, 255, 255, .35) 100%)'
      rightShader = vMask.getElementsByClassName('oridomi-shader-bottom')[0]
      rightShader.className = 'oridomi-shader-right'
      rightShader.style.background = '-webkit-linear-gradient(right, rgba(0, 0, 0, .5) 0%, rgba(255, 255, 255, .35) 100%)'

    vPanel = hPanel.cloneNode()
    vPanel.className = 'oridomi-panel-v'
    vPanel.style.width = @panelWidth + 'px'
    vPanel.style.height = '100%'
    vPanel.style[transformProp] = @_transform [@panelWidth, 0]
    vPanel.style[transformOriginProp] = 'left'
    vPanel.appendChild vMask

    for anchor in ['left', 'right']
      for i in [1..@vPanels]
        panel = vPanel.cloneNode true
        content = panel.getElementsByClassName('oridomi-content')[0]

        if anchor is 'left'
          x = -((i - 1) * @panelWidth)
          if i is 1
            panel.style[transformProp] = @_transform [0, 0]
        else
          panel.style[transformOriginProp] = 'right'
          x = -((@vPanels * @panelWidth) - (@panelWidth * i))
          if i is 1
            panel.style[transformProp] = @_transform [@_getRightAnchorCoord(), 0]
          else
            panel.style[transformProp] = @_transform [-@panelWidth, 0]


        content.style[transformProp] = @_transform [x, 0]

        if @shading
          @shaders[anchor].left[i - 1] = panel.getElementsByClassName('oridomi-shader-left')[0]
          @shaders[anchor].right[i - 1] = panel.getElementsByClassName('oridomi-shader-right')[0]

        @panels[anchor][i - 1] = panel

        unless i is 1
          @panels[anchor][i - 2].appendChild panel

      @stages[anchor].appendChild @panels[anchor][0]


    @el.classList.add @settings.oriDomiClass
    @el.style.padding = '0'
    @el.style.width = @width + 'px'
    @el.style.height = @height + 'px'
    @el.style.backgroundColor = 'transparent'
    #@el.style[transitionProp] = "all #{@settings.speed}s #{@settings.easingMethod}"
    @el.style[perspectiveProp] = @settings.perspective
    @stages.left.style.display = 'block'
    @el.innerHTML = ''

    for axis in @axes
      @el.appendChild @stages[axis]

    @_callback @settings
    console.timeEnd 'oridomiConstruction'


  _callback: (options) ->
    if typeof options.callback is 'function'
      @panels[0].addEventListener transitionEnd, =>
        @panels[0].removeEventListener transitionEnd, true
        options.callback()
      , true


  _transform: (translation, rotation) ->
    [x, y] = translation
    if !rotation
      "translate3d(#{ x }px, #{ y }px, 0)"
    else
      [rX, rY, rZ, deg] = rotation
      "translate3d(#{ x }px, #{ y }px, 0) rotate3d(#{ rX }, #{ rY }, #{ rZ }, #{ deg }deg)"


  _normalizeAngle: (percent) -><commit_msg>moved from event listener to timeout in callback handler<commit_after>###
* oriDomi
* fold up the DOM
*
* <NAME>
* (c) 2012
###


root = window
$ = root.$ or false
silent = false
testEl = document.createElement 'div'
prefixList = ['Webkit', 'Moz', 'O', 'ms', 'Khtml']
transitionEnd = 'webkitTransitionEnd transitionend oTransitionEnd MSTransitionEnd KhtmlTransitionEnd'
oriDomiSupport = true


testProp = (prop) ->
  return prop if testEl.style[prop]?
  capProp = prop.charAt(0).toUpperCase() + prop.slice 1
  for prefix in prefixList
    if testEl.style[prefix + capProp]?
      return prefix + capProp
  false

# one dimensional:
extendObj = (target, source) ->
  if source isnt Object source
    !silent and console?.warn 'oriDomi: Must pass an object to extend with'
    return target
  if target isnt Object target
    target = {}
  for prop of source
    if not target[prop]?
      target[prop] = source[prop]

  target


transformProp = testProp 'transform'
transformOriginProp = testProp 'transformOrigin'
transformStyleProp = testProp 'transformStyle'
transitionProp = testProp 'transition'
perspectiveProp = testProp 'perspective'
backfaceProp = testProp 'backfaceVisibility'
gradientProp = testProp 'linearGradient'

if !transformProp or !transitionProp or !perspectiveProp or 
  !backfaceProp or !transformOriginProp or !transformStyleProp
    oriDomiSupport = false
    console?.warn 'oriDomi: Browser does not support CSS 3D tranforms, disabling'


defaults =
  vPanels: 6
  hPanels: 2
  perspective: 1000
  shading: true
  speed: .6
  oriDomiClass: 'oriDomi'
  silent: false
  smoothStart: true
  shadingIntensity: 1
  easingMethod: ''
  newClass: null


class root.OriDomi

  constructor: (@el, @settings = {}) ->
    console.time 'oridomiConstruction'
    if !(@ instanceof OriDomi)
      return new oriDomi @el, @settings
    
    silent = true if @settings.silent
    
    if !@el? or @el.nodeType isnt 1
      return !silent and console?.warn 'oriDomi: First argument must be a DOM element'
    
    {@shading, @shadingIntensity, @vPanels, @hPanels} = @settings
    @$el = $ @el if $
    elStyle = root.getComputedStyle @el

    @width = parseInt(elStyle.width, 10) +
             parseInt(elStyle.paddingLeft, 10) +
             parseInt(elStyle.paddingRight, 10)

    @height = parseInt(elStyle.height, 10) +
              parseInt(elStyle.paddingTop, 10) +
              parseInt(elStyle.paddingBottom, 10)


    @panelWidth = Math.floor(@width / @vPanels) or 1
    @panelHeight = Math.floor(@height / @hPanels) or 1
    
    @axes = ['left', 'right', 'top', 'bottom']
    @lastAnchor = @axes[0]
    @lastAngle = 0
    @panels = {}
    @stages = {}
    stage = document.createElement 'div'
    stage.style.display = 'none'
    stage.style.width = @width + 'px'
    stage.style.height = @height + 'px'
    stage.style.position = 'absolute'
    stage.style.padding = '0'
    stage.style.margin = '0'


    for axis in @axes
      @panels[axis] = []
      @stages[axis] = stage.cloneNode()
      @stages[axis].className = 'oridomi-stage-' + axis

    if @shading
      @shaders = {}
      for axis in @axes
        @shaders[axis] = {}
        if axis is 'left' or axis is 'right'
          @shaders[axis].left = []
          @shaders[axis].right = []
        else
          @shaders[axis].top = []
          @shaders[axis].bottom = []

      shader = document.createElement 'div'
      shader.style[transitionProp] = "opacity #{@settings.speed}s #{@settings.easingMethod}"
      shader.style.position = 'absolute'
      shader.style.width = '100%'
      shader.style.height = '100%'
      shader.style.opacity = '0'
      shader.style.top = '0'
      shader.style.left = '0'

    contentHolder = @el.cloneNode true
    contentHolder.classList.add 'oridomi-content'
    contentHolder.margin = '0'

    hMask = document.createElement 'div'
    hMask.className = 'oridomi-mask-h'
    hMask.style.position = 'absolute'
    hMask.style.overflow = 'hidden'
    hMask.style.height = @panelHeight + 'px'
    hMask.appendChild contentHolder

    if @shading
      topShader = shader.cloneNode()
      topShader.className = 'oridomi-shader-top'
      topShader.style.background = '-webkit-linear-gradient(top, rgba(0, 0, 0, .5) 0%, rgba(255, 255, 255, .35) 100%)'
      bottomShader = shader.cloneNode()
      bottomShader.className = 'oridomi-shader-bottom'
      bottomShader.style.background = '-webkit-linear-gradient(bottom, rgba(0, 0, 0, .5) 0%, rgba(255, 255, 255, .35) 100%)'
      hMask.appendChild topShader
      hMask.appendChild bottomShader

    hPanel = document.createElement 'div'
    hPanel.className = 'oridomi-panel-h'
    hPanel.style.width = '100%'
    hPanel.style.height = @panelHeight + 'px'
    hPanel.style.padding = '0'
    hPanel.style[transformProp] = @_transform [0, @panelHeight]
    hPanel.style[transitionProp] = "all #{@settings.speed}s #{@settings.easingMethod}"
    hPanel.style[transformOriginProp] = 'top'
    hPanel.style[transformStyleProp] = 'preserve-3d'
    hPanel.style[backfaceProp] = 'hidden'
    hPanel.appendChild hMask


    for anchor in ['top', 'bottom']
      for i in [1..@hPanels]
        panel = hPanel.cloneNode true
        content = panel.getElementsByClassName('oridomi-content')[0]

        if anchor is 'top'
          y = -((i - 1) * @panelHeight)
          if i is 1
            panel.style[transformProp] = @_transform [0, 0]
        else
          panel.style[transformOriginProp] = 'bottom'
          y = -((@hPanels * @panelHeight) - (@panelHeight * i))
          if i is 1
            panel.style[transformProp] = @_transform [0, @_getBottomAnchorCoord()]
          else
            panel.style[transformProp] = @_transform [0, -@panelHeight]
          
        content.style[transformProp] = @_transform [0, y]

        if @shading
          @shaders[anchor].top[i - 1] = panel.getElementsByClassName('oridomi-shader-top')[0]
          @shaders[anchor].bottom[i - 1] = panel.getElementsByClassName('oridomi-shader-bottom')[0]

        @panels[anchor][i - 1] = panel

        unless i is 1
          @panels[anchor][i - 2].appendChild panel

      @stages[anchor].appendChild @panels[anchor][0]


    vMask = hMask.cloneNode true
    vMask.className = 'oridomi-mask-v'
    vMask.style.width = @panelWidth + 'px'
    vMask.style.height = '100%'

    if @shading
      leftShader = vMask.getElementsByClassName('oridomi-shader-top')[0]
      leftShader.className = 'oridomi-shader-left'
      leftShader.style.background = '-webkit-linear-gradient(left, rgba(0, 0, 0, .5) 0%, rgba(255, 255, 255, .35) 100%)'
      rightShader = vMask.getElementsByClassName('oridomi-shader-bottom')[0]
      rightShader.className = 'oridomi-shader-right'
      rightShader.style.background = '-webkit-linear-gradient(right, rgba(0, 0, 0, .5) 0%, rgba(255, 255, 255, .35) 100%)'

    vPanel = hPanel.cloneNode()
    vPanel.className = 'oridomi-panel-v'
    vPanel.style.width = @panelWidth + 'px'
    vPanel.style.height = '100%'
    vPanel.style[transformProp] = @_transform [@panelWidth, 0]
    vPanel.style[transformOriginProp] = 'left'
    vPanel.appendChild vMask

    for anchor in ['left', 'right']
      for i in [1..@vPanels]
        panel = vPanel.cloneNode true
        content = panel.getElementsByClassName('oridomi-content')[0]

        if anchor is 'left'
          x = -((i - 1) * @panelWidth)
          if i is 1
            panel.style[transformProp] = @_transform [0, 0]
        else
          panel.style[transformOriginProp] = 'right'
          x = -((@vPanels * @panelWidth) - (@panelWidth * i))
          if i is 1
            panel.style[transformProp] = @_transform [@_getRightAnchorCoord(), 0]
          else
            panel.style[transformProp] = @_transform [-@panelWidth, 0]


        content.style[transformProp] = @_transform [x, 0]

        if @shading
          @shaders[anchor].left[i - 1] = panel.getElementsByClassName('oridomi-shader-left')[0]
          @shaders[anchor].right[i - 1] = panel.getElementsByClassName('oridomi-shader-right')[0]

        @panels[anchor][i - 1] = panel

        unless i is 1
          @panels[anchor][i - 2].appendChild panel

      @stages[anchor].appendChild @panels[anchor][0]


    @el.classList.add @settings.oriDomiClass
    @el.style.padding = '0'
    @el.style.width = @width + 'px'
    @el.style.height = @height + 'px'
    @el.style.backgroundColor = 'transparent'
    #@el.style[transitionProp] = "all #{@settings.speed}s #{@settings.easingMethod}"
    @el.style[perspectiveProp] = @settings.perspective
    @stages.left.style.display = 'block'
    @el.innerHTML = ''

    for axis in @axes
      @el.appendChild @stages[axis]

    @_callback @settings
    console.timeEnd 'oridomiConstruction'


  _callback: (options) ->
    if typeof options.callback is 'function'
      # transitionend events are unreliable at the moment unfortunately
      if @lastAngle is 0
        delay = 0
      else
        delay = @settings.speed * 1000

      setTimeout =>
        options.callback()
      , delay


  _transform: (translation, rotation) ->
    [x, y] = translation
    if !rotation
      "translate3d(#{ x }px, #{ y }px, 0)"
    else
      [rX, rY, rZ, deg] = rotation
      "translate3d(#{ x }px, #{ y }px, 0) rotate3d(#{ rX }, #{ rY }, #{ rZ }, #{ deg }deg)"


  _normalizeAngle: (percent) ->
{'fraction_non_alphanumeric': 0.13358140538208488, 'fraction_numerical': 0.019522191662622014, 'mean_word_length': 2.856103139945935, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 19, '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': '176732', 'n_tokens_mistral': 6386, 'n_tokens_neox': 5983, 'n_words': 1396}