~jstys-z/helioviewer.org/client5

« back to all changes in this revision

Viewing changes to lib/jquery/jquery.ui-1.6rc2/ui/ui.magnifier.js

  • Committer: V. Keith Hughitt
  • Date: 2009-03-26 19:20:57 UTC
  • Revision ID: hughitt1@kore-20090326192057-u0x8rf8sf5lmmnwh
nightly build 03-26-2009: Using alpha-channel JPEG 2000 dataset

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
 * jQuery UI Magnifier @VERSION
3
 
 *
4
 
 * Copyright (c) 2008 jQuery
5
 
 * Dual licensed under the MIT (MIT-LICENSE.txt)
6
 
 * and GPL (GPL-LICENSE.txt) licenses.
7
 
 *
8
 
 * http://docs.jquery.com/UI/Magnifier
9
 
 *
10
 
 * Depends:
11
 
 *  ui.core.js
12
 
 */
13
 
(function($) {
14
 
 
15
 
var counter = 0;
16
 
 
17
 
$.widget("ui.magnifier", {
18
 
        _init: function() {
19
 
                var self = this,
20
 
                        o = this.options;
21
 
                
22
 
                this.element
23
 
                        .addClass("ui-magnifier")
24
 
                        .bind('click.magnifier', function(e) {
25
 
                                (!self.disabled && o.click && o.click.apply(this, [e, {
26
 
                                        options: self.options,
27
 
                                        current: self.current[0],
28
 
                                        currentOffset: self.current[1]
29
 
                                }]));
30
 
                        });
31
 
                
32
 
                // the element must have relative or absolute positioning
33
 
                if (!(/^(r|a)/).test(this.element.css("position"))) {
34
 
                        this.element.css("position", "relative");
35
 
                }
36
 
                
37
 
                this.items = [];
38
 
                this.element.find(o.items).each(function() {
39
 
                        var $this = $(this);
40
 
                        // TODO: use a hash so references to this data is readable
41
 
                        self.items.push([
42
 
                                this,
43
 
                                $this.offset(),
44
 
                                [$this.width(),$this.height()],
45
 
                                (o.overlap ? $this.position() : null)
46
 
                        ]);
47
 
                        
48
 
                        (o.opacity && $this.css('opacity', o.opacity.min));
49
 
                });
50
 
                
51
 
                // absolutize
52
 
                (o.overlap && $.each(this.items, function() {
53
 
                        $(this[0]).css({
54
 
                                position: "absolute",
55
 
                                top: this[3].top,
56
 
                                left: this[3].left
57
 
                        });
58
 
                }));
59
 
                
60
 
                this.identifier = ++counter;
61
 
                $(document).bind("mousemove.magnifier"+this.identifier, function(e) {
62
 
                        (self.disabled || self._magnify.apply(self, [e]));
63
 
                });
64
 
                
65
 
                this.pp = this.element.offset();
66
 
        },
67
 
        
68
 
        destroy: function() {
69
 
                this.reset();
70
 
                this.element
71
 
                        .removeClass("ui-magnifier ui-magnifier-disabled")
72
 
                        .unbind(".magnifier");
73
 
                $(document).unbind("mousemove.magnifier"+this.identifier);
74
 
        },
75
 
        
76
 
        disable: function() {
77
 
                this.reset();
78
 
                $.widget.prototype.disable.apply(this, arguments);
79
 
        },
80
 
        
81
 
        reset: function(e) {
82
 
                var o = this.options;
83
 
                
84
 
                $.each(this.items, function() {
85
 
                        var item = this;
86
 
                        $(item[0]).css({
87
 
                                width: item[2][0],
88
 
                                height: item[2][1],
89
 
                                top: (item[3] ? item[3].top : 0),
90
 
                                left: (item[3] ? item[3].left : 0)
91
 
                        });
92
 
                        
93
 
                        (o.opacity && $(item[0]).css('opacity', o.opacity.min));
94
 
                        (o.zIndex && $(item[0]).css("z-index", ""));
95
 
                });
96
 
        },
97
 
        
98
 
        _magnify: function(e) {
99
 
                var p = [e.pageX,e.pageY], o = this.options, c, distance = 1;
100
 
                this.current = this.items[0];
101
 
                
102
 
                // Compute the parent's distance
103
 
                // we don't need to fire anything if we are not near the parent
104
 
                var overlap = ((p[0] > this.pp.left-o.distance) &&
105
 
                        (p[0] < this.pp.left + this.element[0].offsetWidth + o.distance) &&
106
 
                        (p[1] > this.pp.top-o.distance) &&
107
 
                        (p[1] < this.pp.top + this.element[0].offsetHeight + o.distance));
108
 
                if (!overlap) { return false; }
109
 
                
110
 
                for (var i=0; i<this.items.length; i++) {
111
 
                        c = this.items[i];
112
 
                        
113
 
                        var olddistance = distance;
114
 
                        if (!o.axis) {
115
 
                                distance = Math.sqrt(
116
 
                                          Math.pow(p[0] - ((c[3] ? this.pp.left : c[1].left) + parseInt(c[0].style.left,10)) - (c[0].offsetWidth/2), 2)
117
 
                                        + Math.pow(p[1] - ((c[3] ? this.pp.top  : c[1].top ) + parseInt(c[0].style.top,10)) - (c[0].offsetHeight/2), 2)
118
 
                                );
119
 
                        } else {
120
 
                                if(o.axis == "y") {
121
 
                                        distance = Math.abs(p[1] - ((c[3] ? this.pp.top  : c[1].top ) + parseInt(c[0].style.top,10)) - (c[0].offsetHeight/2));
122
 
                                } else {
123
 
                                        distance = Math.abs(p[0] - ((c[3] ? this.pp.left : c[1].left) + parseInt(c[0].style.left,10)) - (c[0].offsetWidth/2));
124
 
                                }
125
 
                        }
126
 
                        
127
 
                        if (distance < o.distance) {
128
 
                                this.current = distance < olddistance ? c : this.current;
129
 
                                
130
 
                                if (!o.axis || o.axis != "y") {
131
 
                                        $(c[0]).css({
132
 
                                                width: c[2][0]+ (c[2][0] * (o.magnification-1)) - (((distance/o.distance)*c[2][0]) * (o.magnification-1)),
133
 
                                                left: (c[3] ? (c[3].left + o.verticalLine * ((c[2][1] * (o.magnification-1)) - (((distance/o.distance)*c[2][1]) * (o.magnification-1)))) : 0)
134
 
                                        });
135
 
                                }
136
 
                                
137
 
                                if (!o.axis || o.axis != "x") {
138
 
                                        $(c[0]).css({
139
 
                                                height: c[2][1]+ (c[2][1] * (o.magnification-1)) - (((distance/o.distance)*c[2][1]) * (o.magnification-1)),
140
 
                                                top: (c[3] ? c[3].top : 0) + (o.baseline-0.5) * ((c[2][0] * (o.magnification-1)) - (((distance/o.distance)*c[2][0]) * (o.magnification-1)))
141
 
                                        });
142
 
                                }
143
 
                                
144
 
                                if (o.opacity) {
145
 
                                        $(c[0]).css('opacity', o.opacity.max-(distance/o.distance) < o.opacity.min ? o.opacity.min : o.opacity.max-(distance/o.distance));
146
 
                                }
147
 
                        } else {
148
 
                                $(c[0]).css({
149
 
                                        width: c[2][0],
150
 
                                        height: c[2][1],
151
 
                                        top: (c[3] ? c[3].top : 0),
152
 
                                        left: (c[3] ? c[3].left : 0)
153
 
                                });
154
 
                                
155
 
                                (o.opacity && $(c[0]).css('opacity', o.opacity.min));
156
 
                        }
157
 
                        
158
 
                        (o.zIndex && $(c[0]).css("z-index", ""));
159
 
                }
160
 
                
161
 
                (o.zIndex && $(this.current[0]).css("z-index", o.zIndex));
162
 
        }
163
 
});
164
 
 
165
 
$.extend($.ui.magnifier, {
166
 
        defaults: {
167
 
                distance: 150,
168
 
                magnification: 2,
169
 
                baseline: 0,
170
 
                verticalLine: -0.5,
171
 
                items: "> *"
172
 
        }
173
 
});
174
 
 
175
 
})(jQuery);