User:Persondude2/tasktable.js

$(function {  var NOT_SET = 0;   var CHECKED = 1;   var HIGHLIGHTED = 2;   function rowHighlight(el, val) {      var cssText = '';      if (val == '2') {         cssText = 'background-color: #CCC !important';      } else if (val == '1') {         cssText = 'background-color: #CFC !important';      }      $(el).children('td').css('cssText', cssText);   }   $('table.tasktable[id]').each(function { var table = this; var rows = $(table).find('tr:has(td)'); if (rows.length < 1) return; var numColumns = $(rows[0]).children('td').length; var cookieId = 'tasktable-' + table.id; var settings = getCookie(cookieId).split(''); function persist { setCookie(cookieId, settings.join(''), 60 * 60 * 24 * 7); }     while (settings.length < rows.length) { settings.push(NOT_SET); }     settings = settings.slice(0, rows.length); rows.each(function(i) {        rowHighlight(this, settings[i]);         $(this).mouseover(function { rowHighlight(this, HIGHLIGHTED); }).mouseout(function { rowHighlight(this, settings[i]); }).click(function { settings[i] = 1 - settings[i]; rowHighlight(this, settings[i]); persist; });     });      $(table).append(         $(' ').append( $(' ').attr('colspan', numColumns).append(              $(' ').attr('type', 'button').val('Clear selected rows').click(function { rows.each(function(i) {                    settings[i] = NOT_SET;                     rowHighlight(this, settings[i]);                  }); persist; })           )         )      );   }); });