Sha256: cb5b8ce2f73c5fc222dcec22ec833df45b86fc1a33d1bc1793b7777c1f9641e8

Contents?: true

Size: 958 Bytes

Versions: 4

Compression:

Stored size: 958 Bytes

Contents

class Trix.ObjectGroup
  @groupObjects: (ungroupedObjects = [], {depth, asTree} = {}) ->
    depth ?= 0 if asTree
    objects = []
    for object in ungroupedObjects
      if group
        if object.canBeGrouped?(depth) and group[group.length - 1].canBeGroupedWith?(object, depth)
          group.push(object)
          continue
        else
          objects.push(new this group, {depth, asTree})
          group = null

      if object.canBeGrouped?(depth)
        group = [object]
      else
        objects.push(object)

    if group
      objects.push(new this group, {depth, asTree})
    objects

  constructor: (@objects = [], {depth, asTree}) ->
    if asTree
      @depth = depth
      @objects = @constructor.groupObjects(@objects, {asTree, depth: @depth + 1})

  getObjects: ->
    @objects

  getDepth: ->
    @depth

  getCacheKey: ->
    keys = ["objectGroup"]
    keys.push(object.getCacheKey()) for object in @getObjects()
    keys.join("/")

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
vapid-0.1.3 lib/vapid/vendor/trix/src/trix/core/collections/object_group.coffee
vapid-0.1.2 lib/vapid/vendor/trix/src/trix/core/collections/object_group.coffee
vapid-0.1.1 lib/vapid/vendor/trix/src/trix/core/collections/object_group.coffee
vapid-0.1.0 lib/vapid/vendor/trix/src/trix/core/collections/object_group.coffee