-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmagnify.jquery.js
More file actions
77 lines (72 loc) · 2.46 KB
/
magnify.jquery.js
File metadata and controls
77 lines (72 loc) · 2.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
/*!
* jQuery magnify a short hand method for preview of thumbnailed images on mouseover/mouseenter event
* Author: Kolatzek
* Licensed under the MIT license
*/
(function( $ ) {
var settings = {
preload: true,
imgDivClass: 'fullIMG',
maxX: 450,
maxY: 300
};
var methods = {
init : function( options ) {
return this.each(function(){
var opt = $.extend({}, settings, options);
if($(this).children('a').length != 0) {
$(this).bind('mouseenter.magnify', opt, methods.showFullImg);
$(this).bind('mouseleave.magnify', opt, methods.hideFullImg);
if(settings.preload){
var img = $(this).children('a').first().attr('href');
var tmpimg = '<img src="'+img+'" id="tmp_img_magnify_"/>';
$('body').append(tmpimg);
$('#tmp_img_magnify_').remove();
}
}
});
},
destroy : function( ) {
return this.each(function(){
$(window).unbind('.magnify');
})
},
showFullImg : function( event ) {
var settings = $.extend({}, event.data);
var img = $(event.target).children('a').first().attr('href');
if(img) {
var id = $(event.target).attr('id');
if(!id) {
id = $(event.target).children('a').first().attr('href').replace(/[^a-zA-Z]/g, '');
$(event.target).attr('id', id)
}
if( $('#'+id+'_prev').length == 0 ) {
var newDIV = $('<div class="'+settings.imgDivClass+'" id="'+id+'_prev"><img src="'+img+'" style="max-width: '+settings.maxX+'; max-height: '+settings.maxY+';"/></div>').css('position','absolute').hide();
$('#'+id).append(newDIV);
}
var pos = $(event.target).offset();
if( (pos.left + $('#'+id).outerWidth(true) + $('#'+id+'_prev').outerWidth(true)) > $(document).outerWidth(true)) {
pos.left=pos.left-$('#'+id+'_prev').outerWidth(true);
}
else {
pos.left=pos.left+$('#'+id).outerWidth(true);
}
$('#'+id+'_prev').css('top', Math.round(pos.top)).css('left', Math.round(pos.left));
$('#'+id+'_prev, #'+id+'_prev img').fadeIn();
}
},
hideFullImg : function( event ) {
var settings = $.extend({}, event.data);
$('.'+settings.imgDivClass).hide();
}
};
$.fn.magnify = function(method){
if ( methods[method] ) {
return methods[method].apply( this, Array.prototype.slice.call( arguments, 1 ));
} else if ( typeof method === 'object' || ! method ) {
return methods.init.apply( this, arguments );
} else {
$.error( 'Method ' + method + ' does not exist on jQuery.myplugin' );
}
}
})( jQuery );