Skip to content

Commit 16f421f

Browse files
committed
Position demo: Address todo comment by replacing plugin methods
1 parent 62c9a9c commit 16f421f

File tree

1 file changed

+21
-22
lines changed

1 file changed

+21
-22
lines changed

demos/position/cycler.html

Lines changed: 21 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -25,52 +25,51 @@
2525
</style>
2626
<script>
2727
$(function() {
28-
// TODO refactor into a widget and get rid of these plugin methods
29-
$.fn.left = function( using ) {
30-
return this.position({
28+
function left( element, using ) {
29+
element.position({
3130
my: "right middle",
3231
at: "left+25 middle",
3332
of: "#container",
3433
collision: "none",
3534
using: using
3635
});
37-
};
38-
$.fn.right = function( using ) {
39-
return this.position({
36+
}
37+
function right( element, using ) {
38+
element.position({
4039
my: "left middle",
4140
at: "right-25 middle",
4241
of: "#container",
4342
collision: "none",
4443
using: using
4544
});
46-
};
47-
$.fn.center = function( using ) {
48-
return this.position({
45+
}
46+
function center( element, using ) {
47+
element.position({
4948
my: "center middle",
5049
at: "center middle",
5150
of: "#container",
5251
using: using
5352
});
54-
};
53+
}
5554

56-
$( "img:eq(0)" ).left();
57-
$( "img:eq(1)" ).center();
58-
$( "img:eq(2)" ).right();
55+
left( $( "img:eq(0)" ) );
56+
center( $( "img:eq(1)" ) );
57+
right( $( "img:eq(2)" ) );
5958

6059
function animate( to ) {
6160
$( this ).stop( true, false ).animate( to );
6261
}
6362
function next( event ) {
6463
event.preventDefault();
65-
$( "img:eq(2)" ).center( animate );
66-
$( "img:eq(1)" ).left( animate );
67-
$( "img:eq(0)" ).right().appendTo( "#container" );
64+
center( $( "img:eq(2)" ), animate );
65+
left( $( "img:eq(1)" ), animate );
66+
right( $( "img:eq(0)" ).appendTo( "#container" ) );
6867
}
6968
function previous( event ) {
7069
event.preventDefault();
71-
$( "img:eq(0)" ).center( animate );
72-
$( "img:eq(1)" ).right( animate );
73-
$( "img:eq(2)" ).left().prependTo( "#container" );
70+
center( $( "img:eq(0)" ), animate );
71+
right( $( "img:eq(1)" ), animate );
72+
left( $( "img:eq(2)" ).prependTo( "#container" ) );
7473
}
7574
$( "#previous" ).click( previous );
7675
$( "#next" ).click( next );
@@ -80,9 +79,9 @@
8079
});
8180

8281
$( window ).resize(function() {
83-
$( "img:eq(0)" ).left( animate );
84-
$( "img:eq(1)" ).center( animate );
85-
$( "img:eq(2)" ).right( animate );
82+
left( $( "img:eq(0)" ), animate );
83+
center( $( "img:eq(1)" ), animate );
84+
right( $( "img:eq(2)" ), animate );
8685
});
8786
});
8887
</script>

0 commit comments

Comments
 (0)