source: Dev/trunk/src/client/dojox/image/Magnifier.js @ 529

Last change on this file since 529 was 483, checked in by hendrikvanantwerpen, 11 years ago

Added Dojo 1.9.3 release.

File size: 2.3 KB
Line 
1define(["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                // summary:
5                //              Adds magnification on a portion of an image element, using `dojox.gfx`
6                //
7                // description:
8                //              An unobtrusive way to add an unstyled overlay
9                //              above the srcNode image element. The overlay/glass is a
10                //              scaled version of the src image (so larger images sized down
11                //              are clearer).
12                //
13                //              over-ride the _createGlass method to create your custom surface,
14                //              being sure to create an img node on that surface.
15
16                _createGlass: function(){
17                        // summary:
18                        //              create the glassNode, and an img on a dojox.gfx surface
19
20                        // images are hard to make into workable templates, so just add outer overlay
21                        // and skip using dijit._Templated
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                        // summary:
43                        //              position the overlay centered under the cursor
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                        // with svg, our mouseout connection to the image surface doesn't
51                        // fire, so we'r have to manually calculate offsets
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                        // summary:
61                        //              set the image's offset in the clipping window relative to the mouse position
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                        // set the image offset
69                        this.img.setShape({ x: x, y: y });
70
71                }
72        });     
73});
Note: See TracBrowser for help on using the repository browser.