Sha256: 18dc1a7b8eb313de0f9faff82467acaba6a1211925999312f8612ce6a3e17440

Contents?: true

Size: 1.94 KB

Versions: 55

Compression:

Stored size: 1.94 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('.asset-field'))

    # Add some classes for targeting and styling
    if @$image.closest('.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

55 entries across 55 versions & 1 rubygems

Version Path
tenon-1.0.67 app/assets/javascripts/tenon/features/tenon_content/image_controls.js.coffee
tenon-1.0.66 app/assets/javascripts/tenon/features/tenon_content/image_controls.js.coffee
tenon-1.0.65 app/assets/javascripts/tenon/features/tenon_content/image_controls.js.coffee
tenon-1.0.64 app/assets/javascripts/tenon/features/tenon_content/image_controls.js.coffee
tenon-1.0.63 app/assets/javascripts/tenon/features/tenon_content/image_controls.js.coffee
tenon-1.0.62 app/assets/javascripts/tenon/features/tenon_content/image_controls.js.coffee
tenon-1.0.61 app/assets/javascripts/tenon/features/tenon_content/image_controls.js.coffee
tenon-1.0.60 app/assets/javascripts/tenon/features/tenon_content/image_controls.js.coffee
tenon-1.0.59 app/assets/javascripts/tenon/features/tenon_content/image_controls.js.coffee
tenon-1.0.57 app/assets/javascripts/tenon/features/tenon_content/image_controls.js.coffee
tenon-1.0.56 app/assets/javascripts/tenon/features/tenon_content/image_controls.js.coffee
tenon-1.0.55 app/assets/javascripts/tenon/features/tenon_content/image_controls.js.coffee
tenon-1.0.54 app/assets/javascripts/tenon/features/tenon_content/image_controls.js.coffee
tenon-1.0.53 app/assets/javascripts/tenon/features/tenon_content/image_controls.js.coffee
tenon-1.0.52 app/assets/javascripts/tenon/features/tenon_content/image_controls.js.coffee
tenon-1.0.51 app/assets/javascripts/tenon/features/tenon_content/image_controls.js.coffee
tenon-1.0.50 app/assets/javascripts/tenon/features/tenon_content/image_controls.js.coffee
tenon-1.0.49 app/assets/javascripts/tenon/features/tenon_content/image_controls.js.coffee
tenon-1.0.48 app/assets/javascripts/tenon/features/tenon_content/image_controls.js.coffee
tenon-1.0.47 app/assets/javascripts/tenon/features/tenon_content/image_controls.js.coffee