Sha256: 5ac1f4c54ae9f8eab273f95bad085e904e794d9af60078fb52bfd0095462a0a8

Contents?: true

Size: 1.59 KB

Versions: 83

Compression:

Stored size: 1.59 KB

Contents

class Tenon.features.tenonContent.WrappedSizing
  constructor: (@$container) ->
    $(document).on('click', '.image-controls.wrapped-image [data-column-resize-operation]', @_changeSize)

  _changeSize: (e) =>
    e.preventDefault()
    e.stopImmediatePropagation() # prevent closure of controls
    @$button = $(e.currentTarget)
    operation = @$button.data('column-resize-operation')
    @$column = @_getColumn()
    $.each @_words, (i, word) =>
      @["_#{operation}From"](word, i + 1) and false if @$column.hasClass(word)

    # Let the other classes know the size has changed
    @$column.on 'transitionend MSTransitionEnd webkitTransitionEnd oTransitionEnd', =>
      @$column.trigger('tenon.content.column_resized')

  _increaseFrom: (word, num) =>
    unless num >= @_words.length - 1
      newClass = @_numberToWord(num + 1)
      @_setSizes(word, newClass)

  _decreaseFrom: (word, num) =>
    unless num <= 2
      newClass = @_numberToWord(num - 1)
      @_setSizes(word, newClass)

  _setSizes: (oldColumn, newColumn, oldSibling, newSibling) =>
    # Resize the columns
    @$column.removeClass(oldColumn).addClass(newColumn)

    # Save the values
    @$column.find('input[name$="[size]"]').val(newColumn)

  _getColumn: =>
    @$button
      .closest('.image-controls')
      .data('image')
      .closest(@_wordClasses())

  _words: [
    'one', 'two', 'three', 'four', 'five', 'six',
    'seven', 'eight', 'nine', 'ten', 'eleven', 'twelve'
  ]

  _wordToNumber: (word)   => @_words.indexOf(word) + 1
  _numberToWord: (number) => @_words[number - 1]
  _wordClasses: => _.map(@_words, (word) -> ".#{word}").join(',')

Version data entries

83 entries across 83 versions & 1 rubygems

Version Path
tenon-1.1.8 app/assets/javascripts/tenon/features/tenon_content/wrapped_sizing.js.coffee
tenon-1.1.7 app/assets/javascripts/tenon/features/tenon_content/wrapped_sizing.js.coffee
tenon-1.1.6 app/assets/javascripts/tenon/features/tenon_content/wrapped_sizing.js.coffee
tenon-1.1.5 app/assets/javascripts/tenon/features/tenon_content/wrapped_sizing.js.coffee
tenon-1.1.4 app/assets/javascripts/tenon/features/tenon_content/wrapped_sizing.js.coffee
tenon-1.1.3 app/assets/javascripts/tenon/features/tenon_content/wrapped_sizing.js.coffee
tenon-1.1.2 app/assets/javascripts/tenon/features/tenon_content/wrapped_sizing.js.coffee
tenon-1.1.1 app/assets/javascripts/tenon/features/tenon_content/wrapped_sizing.js.coffee
tenon-1.0.76 app/assets/javascripts/tenon/features/tenon_content/wrapped_sizing.js.coffee
tenon-1.0.75 app/assets/javascripts/tenon/features/tenon_content/wrapped_sizing.js.coffee
tenon-1.0.74 app/assets/javascripts/tenon/features/tenon_content/wrapped_sizing.js.coffee
tenon-1.0.73 app/assets/javascripts/tenon/features/tenon_content/wrapped_sizing.js.coffee
tenon-1.0.72 app/assets/javascripts/tenon/features/tenon_content/wrapped_sizing.js.coffee
tenon-1.0.71 app/assets/javascripts/tenon/features/tenon_content/wrapped_sizing.js.coffee
tenon-1.0.70 app/assets/javascripts/tenon/features/tenon_content/wrapped_sizing.js.coffee
tenon-1.0.69 app/assets/javascripts/tenon/features/tenon_content/wrapped_sizing.js.coffee
tenon-1.0.68 app/assets/javascripts/tenon/features/tenon_content/wrapped_sizing.js.coffee
tenon-1.0.67 app/assets/javascripts/tenon/features/tenon_content/wrapped_sizing.js.coffee
tenon-1.0.66 app/assets/javascripts/tenon/features/tenon_content/wrapped_sizing.js.coffee
tenon-1.0.65 app/assets/javascripts/tenon/features/tenon_content/wrapped_sizing.js.coffee