Mercurial > mozilla-the-big-picture
changeset 7:90e484302486
Fixed some bugs.
author | Atul Varma <varmaa@toolness.com> |
---|---|
date | Fri, 27 Nov 2009 14:47:52 -0500 |
parents | 84878cbf5cf1 |
children | cd71f59b38f4 |
files | cropper.js |
diffstat | 1 files changed, 22 insertions(+), 16 deletions(-) [+] |
line wrap: on
line diff
--- a/cropper.js Fri Nov 27 14:20:38 2009 -0500 +++ b/cropper.js Fri Nov 27 14:47:52 2009 -0500 @@ -39,32 +39,32 @@ observe: function observe(subject, topic) { var selection = this.selectableImage.getSelection(); var ctx = this.canvas.getContext("2d"); - ctx.drawImage( - this.selectableImage.img, - selection.left, - selection.top, - selection.width, - selection.height, - 0, - 0, - this.size, - this.size - ); + if (selection.width == 0 || selection.height == 0) { + ctx.fillStyle = "rgb(255,255,255)"; + ctx.fillRect(0, 0, this.size, this.size); + } else + ctx.drawImage(this.selectableImage.img, + selection.left, + selection.top, + selection.width, + selection.height, + 0, + 0, + this.size, + this.size); } }; function SelectableImage(url, canvas) { var img = new Image(); + this._isLoading = true; img._parent = this; img.onload = this.onImgLoad; img.src = url; canvas._parent = this; - $(canvas).mousedown(this.onDragStart); - $(canvas).mouseup(this.onDragStop); - this.isDirty = false; this.canvas = canvas; this.img = img; @@ -79,9 +79,13 @@ onImgLoad: function onImgLoad(evt) { var self = evt.target._parent; + self._isLoading = false; self.canvas.width = self.img.width; self.canvas.height = self.img.height; + $(self.canvas).mousedown(self.onDragStart); + $(self.canvas).mouseup(self.onDragStop); self._markDirty(); + self._observers.notify("selection-changed"); }, onDragStart: function onDragStart(evt) { @@ -132,8 +136,10 @@ setSelection: function setSelection(selection) { this._selection = selection; - this._markDirty(); - this._observers.notify("selection-changed"); + if (!this._isLoading) { + this._markDirty(); + this._observers.notify("selection-changed"); + } }, getSelection: function getSelection() {