-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjphotogrid.js
executable file
·117 lines (107 loc) · 2.93 KB
/
jphotogrid.js
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
/*
* Copyright (C) 2010 Joel Sutherland
* Licenced under the MIT license
* http://www.newmediacampaigns.com/page/zoomable-jquery-image-gallery-jphotogrid
*/
(function($) {
$.fn.jphotogrid = function(settings, callback) {
settings = $.extend(true, {
activeClass: 'active',
selectedClass: 'selected',
baseCSS: {},
selectedCSS: {}
}, settings);
var url = settings.flickrbase + settings.feedapi + '?';
var first = true;
//Convert floats to absolute
function toAbsolute(el){
$(el).children().each(function(){
var pos = $(this).position();
$(this).data('ptop',Math.floor(Number(pos.top)) + 'px');
$(this).data('pleft',Math.floor(Number(pos.left)) + 'px');
}).each(function(){
placeOriginal(this);
});
}
function placeOriginal(el, animate, callback){
var dtop = $(el).data('ptop');
var dleft = $(el).data('pleft');
var props = $.extend({
top: dtop,
left: dleft
}, settings.baseCSS);
if(animate){
$(el).animate(props, 'slow', function(){
if($.isFunction(callback)) callback();
});
}
else{
$(el).css($.extend(props, {position: 'absolute'}));
}
}
function hideSelected(callback){
$container.find('.' + settings.selectedClass).each(function(){
$(this).removeClass(settings.selectedClass);
placeOriginal(this, true);
});
if($.isFunction(callback)) callback();
}
function select(el){
hideSelected(function(){
$(el).addClass('selected').removeClass('active');
$(el).animate(settings.selectedCSS, 'slow');
});
}
for(var key in settings.qstrings){
if(!first)
url += '&';
url += key + '=' + settings.qstrings[key];
first = false;
}
return $(this).each(function(){
$container = $(this);
$(this).css('position','relative');
toAbsolute(this);
$(this).children()
.css('cursor', 'pointer')
.hover(function(){
if(!$(this).hasClass(settings.selectedClass))
$(this).addClass(settings.activeClass);
},function(){
$(this).removeClass(settings.activeClass);
});
if( $.isFunction($.fn.on) ) {
$(document).on('click', '.' + settings.activeClass, function(){
select(this);
});
$(document).on('click', '.' + settings.selectedClass, function(){
hideSelected();
});
} else {
$('.' + settings.activeClass).live('click', function(){
select(this);
});
$('.' + settings.selectedClass).live('click', function(){
hideSelected();
});
}
$(this).find('div')
.hover(function(){
$(this).css('opacity', 0);
},function(){
$(this).css('opacity', .5);
})
.click(function(){
$(this).css('opacity', 0);
$li = $(this).parent();
$li.css("z-index", 99);
$li.animate({
top: 0,
left: 0,
width: '100%',
height: '400px'
}, 'slow');
});
});
}
})(jQuery);