Check 'em All - Checkbox button

No replies
nicholas
nicholas's picture
Joined: 02/01/2009
User offline. Last seen 4 hours 35 min ago.

Basics

Description & Info:
Checks and Unchecks checkboxes that are highlighted on a page

Highlight a section of a page that contains checkboxes
with your cursor then click the button.

All of the checkboxes in the highlighted area will
be toggled between a checked or unchecked state.

Behavior

Left: Toggle State of all Highlighted checkboxes

Middle: Check all highlighted checkboxes

Right: Uncheck all highlighted checkboxes

Change Log

Code

/*Code*/

Initialization

/*Initialization code*/
if (typeof custombuttons.uCbuttonButes != 'function') {
  alert( "This Button requires the Custom Buttons Extension" );
  this.disabled(true);
}
 
var boxArray = new Array();
 
function getSelectedSource() {
  var focusedWindow = document.commandDispatcher.focusedWindow;
  var winWrapper = new XPCNativeWrapper(focusedWindow, "document", "getSelection()");
  var x = content.document.createElement("div");
  x.appendChild(winWrapper.getSelection().getRangeAt(0).cloneContents());
  return x;
}
 
function getBoxes() {
  var sel = getSelectedSource();
  var box = sel.getElementsByTagName('input');
  for (i=0;i<box.length;i++) {
    var boxtype = box[i].getAttribute("type");
    if (boxtype.match("checkbox")) {
      boxName = box[i].getAttribute("name");
      boxArray.push(boxName);
    }
  }
  return;
}
 
function checkBoxes() {
  getBoxes();
  for (j=0;j<boxArray.length;j++) {
    var getBox = content.document.getElementsByName(boxArray[j]);
    for (k=0;k<getBox.length;k++) {
      getBox[k].setAttribute("checked", "checked");
    }
  }
}
 
function uncheckBoxes() {
  getBoxes();
  for (j=0;j<boxArray.length;j++) {
    var getBox = content.document.getElementsByName(boxArray[j]);
    for (k=0;k<getBox.length;k++) {
      getBox[k].removeAttribute("checked");
    }
  }
}
 
function toggleBoxes() {
  getBoxes();
  for (j=0;j<boxArray.length;j++) {
    var getBox = content.document.getElementsByName(boxArray[j]);
    for (k=0;k<getBox.length;k++) {
      if (getBox[k].getAttribute("checked") == "checked") {
        getBox[k].removeAttribute("checked");
      }
      else {
        getBox[k].setAttribute("checked", "checked");
      }
    }
  }
}
 
this.leftclick = function(evt) {
  toggleBoxes();
}
this.midclick = function(evt) {
  checkBoxes();
}
this.rightclick = function(evt) {
  uncheckBoxes();
}
 
this.tooltipText = this.label + "\n" +
                   "L: Toggle states of all highlighted checkboxes\n" +
                   "M: Check all highlighted checkboxes\n" +
                   "R: Uncheck all highlighted checkboxes";
 
this.setAttribute( 'onclick', 'custombuttons.gQuot.mHandler( event, this )' );
this.style.opacity = '.65';
this.setAttribute("onmouseover", "if (custombuttons) custombuttons.ButtonBrt(event);" );
this.setAttribute("onmouseout", "if (custombuttons) custombuttons.ButtonDim(event);" );
 
this.setAttribute('author','nicholas');
this.setAttribute('version','2008.10.24.00');
this.setAttribute('homepage','http://custombuttons2.com/forum/index.php');
this.setAttribute('dependency','FF3.0*, FL1.0*, TB2.0*, CB2 2.0.5*');
this.setAttribute('status','Beta');
this.setAttribute('public',true);

Help

Highlight%20a%20section%20of%20a%20page%20that%20contains%20checkboxes%0Awith%20your%20cursor%20then%20click%20the%20button.%0A%0AAll%20of%20the%20checkboxes%20in%20the%20highlighted%20area%20will%0Abe%20toggled%20between%20a%20checked%20or%20unchecked%20state.