Sha256: 05cd9268ea07e7a57750375f0548ee9f05ff14861da2230acd1c9a62d5e385a1

Contents?: true

Size: 1.99 KB

Versions: 56

Compression:

Stored size: 1.99 KB

Contents

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

  _changeSize: (e) =>
    e.preventDefault()
    e.stopImmediatePropagation()
    operation = $(e.currentTarget).data('column-resize-operation')
    @$column = $(e.currentTarget)
      .closest('.image-controls')
      .data('image')
      .closest(@_wordClasses())
    @$sibling = @$column.siblings()

    # Resize the columns
    $.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
      siblingClass = @_numberToWord(@_words.length - num)
      newSiblingClass = @_numberToWord(@_words.length - num - 1)
      newClass = @_numberToWord(num + 1)
      @_setSizes(word, newClass, siblingClass, newSiblingClass)

  _decreaseFrom: (word, num) =>
    unless num <= 2
      siblingClass = @_numberToWord(@_words.length - num)
      newSiblingClass = @_numberToWord(@_words.length - num + 1)
      newClass = @_numberToWord(num - 1)
      @_setSizes(word, newClass, siblingClass, newSiblingClass)

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

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

  _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

56 entries across 56 versions & 1 rubygems

Version Path
tenon-1.0.56 app/assets/javascripts/tenon/features/tenon_content/column_sizing.js.coffee
tenon-1.0.55 app/assets/javascripts/tenon/features/tenon_content/column_sizing.js.coffee
tenon-1.0.54 app/assets/javascripts/tenon/features/tenon_content/column_sizing.js.coffee
tenon-1.0.53 app/assets/javascripts/tenon/features/tenon_content/column_sizing.js.coffee
tenon-1.0.52 app/assets/javascripts/tenon/features/tenon_content/column_sizing.js.coffee
tenon-1.0.51 app/assets/javascripts/tenon/features/tenon_content/column_sizing.js.coffee
tenon-1.0.50 app/assets/javascripts/tenon/features/tenon_content/column_sizing.js.coffee
tenon-1.0.49 app/assets/javascripts/tenon/features/tenon_content/column_sizing.js.coffee
tenon-1.0.48 app/assets/javascripts/tenon/features/tenon_content/column_sizing.js.coffee
tenon-1.0.47 app/assets/javascripts/tenon/features/tenon_content/column_sizing.js.coffee
tenon-1.0.46 app/assets/javascripts/tenon/features/tenon_content/column_sizing.js.coffee
tenon-1.0.45 app/assets/javascripts/tenon/features/tenon_content/column_sizing.js.coffee
tenon-1.0.44 app/assets/javascripts/tenon/features/tenon_content/column_sizing.js.coffee
tenon-1.0.43 app/assets/javascripts/tenon/features/tenon_content/column_sizing.js.coffee
tenon-1.0.42 app/assets/javascripts/tenon/features/tenon_content/column_sizing.js.coffee
tenon-1.0.41 app/assets/javascripts/tenon/features/tenon_content/column_sizing.js.coffee
tenon-1.0.40 app/assets/javascripts/tenon/features/tenon_content/column_sizing.js.coffee
tenon-1.0.39 app/assets/javascripts/tenon/features/tenon_content/column_sizing.js.coffee
tenon-1.0.38 app/assets/javascripts/tenon/features/tenon_content/column_sizing.js.coffee
tenon-1.0.37 app/assets/javascripts/tenon/features/tenon_content/column_sizing.js.coffee