| 1 |
define(["dojo/_base/declare", "dojo/dom-construct", "dojo/_base/window", "dojox/gfx", "dojox/gfx/canvas", "./MagnifierLite"], function(declare, construct, window, gfx, canvas, MagnifierLite){ |
| 2 |
|
| 3 |
return declare("dojox.image.Magnifier", MagnifierLite, { |
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
_createGlass: function(){ |
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
this.glassNode = construct.create('div', { |
| 23 |
style: { |
| 24 |
height: this.glassSize + "px", |
| 25 |
width: this.glassSize + "px" |
| 26 |
}, |
| 27 |
className: "glassNode" |
| 28 |
}, window.body()); |
| 29 |
this.surfaceNode = construct.create('div', null, this.glassNode); |
| 30 |
|
| 31 |
gfx.switchTo('canvas'); |
| 32 |
this.surface = canvas.createSurface(this.surfaceNode, this.glassSize, this.glassSize); |
| 33 |
this.img = this.surface.createImage({ |
| 34 |
src: this.domNode.src, |
| 35 |
width: this._zoomSize.w, |
| 36 |
height: this._zoomSize.h |
| 37 |
}); |
| 38 |
|
| 39 |
}, |
| 40 |
|
| 41 |
_placeGlass: function(e){ |
| 42 |
|
| 43 |
|
| 44 |
var x = e.pageX - 2, |
| 45 |
y = e.pageY - 2, |
| 46 |
xMax = this.offset.x + this.offset.w + 2, |
| 47 |
yMax = this.offset.y + this.offset.h + 2 |
| 48 |
; |
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
if(x < this.offset.x || y < this.offset.y || x > xMax || y > yMax){ |
| 53 |
this._hideGlass(); |
| 54 |
}else{ |
| 55 |
this.inherited(arguments); |
| 56 |
} |
| 57 |
}, |
| 58 |
|
| 59 |
_setImage: function(e){ |
| 60 |
|
| 61 |
|
| 62 |
|
| 63 |
var xOff = (e.pageX - this.offset.x) / this.offset.w, |
| 64 |
yOff = (e.pageY - this.offset.y) / this.offset.h, |
| 65 |
x = (this._zoomSize.w * xOff * -1)+(this.glassSize*xOff), |
| 66 |
y = (this._zoomSize.h * yOff * -1)+(this.glassSize*yOff) |
| 67 |
; |
| 68 |
|
| 69 |
this.img.setShape({ x: x, y: y }); |
| 70 |
|
| 71 |
} |
| 72 |
}); |
| 73 |
}); |