Sha256: cfcb87f799ee5bcc88653077f622b9fb644c8eb378f7cf87485a1df8bf94b863

Contents?: true

Size: 761 Bytes

Versions: 2

Compression:

Stored size: 761 Bytes

Contents

class @Mercury.HistoryBuffer

  constructor: (@maxLength = 200) ->
    @index = 0
    @stack = []
    @markerRegExp = /<em class="mercury-marker"><\/em>/g


  push: (item) ->
    if $.type(item) == 'string'
      return if @stack[@index] && @stack[@index].replace(@markerRegExp, '') == item.replace(@markerRegExp, '')
    else if $.type(item) == 'object' && item.html
      return if @stack[@index] && @stack[@index].html == item.html

    @stack = @stack[0...@index + 1]
    @stack.push(item)
    @stack.shift() if @stack.length > @maxLength
    @index = @stack.length - 1


  undo: ->
    return null if @index < 1
    @index -= 1
    return @stack[@index]


  redo: ->
    return null if @index >= @stack.length - 1
    @index += 1
    return @stack[@index]

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
mercury-rails-0.1.1 app/assets/javascripts/mercury/history_buffer.js.coffee
mercury-rails-0.1.0 app/assets/javascripts/mercury/history_buffer.js.coffee