lib/assets/javascripts/googleplus.photo.js.coffee in googleplus-reader-0.0.7 vs lib/assets/javascripts/googleplus.photo.js.coffee in googleplus-reader-0.1.0
- old
+ new
@@ -8,26 +8,11 @@
constructor: (@attributes) ->
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
@@ -35,8 +20,18 @@
.on 'error', (details...) ->
element.off('load error')
deferred.reject(details...)
return
- element.attr(src: url)
+ element.attr(src: @url(options))
deferred.promise()
+
+ url: (options = {}) ->
+ if options.width? and @attributes.preview_url?
+ width = options.width
+ width = Math.min(width, @attributes.width) if @attributes.width?
+ width = Math.round(width)
+ @attributes.preview_url.replace(/w\d+-h\d+(-p)?/, "w#{width}")
+
+ else
+ @attributes.url or @attributes.preview_url