Sha256: 2f0bffd13587ec461644adf9aa349f778ebf695b720ac511659d29ab3eb3cc1c

Contents?: true

Size: 1.3 KB

Versions: 1

Compression:

Stored size: 1.3 KB

Contents

class OverlayMe.Draggable extends Backbone.View

  tagName: 'div'

  initialize: (attributes, options) ->
    super(attributes, options)
    if ( cssData = localStorage.getItem(@id) )
      $(@el).css(JSON.parse(cssData))
    else
      $(@el).css(options.default_css) unless options.default_css == undefined

  engageMove: (event) ->
    event.preventDefault()
    @moving = true
    @lastX = event.clientX
    @lastY = event.clientY
    $(window).bind 'mymousemove', (event, mouseEvent) =>
      @updateOverlay(mouseEvent.clientX - @lastX, mouseEvent.clientY - @lastY)
      @lastX = mouseEvent.clientX
      @lastY = mouseEvent.clientY
    $(@el).addClass 'on-move'

  endMove: (event) ->
    @moving = false
    $(window).unbind('mymousemove')
    $(@el).removeClass 'on-move'

  toggleMove: (event) ->
    if @moving
      @endMove(event)
    else
      @engageMove(event)

  updateOverlay: (x, y) ->
    newX = parseInt($(@el).css('left')) + x
    newY = parseInt($(@el).css('top')) + y
    $(@el).css({ top:"#{newY}px", left:"#{newX}px", right: "auto"})
    @saveCss()

  saveCss: () ->
    cssData = {
      top:$(@el).css('top'),
      left:$(@el).css('left'),
      visibility:$(@el).css('visibility'),
      opacity: $(@el).css('opacity')
    }
    localStorage.setItem(@id, JSON.stringify(cssData))

  render: ->
    @el

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
overlay_me-0.12.0 javascripts/draggable.js.coffee