-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathjquery.pdxfade.js
More file actions
234 lines (197 loc) · 9.88 KB
/
Copy pathjquery.pdxfade.js
File metadata and controls
234 lines (197 loc) · 9.88 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
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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
/*
Copyright (c) 2011 Oscar Godson (@oscargodson), City of Portland, OR
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Get the Source at: http://github.com/eGovPDX/PDXFade
*/
;(function($){
$.fn.pdxfade = function(options) {
var settings = $.extend({}, $.fn.pdxfade.defaultOptions, options);
var classNames = {
activeSlide:settings.classNamespace+'-active-slide',
slideshowWrapper:settings.classNamespace+'-slideshow-wrapper',
nextButton:settings.classNamespace+'-next',
previousButton:settings.classNamespace+'-previous',
overlay:settings.classNamespace+'-overlay',
overlayInner:settings.classNamespace+'-overlay-inner',
linkIcon:settings.classNamespace+'-link-icon'
};
return this.each(function() {
var $this = $(this)
, timer
, api = {
go: function(dir){
dir = dir || 'next';
if($this.find(':animated').length < 1){
window.clearInterval(timer);
var currentSlide = $this.find('.'+classNames.activeSlide)
, updateText = function(){
var overlay = $this.parent().find('.'+classNames.overlay);
if($this.find('.'+classNames.activeSlide+' '+settings.titleTag).length > 0 || $this.find('.'+classNames.activeSlide+' '+settings.descriptionTag).length > 0){
overlay.animate({bottom:'0px'},150);
api.updateText($this.find('.'+classNames.activeSlide+' '+settings.titleTag).text(),$this.find('.'+classNames.activeSlide+' '+settings.descriptionTag).html());
}
else{
overlay.animate({bottom:'-'+overlay.outerHeight()+'px'},150);
}
}
currentSlide.fadeOut(settings.animationTime).removeClass(classNames.activeSlide);
if(dir == 'next'){
if(currentSlide.next().length > 0){
currentSlide.next().fadeIn(settings.animationTime).addClass(classNames.activeSlide);
}
else{
$this.find('li:first').fadeIn(settings.animationTime).addClass(classNames.activeSlide);
}
}
else if(dir == 'prev' || dir == 'previous'){
if(currentSlide.prev().length > 0){
currentSlide.prev().fadeIn(settings.animationTime).addClass(classNames.activeSlide);
}
else{
$this.find('li:last').fadeIn(settings.animationTime).addClass(classNames.activeSlide);
}
}
if(!$('.'+classNames.activeSlide+' img').parent().attr('href')){
$('.'+classNames.linkIcon).hide();
}
updateText();
timer = window.setInterval(function(){ api.next(); },settings.animationTime+settings.delayTime);
}
return this;
},
//Just a shortcut to api.go('next');
next: function(){ api.go('next'); return this; },
//Just a shortcut to api.go('prev') or api.go('previous');
prev: function(){ api.go('prev'); return this; },
updateText: function(title,description){
title = title || '';
description = description || '';
$this.parent().find('.'+classNames.overlay+' '+settings.titleTag).text(title);
$this.parent().find('.'+classNames.overlay+' '+settings.descriptionTag).html(description);
return this;
}
};
timer = window.setInterval(function(){ api.next(); },settings.animationTime+settings.delayTime)
$this.css({margin:'0',padding:'0',listStyle:'none'}).find('li').css('display','block');
$this.find('img')
//Forces no caching on images so we can check when they are really loaded
.each(function(){
$(this).attr('src',$(this).attr('src')+'?rand='+Math.round(Math.random()*10001));
});
$this.find('li:first').addClass(classNames.activeSlide);
$this.find('li:not(:first)').css('display','none');
$this.find('img:first').load(function(){
if(settings.width == 'auto'){
settings.width = $(this).outerWidth()+'px'
}
if(settings.height == 'auto'){
settings.height = $(this).outerHeight()+'px'
}
$this.wrap('<div class="'+classNames.slideshowWrapper+'"></div>')
.parent('.'+classNames.slideshowWrapper)
.css({
position:'relative',
width:settings.width,
height:settings.height,
overflow:'hidden'
})
.append('<img class="'+classNames.previousButton+'" src="'+settings.assetPath+'left-arrow-'+settings.arrowColor+'.png" title="Previous Slide"><img class="'+classNames.nextButton+'" src="'+settings.assetPath+'right-arrow-'+settings.arrowColor+'.png" title="Next Slide"><img class="'+classNames.linkIcon+'" src="'+settings.assetPath+'link.gif"><div class="'+classNames.overlay+'"><div class="'+classNames.overlayInner+'"><'+settings.titleTag+'></'+settings.titleTag+'><'+settings.descriptionTag+'></'+settings.descriptionTag+'></div></div>')
.find('.'+classNames.previousButton+',.'+classNames.nextButton).load(function(){
$(this).css({
top:$this.find('img:first').outerHeight()/2-$(this).outerHeight()/2+'px',
position:'absolute',
cursor:'pointer'
}).fadeTo(0,0.5);
})
.filter('.'+classNames.previousButton).css({left:'10px'})
.click(function(){ api.prev(); })
.end()
.filter('.'+classNames.nextButton).css({right:'10px'})
.click(function(){ api.next(); });
$this.parent().find('.'+classNames.linkIcon).load(function(){
$(this).css({
position:'absolute',
top:$this.find('img:first').outerHeight()/2-$(this).outerHeight()/2+'px',
left:$this.find('img:first').outerWidth()/2-$(this).outerWidth()/2+'px',
display:'none',
cursor:'pointer'
});
});
$this.parent()
.find('.'+classNames.overlay)
.css({
position:'absolute',
bottom:'0',
width:'100%',
background:'#000',
opacity:'0.8',
filter:'alpha(opacity=80)'
})
.find('.'+classNames.overlayInner)
.css({
padding:'10px'
});
if($this.find('li:first '+settings.titleTag).text() !== '' || $this.find('li:first '+settings.descriptionTag).text() !== ''){
api.updateText($this.find('li:first '+settings.titleTag).text(),$this.find('li:first '+settings.descriptionTag).html());
}
else{
$('.'+classNames.overlay).css('bottom','-'+$(this).outerHeight()+'px');
}
//Make things fade in and out on mouseenter/leave (like arrows)
$this.parent().bind('mouseenter mouseleave',function(e){
var arrows = $('.'+classNames.previousButton+',.'+classNames.nextButton)
, to = 0.8
, href = $('.'+classNames.activeSlide+' img').parent().attr('href');
if(e.type == 'mouseleave'){ to = 0.5; }
arrows.stop(false,false).fadeTo(0,to);
//The link icon...
if(e.type == 'mouseenter'){
if(href){
$this.parent().find('.'+classNames.linkIcon).fadeTo(0,0.25,
function(){
//Fix for IE8 and the arrow images having black borders
$('.'+classNames.previousButton+',.'+classNames.nextButton).css('filter','');
})
.click(function(){
window.location = href;
});
}
}
else if(e.type == 'mouseleave'){
$this.parent().find('.'+classNames.linkIcon).hide();
}
});
//Default styles for the slideshow wrapper
$this.parent(classNames.slideshowWrapper).css({height:$(this).outerHeight()+'px'});
//Default styles for the uls,ols, lis, and imgs
$this.find('li').css({margin:'0',padding:'0',listStyle:'none', position:'absolute'});
});
});
};
$.fn.pdxfade.defaultOptions = {
animationTime:500,
delayTime:5000,
width:'auto',
height:'auto',
classNamespace:'pdxfade',
titleTag: 'h2',
descriptionTag:'p',
assetPath:'',
arrowColor:'white' //can be white or black
};
})(jQuery);