jQuery: The Write Less, Do More JavaScript Library

Changeset 5527

Show
Ignore:
Timestamp:
05/09/08 03:15:18 (3 days ago)
Author:
brandon.aaron
Message:

batch plugin: 1.0 :)

Location:
trunk/plugins/batch
Files:
2 modified

Legend:

Unmodified
Added
Removed
  • trunk/plugins/batch/jquery.batch.js

    r4158 r5527  
    1 /* Copyright (c) 2007 Brandon Aaron (http://brandonaaron.net) 
     1/*! Copyright (c) 2007 Brandon Aaron (http://brandonaaron.net) 
    22 * Dual licensed under the MIT (http://www.opensource.org/licenses/mit-license.php)  
    33 * and GPL (http://www.opensource.org/licenses/gpl-license.php) licenses. 
     
    66 * $Rev$ 
    77 * 
    8  * Version: @VERSION 
     8 * Version: 1.0 
    99 */ 
    1010(function($){ 
     
    1818}; 
    1919 
    20 $.each( "attr css offset width height html text val".split(" "), function(index, method) { 
    21     $.fn[method+"s"] = function() { 
    22         return this.batch.apply( this, [method].concat( $.makeArray(arguments) ) ); 
    23     }; 
    24 }); 
     20$.batch = { 
     21    version: "1.0", 
     22    registerPlugin: function() { 
     23        $.each( arguments, function( index, plugin ) { 
     24            var method = plugin.constructor == Array && plugin[0] || plugin, 
     25                newMethod = plugin.constructor == Array && plugin[1] || plugin+"s"; 
     26            if ( $.fn[ method ] && !$.fn[ newMethod ] ) 
     27                $.fn[ newMethod ] = function() { 
     28                    return this.batch.apply( this, [ method ].concat( $.makeArray(arguments) ) ); 
     29                }; 
     30        }); 
     31    } 
     32}; 
     33 
     34$.batch.registerPlugin( 'attr', ['css','styles'], 'offset', 'width', 'height', 'html', 'text', 'val' ); 
    2535 
    2636})(jQuery); 
  • trunk/plugins/batch/test/unit/batch.js

    r4158 r5527  
    22 
    33test("batch", function() { 
     4    $.each( ['attr', 'styles', 'offset', 'width', 'height', 'html', 'text', 'val'], function(index, name) { 
     5        ok( $.fn[name], "Make sure " + name + " exists" ); 
     6    }); 
     7}); 
     8test("attrs", function() { 
    49    isSet( $('input[value=Test]').attrs('value'), ["Test", "Test"], "$('input[value=Test]').attrs('value')" ); 
    510    isSet( $('input[value=Test]').attrs('value', function(){ return 'Updated'; }).attrs('value'), ["Updated", "Updated"], "$('input[value=Test]').attrs('value', function(){ return 'Updated'; })" );