Skip to content

Commit

Permalink
Fixed SVG images sometimes loading with a size of 0,0 GH-20
Browse files Browse the repository at this point in the history
  • Loading branch information
tantaman committed Jul 1, 2012
1 parent c841f43 commit f060586
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 17 deletions.
3 changes: 3 additions & 0 deletions client/src/model/presentation/components/Image.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ define(["./Component"],
@cachedImage.src = @get("src")
console.log @get("src")

toBase64: () ->


constructor: `function ImageModel() {
Component.prototype.constructor.apply(this, arguments);
}`
Expand Down
21 changes: 13 additions & 8 deletions client/src/ui/editor/components/ImageView.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,12 @@ define(["./ComponentView"],
if @model.get("imageType") is "SVG"
@scale = svgScale

render: () ->
ComponentView.prototype.render.call(@)
$img = $("<img src=#{@model.get('src')}></img>")

_finishRender: ($img) ->
if @model.get("imageType") is "SVG"
$img.css(
width: "100%"
height: "100%"
)
# TODO: don't we need to wait for the onload callback before we grab these values..??
naturalWidth = $img[0].naturalWidth
naturalHeight = $img[0].naturalHeight

Expand All @@ -42,18 +38,27 @@ define(["./ComponentView"],
height: scale.height
)
else
width = Math.max(naturalWidth, 50);
height = Math.max(naturalHeight, 50);
@$el.css(
width: Math.max(naturalWidth, 50)
height: Math.max(naturalHeight, 50)
width: width
height: height
)
@model.set("scale", {width: naturalWidth, height: naturalHeight})
@model.set("scale", {width: width, height: height})

$img.bind("dragstart", (e) -> e.preventDefault(); false)
@$el.find(".content").append($img);
@$el.css({
top: @model.get("y")
left: @model.get("x")
})

render: () ->
ComponentView.prototype.render.call(@)
$img = $("<img src=#{@model.get('src')}></img>")
$img.load(=> @_finishRender($img))
$img.error(=> @remove())

@$el
)
)
1 change: 1 addition & 0 deletions client/web/scripts/model/presentation/components/Image.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

30 changes: 21 additions & 9 deletions client/web/scripts/ui/editor/components/ImageView.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit f060586

Please sign in to comment.