|
25 | 25 | </style>
|
26 | 26 | <script>
|
27 | 27 | $(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({ |
31 | 30 | my: "right middle",
|
32 | 31 | at: "left+25 middle",
|
33 | 32 | of: "#container",
|
34 | 33 | collision: "none",
|
35 | 34 | using: using
|
36 | 35 | });
|
37 |
| - }; |
38 |
| - $.fn.right = function( using ) { |
39 |
| - return this.position({ |
| 36 | + } |
| 37 | + function right( element, using ) { |
| 38 | + element.position({ |
40 | 39 | my: "left middle",
|
41 | 40 | at: "right-25 middle",
|
42 | 41 | of: "#container",
|
43 | 42 | collision: "none",
|
44 | 43 | using: using
|
45 | 44 | });
|
46 |
| - }; |
47 |
| - $.fn.center = function( using ) { |
48 |
| - return this.position({ |
| 45 | + } |
| 46 | + function center( element, using ) { |
| 47 | + element.position({ |
49 | 48 | my: "center middle",
|
50 | 49 | at: "center middle",
|
51 | 50 | of: "#container",
|
52 | 51 | using: using
|
53 | 52 | });
|
54 |
| - }; |
| 53 | + } |
55 | 54 |
|
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)" ) ); |
59 | 58 |
|
60 | 59 | function animate( to ) {
|
61 | 60 | $( this ).stop( true, false ).animate( to );
|
62 | 61 | }
|
63 | 62 | function next( event ) {
|
64 | 63 | 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" ) ); |
68 | 67 | }
|
69 | 68 | function previous( event ) {
|
70 | 69 | 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" ) ); |
74 | 73 | }
|
75 | 74 | $( "#previous" ).click( previous );
|
76 | 75 | $( "#next" ).click( next );
|
|
80 | 79 | });
|
81 | 80 |
|
82 | 81 | $( 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 ); |
86 | 85 | });
|
87 | 86 | });
|
88 | 87 | </script>
|
|
0 commit comments