]> scripts.mit.edu Git - autoinstalls/wordpress.git/blobdiff - wp-admin/js/forms.js
Wordpress 2.6.2
[autoinstalls/wordpress.git] / wp-admin / js / forms.js
index b1d8ce272933695cb4b7129a06c4de96423b5e9f..9e493e5e72be11de1cdaf4e4753b1ba629be50cf 100644 (file)
@@ -1,31 +1,26 @@
-function checkAll(form) {
-       for (i = 0, n = form.elements.length; i < n; i++) {
-               if(form.elements[i].type == "checkbox" && !(form.elements[i].getAttribute('onclick',2))) {
-                       if(form.elements[i].checked == true)
-                               form.elements[i].checked = false;
-                       else
-                               form.elements[i].checked = true;
-               }
-       }
+function checkAll(jQ) { // use attr( checked, fn )
+       jQuery(jQ).find( 'tbody:visible :checkbox' ).attr( 'checked', function() {
+               return jQuery(this).attr( 'checked' ) ? '' : 'checked';
+       } );
 }
 
-function getNumChecked(form) {
-       var num = 0;
-       for (i = 0, n = form.elements.length; i < n; i++) {
-               if (form.elements[i].type == "checkbox") {
-                       if (form.elements[i].checked == true)
-                               num++;
+jQuery( function($) {
+       var lastClicked = false;
+       $( 'tbody :checkbox' ).click( function(e) {
+               if ( 'undefined' == e.shiftKey ) { return true; }
+               if ( e.shiftKey ) {
+                       if ( !lastClicked ) { return true; }
+                       var checks = $( lastClicked ).parents( 'form:first' ).find( ':checkbox' );
+                       var first = checks.index( lastClicked );
+                       var last = checks.index( this );
+                       if ( 0 < first && 0 < last && first != last ) {
+                               checks.slice( first, last ).attr( 'checked', $( this ).is( ':checked' ) ? 'checked' : '' );
+                       }
                }
-       }
-       return num;
-}
-
-function checkAllUsers(role) {
- var checkboxs = document.getElementsByTagName('input');
- for(var i = 0, inp; inp = checkboxs[i]; i++)
-       if(inp.type.toLowerCase() == 'checkbox' && inp.className == role)
-               if(inp.checked == false)
-                       inp.checked = true;
-               else
-                       inp.checked = false;
-}
\ No newline at end of file
+               lastClicked = this;
+               return true;
+       } );
+       $( 'thead :checkbox' ).click( function() {
+               checkAll( $(this).parents( 'form:first' ) );
+       } );
+} );
\ No newline at end of file