Sha256: 0c07c0c365e7178753ac8cf2f781d3ec075060aa74eec2954e33a897641ca1e4

Contents?: true

Size: 827 Bytes

Versions: 1

Compression:

Stored size: 827 Bytes

Contents

class Photo
  constructor: (@attributes) ->
    @$ = jQuery

  load: (options = {}) ->
    deferred = @$.Deferred()

    width = options.width if options.width?

    if @attributes.width?
      if width?
        width = Math.min(width, @attributes.width)
      else
        width = @attributes.width

    if width?
      width = Math.round(width)
      url = @attributes.url.replace(/w\d+-h\d+(-p)?/, "w#{width}")
    else
      url = @attributes.url

    element = @$('<img/>')

    element
      .on 'load', ->
        element.off('load error')
        deferred.resolve(element)
        return

      .on 'error', (details...) ->
        element.off('load error')
        deferred.reject(details...)
        return

    element.attr(src: url)

    deferred.promise()

window.GooglePlus ||= {}
window.GooglePlus.Photo = Photo

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
googleplus-reader-0.0.4 lib/assets/javascripts/googleplus.photo.js.coffee