Sha256: f028ecb55113c01eb90b4814e2228ac729c1701847a7bb2ee24a1ac3c235610d

Contents?: true

Size: 1.96 KB

Versions: 17

Compression:

Stored size: 1.96 KB

Contents

class Tenon.features.tenonContent.ImageControls
  constructor: ($container) ->
    $(document).on('click', @hideControls)
    $container.on('click', '.image img', @toggleControls)

  toggleControls: (e) =>
    @hideControls()
    @_buildControls(e)
    e.stopImmediatePropagation()

  showControls: (x, y) =>
    x ||= @previousX
    y ||= @previousY
    @$controls.appendTo('body').css
      left: @_leftOffset(x)
      top: y + 'px'
      display: 'block'

    @previousX = x
    @previousY = y

  hideControls: =>
    $('body > .image-controls').hide()
    $('.tooltip').remove()

  _removeControls: =>
    $('body > .image-controls, body > .link-form').remove()
    delete Tenon.activeImageControls

  _buildControls: (e) =>
    @_removeControls()
    Tenon.activeImageControls = this
    $img = $(e.currentTarget)
    @$image = $img.closest('.image')
    @$controls = @$image.find('.image-controls').clone()
    @_tagControls()
    @showControls(e.pageX, e.pageY)

  _tagControls: =>
    # Add some data for use in operations
    @$controls.data('image', @$image)
    @$controls.find('.replace-image')
      .data('asset-field', @$image.closest('.tn-tc-asset-field'))

    # Add some classes for targeting and styling
    if @$image.closest('.tn-tc-wrapped-image-with-text').length > 0
      @$controls.addClass('wrapped-image', true)
    else if @$image.closest('.full-width-image').length > 0
      @$controls.addClass('full-width-image')
    else if @$image.closest('.three-column-image').length > 0
      @$controls.addClass('three-column-image')
    else if @$image.closest('.four-column-image').length > 0
      @$controls.addClass('four-column-image')
    else if @$image.closest('.stacked-image-and-text').length > 0
      @$controls.addClass('stacked-image-and-text')
    else
      @$controls.addClass('column-image')

  _leftOffset: (left) =>
    if $(window).width() < 641
      (($(window).width() - @$controls.width()) / 2) + 'px'
    else
      left - (@$controls.width() / 2) + 'px'

Version data entries

17 entries across 17 versions & 1 rubygems

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