Sha256: 8d606115d7bac458e518a2dcddd5273f31f99259006a9c956a2816ac42df4831

Contents?: true

Size: 1.99 KB

Versions: 27

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 <= 1
      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

27 entries across 27 versions & 1 rubygems

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