No regular expressions were active.
|
|
1 |
|
// jQuery
plugin - D
olphin Pro
mo Images
|
|
|
2 |
|
(function(
$){
|
|
|
3 |
|
$.fn.d
olPromo =
function(
iInterval,
fRatio )
{
|
|
|
4 |
|
fu
nction res
izeMyImage
($Img) {
|
|
|
5 |
|
$Img.css
( { width:
'auto', h
eight: 'au
to', left:
0, top: 0
} );
|
|
|
6 |
|
|
|
|
7 |
|
if( $Img
.width() >
$promo.wi
dth() ) {
|
|
|
8 |
|
var
fImgRatio
= $Img.he
ight() / $
Img.width(
);
|
|
|
9 |
|
$Img
.width( $p
romo.width
() ).heigh
t( Math.ro
und( $prom
o.width()
* fImgRati
o ) );
|
|
|
10 |
|
}
|
|
|
11 |
|
|
|
|
12 |
|
if( $Img
.height()
> $promo.h
eight() )
{
|
|
|
13 |
|
var
fImgRatio
= $Img.wid
th() / $Im
g.height()
;
|
|
|
14 |
|
$Img
.width( Ma
th.round(
$promo.hei
ght() * fI
mgRatio )
).height(
$promo.hei
ght() );
|
|
|
15 |
|
}
|
|
|
16 |
|
|
|
|
17 |
|
if( $Img
.width() <
$promo.wi
dth() ) {
|
|
|
18 |
|
var
left = Mat
h.round( (
$promo.wi
dth() - $I
mg.width()
) / 2 );
|
|
|
19 |
|
$Img
.css( 'lef
t', left )
;
|
|
|
20 |
|
}
|
|
|
21 |
|
|
|
|
22 |
|
if( $Img
.height()
< $promo.h
eight() )
{
|
|
|
23 |
|
var
top = Math
.round( (
$promo.hei
ght() - $I
mg.height(
) ) / 2 );
|
|
|
24 |
|
$Img
.css( 'top
', top );
|
|
|
25 |
|
}
|
|
|
26 |
|
}
|
|
|
27 |
|
|
|
|
28 |
|
fu
nction swi
tchThem()
{
|
|
|
29 |
|
if( type
of ePrev !
= 'undefin
ed' )
|
|
|
30 |
|
ePre
v.fadeOut(
1000 );
|
|
|
31 |
|
|
|
|
32 |
|
eNext.fa
deIn( 1000
);
|
|
|
33 |
|
|
|
|
34 |
|
ePrev =
eNext;
|
|
|
35 |
|
eNext =
eNext.next
( 'img' );
|
|
|
36 |
|
|
|
|
37 |
|
if( !eNe
xt.length
)
|
|
|
38 |
|
eNex
t = $( 'im
g:first',
$promo );
|
|
|
39 |
|
}
|
|
|
40 |
|
|
|
|
41 |
|
fu
nction res
etPromoSiz
e() {
|
|
|
42 |
|
$promo.h
eight( Mat
h.round( $
promo.widt
h() * fRat
io ) );
|
|
|
43 |
|
}
|
|
|
44 |
|
|
|
|
45 |
|
//
default pa
rameters
|
|
|
46 |
|
va
r iInterva
l = iInter
val || 300
0; //switc
hing inter
val in mil
liseconds
|
|
|
47 |
|
va
r fRatio =
fRatio ||
0.28125;
//main div
size prop
ortion (he
ight/width
)
|
|
|
48 |
|
|
|
|
49 |
|
va
r $promo =
this;
|
|
|
50 |
|
|
|
|
51 |
|
re
setPromoSi
ze();
|
|
|
52 |
|
|
|
|
53 |
|
$(
'img', $p
romo ) //g
et all ima
ges
|
|
|
54 |
|
.e
ach( funct
ion() { //
for each i
mage
|
|
|
55 |
|
var $Img
= $(this)
; //get cu
rrent imag
e
|
|
|
56 |
|
|
|
|
57 |
|
var imgO
nload = fu
nction() {
//when th
e image is
loaded
|
|
|
58 |
|
$Img
.hide();
|
|
|
59 |
|
resi
zeMyImage(
$Img );
|
|
|
60 |
|
};
|
|
|
61 |
|
|
|
|
62 |
|
if( docu
ment.all )
//ie
|
|
|
63 |
|
$Img
.ready( im
gOnload );
|
|
|
64 |
|
else
|
|
|
65 |
|
$Img
.bind( 'lo
ad', imgOn
load );
|
|
|
66 |
|
}
);
|
|
|
67 |
|
|
|
|
68 |
|
//
run switch
ing
|
|
|
69 |
|
va
r eNext =
$( 'img:fi
rst', $pro
mo );
|
|
|
70 |
|
va
r ePrev;
|
|
|
71 |
|
|
|
|
72 |
|
sw
itchThem()
;
|
|
|
73 |
|
se
tInterval(
switchThe
m, iInterv
al );
|
|
|
74 |
|
|
|
|
75 |
|
|
|
|
76 |
|
va
r iOldWidt
h = $promo
.width()
|
|
|
77 |
|
//
attach eve
nt on wind
ow resize
|
|
|
78 |
|
$(
window).re
size( func
tion() {
|
|
|
79 |
|
resetPro
moSize();
|
|
|
80 |
|
var iNew
Width = $p
romo.width
();
|
|
|
81 |
|
|
|
|
82 |
|
if( iOld
Width != i
NewWidth )
{ //if th
e main div
width is
changed
|
|
|
83 |
|
iOld
Width = $p
romo.width
();
|
|
|
84 |
|
|
|
|
85 |
|
$( '
img', $pro
mo ).each(
function(
) {
|
|
|
86 |
|
var $Img =
$(this);
|
|
|
87 |
|
resizeMyIm
age( $Img
);
|
|
|
88 |
|
} );
|
|
|
89 |
|
}
|
|
|
90 |
|
}
);
|
|
|
91 |
|
};
|
|
|
92 |
|
})(jQuery)
;
|