]> source.dussan.org Git - jquery-ui.git/commitdiff
Position demo: Address todo comment by replacing plugin methods
authorJörn Zaefferer <joern.zaefferer@gmail.com>
Thu, 24 Apr 2014 10:15:51 +0000 (12:15 +0200)
committerJörn Zaefferer <joern.zaefferer@gmail.com>
Thu, 24 Apr 2014 10:15:51 +0000 (12:15 +0200)
demos/position/cycler.html

index 83320d94f01ad9b108bdb9e9076a0da9b71c16ee..873cac58f6709d94717bfeba946035a3af77014d 100644 (file)
        </style>
        <script>
        $(function() {
-               // TODO refactor into a widget and get rid of these plugin methods
-               $.fn.left = function( using ) {
-                       return this.position({
+               function left( element, using ) {
+                       element.position({
                                my: "right middle",
                                at: "left+25 middle",
                                of: "#container",
                                collision: "none",
                                using: using
                        });
-               };
-               $.fn.right = function( using ) {
-                       return this.position({
+               }
+               function right( element, using ) {
+                       element.position({
                                my: "left middle",
                                at: "right-25 middle",
                                of: "#container",
                                collision: "none",
                                using: using
                        });
-               };
-               $.fn.center = function( using ) {
-                       return this.position({
+               }
+               function center( element, using ) {
+                       element.position({
                                my: "center middle",
                                at: "center middle",
                                of: "#container",
                                using: using
                        });
-               };
+               }
 
-               $( "img:eq(0)" ).left();
-               $( "img:eq(1)" ).center();
-               $( "img:eq(2)" ).right();
+               left( $( "img:eq(0)" ) );
+               center( $( "img:eq(1)" ) );
+               right( $( "img:eq(2)" ) );
 
                function animate( to ) {
                        $( this ).stop( true, false ).animate( to );
                }
                function next( event ) {
                        event.preventDefault();
-                       $( "img:eq(2)" ).center( animate );
-                       $( "img:eq(1)" ).left( animate );
-                       $( "img:eq(0)" ).right().appendTo( "#container" );
+                       center( $( "img:eq(2)" ), animate );
+                       left( $( "img:eq(1)" ), animate );
+                       right( $( "img:eq(0)" ).appendTo( "#container" ) );
                }
                function previous( event ) {
                        event.preventDefault();
-                       $( "img:eq(0)" ).center( animate );
-                       $( "img:eq(1)" ).right( animate );
-                       $( "img:eq(2)" ).left().prependTo( "#container" );
+                       center( $( "img:eq(0)" ), animate );
+                       right( $( "img:eq(1)" ), animate );
+                       left( $( "img:eq(2)" ).prependTo( "#container" ) );
                }
                $( "#previous" ).click( previous );
                $( "#next" ).click( next );
@@ -80,9 +79,9 @@
                });
 
                $( window ).resize(function() {
-                       $( "img:eq(0)" ).left( animate );
-                       $( "img:eq(1)" ).center( animate );
-                       $( "img:eq(2)" ).right( animate );
+                       left( $( "img:eq(0)" ), animate );
+                       center( $( "img:eq(1)" ), animate );
+                       right( $( "img:eq(2)" ), animate );
                });
        });
        </script>