2
* jQuery UI Magnifier @VERSION
4
* Copyright (c) 2008 jQuery
5
* Dual licensed under the MIT (MIT-LICENSE.txt)
6
* and GPL (GPL-LICENSE.txt) licenses.
8
* http://docs.jquery.com/UI/Magnifier
17
$.widget("ui.magnifier", {
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]
32
// the element must have relative or absolute positioning
33
if (!(/^(r|a)/).test(this.element.css("position"))) {
34
this.element.css("position", "relative");
38
this.element.find(o.items).each(function() {
40
// TODO: use a hash so references to this data is readable
44
[$this.width(),$this.height()],
45
(o.overlap ? $this.position() : null)
48
(o.opacity && $this.css('opacity', o.opacity.min));
52
(o.overlap && $.each(this.items, function() {
60
this.identifier = ++counter;
61
$(document).bind("mousemove.magnifier"+this.identifier, function(e) {
62
(self.disabled || self._magnify.apply(self, [e]));
65
this.pp = this.element.offset();
71
.removeClass("ui-magnifier ui-magnifier-disabled")
72
.unbind(".magnifier");
73
$(document).unbind("mousemove.magnifier"+this.identifier);
78
$.widget.prototype.disable.apply(this, arguments);
84
$.each(this.items, function() {
89
top: (item[3] ? item[3].top : 0),
90
left: (item[3] ? item[3].left : 0)
93
(o.opacity && $(item[0]).css('opacity', o.opacity.min));
94
(o.zIndex && $(item[0]).css("z-index", ""));
98
_magnify: function(e) {
99
var p = [e.pageX,e.pageY], o = this.options, c, distance = 1;
100
this.current = this.items[0];
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; }
110
for (var i=0; i<this.items.length; i++) {
113
var olddistance = distance;
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)
121
distance = Math.abs(p[1] - ((c[3] ? this.pp.top : c[1].top ) + parseInt(c[0].style.top,10)) - (c[0].offsetHeight/2));
123
distance = Math.abs(p[0] - ((c[3] ? this.pp.left : c[1].left) + parseInt(c[0].style.left,10)) - (c[0].offsetWidth/2));
127
if (distance < o.distance) {
128
this.current = distance < olddistance ? c : this.current;
130
if (!o.axis || o.axis != "y") {
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)
137
if (!o.axis || o.axis != "x") {
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)))
145
$(c[0]).css('opacity', o.opacity.max-(distance/o.distance) < o.opacity.min ? o.opacity.min : o.opacity.max-(distance/o.distance));
151
top: (c[3] ? c[3].top : 0),
152
left: (c[3] ? c[3].left : 0)
155
(o.opacity && $(c[0]).css('opacity', o.opacity.min));
158
(o.zIndex && $(c[0]).css("z-index", ""));
161
(o.zIndex && $(this.current[0]).css("z-index", o.zIndex));
165
$.extend($.ui.magnifier, {