Sha256: b166fab2e39dc832fe4cfd7099cc553952c8a2856fa0cd6e39412fa43fc77330

Contents?: true

Size: 1.13 KB

Versions: 4

Compression:

Stored size: 1.13 KB

Contents

#= require trix/models/attachment
#= require trix/models/piece

Trix.Piece.registerType "attachment", class Trix.AttachmentPiece extends Trix.Piece
  @fromJSON: (pieceJSON) ->
    new this Trix.Attachment.fromJSON(pieceJSON.attachment), pieceJSON.attributes

  constructor: (@attachment) ->
    super
    @length = 1
    @ensureAttachmentExclusivelyHasAttribute("href")

  ensureAttachmentExclusivelyHasAttribute: (attribute) ->
    if @hasAttribute(attribute) and @attachment.hasAttribute(attribute)
      @attributes = @attributes.remove(attribute)

  getValue: ->
    @attachment

  isSerializable: ->
    not @attachment.isPending()

  getCaption: ->
    @attributes.get("caption") ? ""

  getAttributesForAttachment: ->
    @attributes.slice(["caption"])

  canBeGrouped: ->
    super and not @attachment.hasAttribute("href")

  isEqualTo: (piece) ->
    super and @attachment.id is piece?.attachment?.id

  toString: ->
    Trix.OBJECT_REPLACEMENT_CHARACTER

  toJSON: ->
    json = super
    json.attachment = @attachment
    json

  getCacheKey: ->
    [super, @attachment.getCacheKey()].join("/")

  toConsole: ->
    JSON.stringify(@toString())

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
vapid-0.1.3 lib/vapid/vendor/trix/src/trix/models/attachment_piece.coffee
vapid-0.1.2 lib/vapid/vendor/trix/src/trix/models/attachment_piece.coffee
vapid-0.1.1 lib/vapid/vendor/trix/src/trix/models/attachment_piece.coffee
vapid-0.1.0 lib/vapid/vendor/trix/src/trix/models/attachment_piece.coffee