Skip to content
Browse files

pushed project to github

  • Loading branch information...
1 parent e5c077a commit fae66be90045f5980e015da637b77b33337e1673 @mletynski committed Apr 13, 2012
View
3 .gitignore
@@ -0,0 +1,3 @@
+.DS_Store
+Thumbs.db
+
View
BIN images/checked.gif
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
BIN images/checked_highlighted.gif
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
BIN images/intermediate.gif
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
BIN images/intermediate_highlighted.gif
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
BIN images/unchecked.gif
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
BIN images/unchecked_highlighted.gif
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
7 js/tristate-0.9.1-min.js
@@ -0,0 +1,7 @@
+/*
+ --- Tristate Checkbox ---
+v 0.9.1 18th Dec 2008
+By Shams Mahmood
+http://shamsmi.blogspot.com
+*/
+var STATE_NONE=0;var STATE_SOME=1;var STATE_ALL=2;var UNCHECKED_NORM="UNCHECKED_NORM";var UNCHECKED_HILI="UNCHECKED_HILI";var INTERMEDIATE_NORM="INTERMEDIATE_NORM";var INTERMEDIATE_HILI="INTERMEDIATE_HILI";var CHECKED_NORM="CHECKED_NORM";var CHECKED_HILI="CHECKED_HILI";var DEFAULT_CONFIG={UNCHECKED_NORM:"http://lh6.ggpht.com/_c_AszxFWLLs/SUrdffHaeiI/AAAAAAAACkw/uXPxlSq7ZME/s144/unchecked.gif",UNCHECKED_HILI:"http://lh4.ggpht.com/_c_AszxFWLLs/SUrdfZ1ojEI/AAAAAAAACk4/5YVi4rip30A/s144/unchecked_highlighted.gif",INTERMEDIATE_NORM:"http://lh5.ggpht.com/_c_AszxFWLLs/SUrdbwoLc0I/AAAAAAAACkg/SvmbPidI2-o/s144/intermediate.gif",INTERMEDIATE_HILI:"http://lh5.ggpht.com/_c_AszxFWLLs/SUrdbwtXDOI/AAAAAAAACko/82v692p5tno/s144/intermediate_highlighted.gif",CHECKED_NORM:"http://lh3.ggpht.com/_c_AszxFWLLs/SUrdbiLuQCI/AAAAAAAACkQ/faUYorb0WT8/s144/checked.gif",CHECKED_HILI:"http://lh4.ggpht.com/_c_AszxFWLLs/SUrdb6se_WI/AAAAAAAACkY/Khw5XhX0T5Y/s144/checked_highlighted.gif"};function getNextStateFromValue(A){if(A==STATE_SOME){return STATE_ALL}if(A==STATE_ALL){return STATE_NONE}return STATE_SOME}function getStateFromValue(B,A){if(B==STATE_SOME){return(!A)?INTERMEDIATE_NORM:INTERMEDIATE_HILI}if(B==STATE_ALL){return(!A)?CHECKED_NORM:CHECKED_HILI}return(!A)?UNCHECKED_NORM:UNCHECKED_HILI}function getFieldAndContainerIds(C){var D=C.substring(0,C.length-".Img".length);var B=document.getElementById(D+".Field").value;var A=document.getElementById(D+".Container").value;return[B,A]}function getAllCheckboxesInContainer(C){var B=document.getElementById(C);var G=B.getElementsByTagName("input");var F=new Array();var E=0;for(var A=0;A<G.length;A++){var D=G[A];if(D.type=="checkbox"){F[E++]=D}}return F}function selectOrUnselectBoxes(C,B){for(var A in C){C[A].checked=B}}function areAllBoxesInGivenCheckedState(C,D){var B=true;for(var A=0;A<C.length;A++){if(C[A].checked!=D){B=false;break}}return B}function replaceImage(A,C){var B=document.getElementById(A);if(B.src!=C){B.src=C}}function mouseOverOutOfImageFunction(C,A){var E=getFieldAndContainerIds(C);var B=document.getElementById(E[0]);var D=getStateFromValue(B.value,A);return DEFAULT_CONFIG[D]}function onMouseOverImageFnc(A){return function(){var B=mouseOverOutOfImageFunction(A,true);replaceImage(A,B)}}function onMouseOutImageFnc(A){return function(){var B=mouseOverOutOfImageFunction(A,false);replaceImage(A,B)}}function onTristateImageClickFnc(A){return function(){var E=getFieldAndContainerIds(A);var D=document.getElementById(E[0]);var C=getNextStateFromValue(D.value);if(C==STATE_SOME){C=getNextStateFromValue(C)}D.value=C;var B=getAllCheckboxesInContainer(E[1]);selectOrUnselectBoxes(B,C==STATE_ALL);var F=mouseOverOutOfImageFunction(A,true);replaceImage(A,F)}}function onCheckboxClickFnc(A,B){return function(){var E=getFieldAndContainerIds(A);var C=getAllCheckboxesInContainer(E[1]);var D=document.getElementById(E[0]);updateStateAndImage(C,D,A)}}function updateStateAndImage(B,D,C){var A=areAllBoxesInGivenCheckedState(B,true);var E=areAllBoxesInGivenCheckedState(B,false);if(A){D.value=STATE_ALL}else{if(E){D.value=STATE_NONE}else{D.value=STATE_SOME}}var F=mouseOverOutOfImageFunction(C,false);replaceImage(C,F)}function initTriStateCheckBox(A,D){var E=document.getElementById(A);var B=A+"Value";var H=E.childNodes[0];E.removeChild(H);var I=document.createElement("input");I.id=B;I.type="hidden";I.value=STATE_NONE;E.appendChild(I);var L=new Image();L.id=A+".Img";L.src=DEFAULT_CONFIG[UNCHECKED_NORM];E.appendChild(L);if(E.addEventListener){E.addEventListener("mouseover",onMouseOverImageFnc(L.id),false);E.addEventListener("mouseout",onMouseOutImageFnc(L.id),false);E.addEventListener("click",onTristateImageClickFnc(L.id),false)}else{if(E.attachEvent){E.attachEvent("onmouseover",onMouseOverImageFnc(L.id));E.attachEvent("onmouseout",onMouseOutImageFnc(L.id));E.attachEvent("onclick",onTristateImageClickFnc(L.id))}}var C=document.createElement("input");C.id=A+".Field";C.type="hidden";C.value=B;E.appendChild(C);var F=document.createElement("input");F.id=A+".Container";F.type="hidden";F.value=D;E.appendChild(F);E.appendChild(H);var G=getAllCheckboxesInContainer(D);for(var J in G){var K=G[J];if(K.addEventListener){K.addEventListener("click",onCheckboxClickFnc(L.id,K.id),false)}else{if(K.attachEvent){K.attachEvent("onclick",onCheckboxClickFnc(L.id,K.id))}}}updateStateAndImage(G,I,L.id)};
View
200 js/tristate-0.9.1.js
@@ -0,0 +1,200 @@
+/*
+ --- Tristate Checkbox ---
+v 0.9.1 18th Dec 2008
+By Shams Mahmood
+http://shamsmi.blogspot.com
+*/
+
+var STATE_NONE = 0;
+var STATE_SOME = 1;
+var STATE_ALL = 2;
+
+var UNCHECKED_NORM = 'UNCHECKED_NORM';
+var UNCHECKED_HILI = 'UNCHECKED_HILI';
+var INTERMEDIATE_NORM = 'INTERMEDIATE_NORM';
+var INTERMEDIATE_HILI = 'INTERMEDIATE_HILI';
+var CHECKED_NORM = 'CHECKED_NORM';
+var CHECKED_HILI = 'CHECKED_HILI';
+
+var DEFAULT_CONFIG = {
+ UNCHECKED_NORM : 'http://lh6.ggpht.com/_c_AszxFWLLs/SUrdffHaeiI/AAAAAAAACkw/uXPxlSq7ZME/s144/unchecked.gif',
+ UNCHECKED_HILI : 'http://lh4.ggpht.com/_c_AszxFWLLs/SUrdfZ1ojEI/AAAAAAAACk4/5YVi4rip30A/s144/unchecked_highlighted.gif',
+ INTERMEDIATE_NORM : 'http://lh5.ggpht.com/_c_AszxFWLLs/SUrdbwoLc0I/AAAAAAAACkg/SvmbPidI2-o/s144/intermediate.gif',
+ INTERMEDIATE_HILI : 'http://lh5.ggpht.com/_c_AszxFWLLs/SUrdbwtXDOI/AAAAAAAACko/82v692p5tno/s144/intermediate_highlighted.gif',
+ CHECKED_NORM : 'http://lh3.ggpht.com/_c_AszxFWLLs/SUrdbiLuQCI/AAAAAAAACkQ/faUYorb0WT8/s144/checked.gif',
+ CHECKED_HILI : 'http://lh4.ggpht.com/_c_AszxFWLLs/SUrdb6se_WI/AAAAAAAACkY/Khw5XhX0T5Y/s144/checked_highlighted.gif'
+};
+
+function getNextStateFromValue(theValue) {
+ if (theValue == STATE_SOME) { return STATE_ALL; }
+ if (theValue == STATE_ALL) { return STATE_NONE; }
+ return STATE_SOME;
+}
+function getStateFromValue(theValue, highlightedState) {
+ if (theValue == STATE_SOME) { return (!highlightedState) ? INTERMEDIATE_NORM : INTERMEDIATE_HILI; }
+ if (theValue == STATE_ALL) { return (!highlightedState) ? CHECKED_NORM : CHECKED_HILI; }
+ return (!highlightedState) ? UNCHECKED_NORM : UNCHECKED_HILI;
+}
+
+function getFieldAndContainerIds(imageId) {
+ var triStateBoxId = imageId.substring(0, imageId.length - '.Img'.length);
+ var triStateBoxFieldId = document.getElementById(triStateBoxId + '.Field').value;
+ var triStateBoxContainerNodeId = document.getElementById(triStateBoxId + '.Container').value;
+ return [triStateBoxFieldId, triStateBoxContainerNodeId];
+}
+
+function getAllCheckboxesInContainer(triStateBoxContainerNodeId) {
+ var triStateBoxContainerNode = document.getElementById(triStateBoxContainerNodeId);
+ var inputElements = triStateBoxContainerNode.getElementsByTagName('input');
+ var checkboxes = new Array();
+ var index = 0;
+
+ for (var x = 0; x < inputElements.length; x++) {
+ var loopElement = inputElements[x];
+ if (loopElement.type == 'checkbox') {
+ checkboxes[index++] = loopElement;
+ }
+ }
+
+ return checkboxes;
+}
+function selectOrUnselectBoxes(checkBoxes, selectBoxes) {
+ for (var x in checkBoxes) {
+ checkBoxes[x].checked = selectBoxes;
+ }
+}
+function areAllBoxesInGivenCheckedState(checkBoxes, boxesSelected) {
+ var result = true;
+ for (var x = 0; x < checkBoxes.length; x++) {
+ if (checkBoxes[x].checked != boxesSelected) {
+ result = false;
+ break;
+ }
+ }
+ return result;
+}
+
+function replaceImage(imageId, imageSrc) {
+ var image = document.getElementById(imageId);
+ if (image.src != imageSrc) {
+ image.src = imageSrc;
+ }
+}
+function mouseOverOutOfImageFunction(imageId, mouseOverMode) {
+
+ var fieldAndContainerIds = getFieldAndContainerIds(imageId);
+ var triStateBoxField = document.getElementById(fieldAndContainerIds[0]);
+
+ var currentState = getStateFromValue(triStateBoxField.value, mouseOverMode);
+ return DEFAULT_CONFIG[currentState];
+}
+function onMouseOverImageFnc(imageId) {
+ return function() {
+ var imageSrc = mouseOverOutOfImageFunction(imageId, true);
+ replaceImage(imageId, imageSrc)
+ };
+}
+function onMouseOutImageFnc(imageId) {
+ return function() {
+ var imageSrc = mouseOverOutOfImageFunction(imageId, false);
+ replaceImage(imageId, imageSrc)
+ };
+}
+function onTristateImageClickFnc(imageId) {
+ return function() {
+ var fieldAndContainerIds = getFieldAndContainerIds(imageId);
+ var triStateBoxField = document.getElementById(fieldAndContainerIds[0]);
+
+ var nextState = getNextStateFromValue(triStateBoxField.value);
+ if (nextState == STATE_SOME) {
+ nextState = getNextStateFromValue(nextState);
+ }
+ triStateBoxField.value = nextState;
+
+ var allTheCheckboxes = getAllCheckboxesInContainer(fieldAndContainerIds[1]);
+ selectOrUnselectBoxes(allTheCheckboxes, nextState == STATE_ALL);
+
+ var imageSrc = mouseOverOutOfImageFunction(imageId, true);
+ replaceImage(imageId, imageSrc)
+ }
+}
+function onCheckboxClickFnc(imageId, checkBoxId) {
+ return function() {
+ var fieldAndContainerIds = getFieldAndContainerIds(imageId);
+ var allTheCheckboxes = getAllCheckboxesInContainer(fieldAndContainerIds[1]);
+
+ var triStateBoxField = document.getElementById(fieldAndContainerIds[0]);
+ updateStateAndImage(allTheCheckboxes, triStateBoxField, imageId)
+ }
+}
+
+function updateStateAndImage(allTheCheckboxes, triStateBoxField, imageId) {
+ var allBoxesSelected = areAllBoxesInGivenCheckedState(allTheCheckboxes, true);
+ var allBoxesUnselected = areAllBoxesInGivenCheckedState(allTheCheckboxes, false);
+
+ if (allBoxesSelected) {
+ triStateBoxField.value = STATE_ALL;
+ } else if (allBoxesUnselected) {
+ triStateBoxField.value = STATE_NONE;
+ } else {
+ triStateBoxField.value = STATE_SOME;
+ }
+ var imageSrc = mouseOverOutOfImageFunction(imageId, false);
+ replaceImage(imageId, imageSrc);
+}
+
+function initTriStateCheckBox(triStateBoxId, triStateBoxContainerId) {
+
+ var triStateBoxNode = document.getElementById(triStateBoxId);
+
+ var triStateBoxFieldId = triStateBoxId + 'Value';
+
+ var triStateBoxTextNode = triStateBoxNode.childNodes[0];
+ triStateBoxNode.removeChild(triStateBoxTextNode);
+
+ var triStateBoxField = document.createElement("input");
+ triStateBoxField.id = triStateBoxFieldId;
+ triStateBoxField.type = 'hidden';
+ triStateBoxField.value = STATE_NONE;
+ triStateBoxNode.appendChild(triStateBoxField);
+
+ var imageNode = new Image();
+ imageNode.id = triStateBoxId + '.Img';
+ imageNode.src = DEFAULT_CONFIG[UNCHECKED_NORM];
+ triStateBoxNode.appendChild(imageNode);
+ if (triStateBoxNode.addEventListener) {
+ triStateBoxNode.addEventListener('mouseover', onMouseOverImageFnc(imageNode.id), false);
+ triStateBoxNode.addEventListener('mouseout', onMouseOutImageFnc(imageNode.id), false);
+ triStateBoxNode.addEventListener('click', onTristateImageClickFnc(imageNode.id), false);
+ } else if (triStateBoxNode.attachEvent) {
+ triStateBoxNode.attachEvent('onmouseover', onMouseOverImageFnc(imageNode.id));
+ triStateBoxNode.attachEvent('onmouseout', onMouseOutImageFnc(imageNode.id));
+ triStateBoxNode.attachEvent('onclick', onTristateImageClickFnc(imageNode.id));
+ }
+
+ var fieldNode = document.createElement("input");
+ fieldNode.id = triStateBoxId + '.Field';
+ fieldNode.type = 'hidden';
+ fieldNode.value = triStateBoxFieldId;
+ triStateBoxNode.appendChild(fieldNode);
+
+ var containerNode = document.createElement("input");
+ containerNode.id = triStateBoxId + '.Container';
+ containerNode.type = 'hidden';
+ containerNode.value = triStateBoxContainerId;
+ triStateBoxNode.appendChild(containerNode);
+
+ triStateBoxNode.appendChild(triStateBoxTextNode);
+
+ var allTheCheckboxes = getAllCheckboxesInContainer(triStateBoxContainerId);
+ for (var x in allTheCheckboxes) {
+ var loopCheckBox = allTheCheckboxes[x];
+ if (loopCheckBox.addEventListener) {
+ loopCheckBox.addEventListener('click', onCheckboxClickFnc(imageNode.id, loopCheckBox.id), false);
+ } else if (loopCheckBox.attachEvent) {
+ loopCheckBox.attachEvent('onclick', onCheckboxClickFnc(imageNode.id, loopCheckBox.id));
+ }
+ }
+
+ updateStateAndImage(allTheCheckboxes, triStateBoxField, imageNode.id);
+}
View
7 js/tristate-0.9.2-min.js
@@ -0,0 +1,7 @@
+/*
+ --- Tristate Checkbox ---
+v 0.9.2 19th Dec 2008
+By Shams Mahmood
+http://shamsmi.blogspot.com
+*/
+var STATE_NONE=0;var STATE_SOME=1;var STATE_ALL=2;var UNCHECKED_NORM="UNCHECKED_NORM";var UNCHECKED_HILI="UNCHECKED_HILI";var INTERMEDIATE_NORM="INTERMEDIATE_NORM";var INTERMEDIATE_HILI="INTERMEDIATE_HILI";var CHECKED_NORM="CHECKED_NORM";var CHECKED_HILI="CHECKED_HILI";var DEFAULT_CONFIG={UNCHECKED_NORM:"http://lh6.ggpht.com/_c_AszxFWLLs/SUrdffHaeiI/AAAAAAAACkw/uXPxlSq7ZME/s144/unchecked.gif",UNCHECKED_HILI:"http://lh4.ggpht.com/_c_AszxFWLLs/SUrdfZ1ojEI/AAAAAAAACk4/5YVi4rip30A/s144/unchecked_highlighted.gif",INTERMEDIATE_NORM:"http://lh5.ggpht.com/_c_AszxFWLLs/SUrdbwoLc0I/AAAAAAAACkg/SvmbPidI2-o/s144/intermediate.gif",INTERMEDIATE_HILI:"http://lh5.ggpht.com/_c_AszxFWLLs/SUrdbwtXDOI/AAAAAAAACko/82v692p5tno/s144/intermediate_highlighted.gif",CHECKED_NORM:"http://lh3.ggpht.com/_c_AszxFWLLs/SUrdbiLuQCI/AAAAAAAACkQ/faUYorb0WT8/s144/checked.gif",CHECKED_HILI:"http://lh4.ggpht.com/_c_AszxFWLLs/SUrdb6se_WI/AAAAAAAACkY/Khw5XhX0T5Y/s144/checked_highlighted.gif"};function getNextStateFromValue(A){if(A==STATE_SOME){return STATE_ALL}if(A==STATE_ALL){return STATE_NONE}return STATE_SOME}function getStateFromValue(B,A){if(B==STATE_SOME){return(!A)?INTERMEDIATE_NORM:INTERMEDIATE_HILI}if(B==STATE_ALL){return(!A)?CHECKED_NORM:CHECKED_HILI}return(!A)?UNCHECKED_NORM:UNCHECKED_HILI}function getFieldAndContainerIds(D){var E=D.substring(0,D.length-".Img".length);var C=document.getElementById(E+".Field").value;var A=document.getElementById(E+".Container");var B="";if(A){B=A.value}return[C,B]}function getAllCheckboxesInContainer(C){if(C==""){return[]}var B=document.getElementById(C);var G=B.getElementsByTagName("input");var F=new Array();var E=0;for(var A=0;A<G.length;A++){var D=G[A];if(D.type=="checkbox"){F[E++]=D}}return F}function selectOrUnselectBoxes(C,B){for(var A in C){C[A].checked=B}}function areAllBoxesInGivenCheckedState(C,D){var B=true;for(var A=0;A<C.length;A++){if(C[A].checked!=D){B=false;break}}return B}function replaceImage(A,C){var B=document.getElementById(A);if(B.src!=C){B.src=C}}function mouseOverOutOfImage(C,A){var E=getFieldAndContainerIds(C);var B=document.getElementById(E[0]);var D=getStateFromValue(B.value,A);return DEFAULT_CONFIG[D]}function onMouseOverImage(A){return function(){var B=mouseOverOutOfImage(A,true);replaceImage(A,B)}}function onMouseOutImage(A){return function(){var B=mouseOverOutOfImage(A,false);replaceImage(A,B)}}function onTristateImageClick(A,B){return function(){var F=getFieldAndContainerIds(A);var E=document.getElementById(F[0]);var D=getNextStateFromValue(E.value);if(!B&&D==STATE_SOME){D=getNextStateFromValue(D)}E.value=D;if(F[1]!=""){var C=getAllCheckboxesInContainer(F[1]);selectOrUnselectBoxes(C,D==STATE_ALL)}var G=mouseOverOutOfImage(A,true);replaceImage(A,G)}}function onCheckboxClick(A,B){return function(){var E=getFieldAndContainerIds(A);var C=getAllCheckboxesInContainer(E[1]);var D=document.getElementById(E[0]);updateStateAndImage(C,D,A)}}function updateStateAndImage(B,D,C){if(B.length>0){var A=areAllBoxesInGivenCheckedState(B,true);var E=areAllBoxesInGivenCheckedState(B,false);if(A){D.value=STATE_ALL}else{if(E){D.value=STATE_NONE}else{D.value=STATE_SOME}}}var F=mouseOverOutOfImage(C,false);replaceImage(C,F)}function createHiddenStateField(C,A){var B=document.createElement("input");B.id=A;B.type="hidden";B.value=STATE_NONE;C.appendChild(B);return B}function createTriStateImageNode(D,C,A){var B=new Image();B.id=C;B.src=DEFAULT_CONFIG[UNCHECKED_NORM];D.appendChild(B);if(D.addEventListener){D.addEventListener("mouseover",onMouseOverImage(B.id),false);D.addEventListener("mouseout",onMouseOutImage(B.id),false);D.addEventListener("click",onTristateImageClick(B.id,A),false)}else{if(D.attachEvent){D.attachEvent("onmouseover",onMouseOverImage(B.id));D.attachEvent("onmouseout",onMouseOutImage(B.id));D.attachEvent("onclick",onTristateImageClick(B.id,A))}}}function createFieldNameHiddenField(D,C,B){var A=document.createElement("input");A.id=C;A.type="hidden";A.value=B;D.appendChild(A)}function createContainerNameHiddenField(D,B,C){var A=document.createElement("input");A.id=B;A.type="hidden";A.value=C;D.appendChild(A)}function attachOnclickEventsToDependentBoxes(E,D){var B=getAllCheckboxesInContainer(E);for(var A in B){var C=B[A];if(C.addEventListener){C.addEventListener("click",onCheckboxClick(D,C.id),false)}else{if(C.attachEvent){C.attachEvent("onclick",onCheckboxClick(D,C.id))}}}return B}function initTriStateCheckBox(A,G,F){var D=document.getElementById(A);var C=G;var B=A+".Value";if(F){C="";B=G}var I=D.childNodes[0];D.removeChild(I);var J=document.getElementById(B);if(!F){J=createHiddenStateField(D,B)}var K=A+".Img";createTriStateImageNode(D,K,F);var L=A+".Field";createFieldNameHiddenField(D,L,B);if(!F){var H=A+".Container";createContainerNameHiddenField(D,H,C)}D.appendChild(I);var E=attachOnclickEventsToDependentBoxes(C,K);updateStateAndImage(E,J,K)};
View
239 js/tristate-0.9.2.js
@@ -0,0 +1,239 @@
+/*
+ --- Tristate Checkbox ---
+v 0.9.2 19th Dec 2008
+By Shams Mahmood
+http://shamsmi.blogspot.com
+*/
+
+var STATE_NONE = 0;
+var STATE_SOME = 1;
+var STATE_ALL = 2;
+
+var UNCHECKED_NORM = 'UNCHECKED_NORM';
+var UNCHECKED_HILI = 'UNCHECKED_HILI';
+var INTERMEDIATE_NORM = 'INTERMEDIATE_NORM';
+var INTERMEDIATE_HILI = 'INTERMEDIATE_HILI';
+var CHECKED_NORM = 'CHECKED_NORM';
+var CHECKED_HILI = 'CHECKED_HILI';
+
+var DEFAULT_CONFIG = {
+ UNCHECKED_NORM : 'http://lh6.ggpht.com/_c_AszxFWLLs/SUrdffHaeiI/AAAAAAAACkw/uXPxlSq7ZME/s144/unchecked.gif',
+ UNCHECKED_HILI : 'http://lh4.ggpht.com/_c_AszxFWLLs/SUrdfZ1ojEI/AAAAAAAACk4/5YVi4rip30A/s144/unchecked_highlighted.gif',
+ INTERMEDIATE_NORM : 'http://lh5.ggpht.com/_c_AszxFWLLs/SUrdbwoLc0I/AAAAAAAACkg/SvmbPidI2-o/s144/intermediate.gif',
+ INTERMEDIATE_HILI : 'http://lh5.ggpht.com/_c_AszxFWLLs/SUrdbwtXDOI/AAAAAAAACko/82v692p5tno/s144/intermediate_highlighted.gif',
+ CHECKED_NORM : 'http://lh3.ggpht.com/_c_AszxFWLLs/SUrdbiLuQCI/AAAAAAAACkQ/faUYorb0WT8/s144/checked.gif',
+ CHECKED_HILI : 'http://lh4.ggpht.com/_c_AszxFWLLs/SUrdb6se_WI/AAAAAAAACkY/Khw5XhX0T5Y/s144/checked_highlighted.gif'
+};
+
+function getNextStateFromValue(theValue) {
+ if (theValue == STATE_SOME) { return STATE_ALL; }
+ if (theValue == STATE_ALL) { return STATE_NONE; }
+ return STATE_SOME;
+}
+function getStateFromValue(theValue, highlightedState) {
+ if (theValue == STATE_SOME) { return (!highlightedState) ? INTERMEDIATE_NORM : INTERMEDIATE_HILI; }
+ if (theValue == STATE_ALL) { return (!highlightedState) ? CHECKED_NORM : CHECKED_HILI; }
+ return (!highlightedState) ? UNCHECKED_NORM : UNCHECKED_HILI;
+}
+
+function getFieldAndContainerIds(imageId) {
+ var triStateBoxId = imageId.substring(0, imageId.length - '.Img'.length);
+ var triStateBoxFieldId = document.getElementById(triStateBoxId + '.Field').value;
+ var triStateBoxContainerNode = document.getElementById(triStateBoxId + '.Container');
+ var triStateBoxContainerNodeId = '';
+ if (triStateBoxContainerNode) {
+ triStateBoxContainerNodeId = triStateBoxContainerNode.value;
+ }
+ return [triStateBoxFieldId, triStateBoxContainerNodeId];
+}
+
+function getAllCheckboxesInContainer(triStateBoxContainerNodeId) {
+ if (triStateBoxContainerNodeId == '') {
+ return [];
+ }
+ var triStateBoxContainerNode = document.getElementById(triStateBoxContainerNodeId);
+ var inputElements = triStateBoxContainerNode.getElementsByTagName('input');
+ var checkboxes = new Array();
+ var index = 0;
+
+ for (var x = 0; x < inputElements.length; x++) {
+ var loopElement = inputElements[x];
+ if (loopElement.type == 'checkbox') {
+ checkboxes[index++] = loopElement;
+ }
+ }
+
+ return checkboxes;
+}
+function selectOrUnselectBoxes(checkBoxes, selectBoxes) {
+ for (var x in checkBoxes) {
+ checkBoxes[x].checked = selectBoxes;
+ }
+}
+function areAllBoxesInGivenCheckedState(checkBoxes, boxesSelected) {
+ var result = true;
+ for (var x = 0; x < checkBoxes.length; x++) {
+ if (checkBoxes[x].checked != boxesSelected) {
+ result = false;
+ break;
+ }
+ }
+ return result;
+}
+
+function replaceImage(imageId, imageSrc) {
+ var image = document.getElementById(imageId);
+ if (image.src != imageSrc) {
+ image.src = imageSrc;
+ }
+}
+function mouseOverOutOfImage(imageId, mouseOverMode) {
+
+ var fieldAndContainerIds = getFieldAndContainerIds(imageId);
+ var triStateBoxField = document.getElementById(fieldAndContainerIds[0]);
+
+ var currentState = getStateFromValue(triStateBoxField.value, mouseOverMode);
+ return DEFAULT_CONFIG[currentState];
+}
+function onMouseOverImage(imageId) {
+ return function() {
+ var imageSrc = mouseOverOutOfImage(imageId, true);
+ replaceImage(imageId, imageSrc)
+ };
+}
+function onMouseOutImage(imageId) {
+ return function() {
+ var imageSrc = mouseOverOutOfImage(imageId, false);
+ replaceImage(imageId, imageSrc)
+ };
+}
+function onTristateImageClick(imageId, standAloneMode) {
+ return function() {
+ var fieldAndContainerIds = getFieldAndContainerIds(imageId);
+ var triStateBoxField = document.getElementById(fieldAndContainerIds[0]);
+
+ var nextState = getNextStateFromValue(triStateBoxField.value);
+ if (!standAloneMode && nextState == STATE_SOME) {
+ nextState = getNextStateFromValue(nextState);
+ }
+ triStateBoxField.value = nextState;
+
+ if (fieldAndContainerIds[1] != '') {
+ var allTheCheckboxes = getAllCheckboxesInContainer(fieldAndContainerIds[1]);
+ selectOrUnselectBoxes(allTheCheckboxes, nextState == STATE_ALL);
+ }
+
+ var imageSrc = mouseOverOutOfImage(imageId, true);
+ replaceImage(imageId, imageSrc)
+ }
+}
+function onCheckboxClick(imageId, checkBoxId) {
+ return function() {
+ var fieldAndContainerIds = getFieldAndContainerIds(imageId);
+ var allTheCheckboxes = getAllCheckboxesInContainer(fieldAndContainerIds[1]);
+
+ var triStateBoxField = document.getElementById(fieldAndContainerIds[0]);
+ updateStateAndImage(allTheCheckboxes, triStateBoxField, imageId)
+ }
+}
+
+function updateStateAndImage(allTheCheckboxes, triStateBoxField, imageId) {
+ if (allTheCheckboxes.length > 0) {
+ var allBoxesSelected = areAllBoxesInGivenCheckedState(allTheCheckboxes, true);
+ var allBoxesUnselected = areAllBoxesInGivenCheckedState(allTheCheckboxes, false);
+
+ if (allBoxesSelected) {
+ triStateBoxField.value = STATE_ALL;
+ } else if (allBoxesUnselected) {
+ triStateBoxField.value = STATE_NONE;
+ } else {
+ triStateBoxField.value = STATE_SOME;
+ }
+ }
+ var imageSrc = mouseOverOutOfImage(imageId, false);
+ replaceImage(imageId, imageSrc);
+}
+function createHiddenStateField(triStateBoxNode, triStateBoxFieldId) {
+ var triStateBoxField = document.createElement('input');
+ triStateBoxField.id = triStateBoxFieldId;
+ triStateBoxField.type = 'hidden';
+ triStateBoxField.value = STATE_NONE;
+ triStateBoxNode.appendChild(triStateBoxField);
+ return triStateBoxField;
+}
+function createTriStateImageNode(triStateBoxNode, imageNodeId, standAloneMode) {
+ var imageNode = new Image();
+ imageNode.id = imageNodeId;
+ imageNode.src = DEFAULT_CONFIG[UNCHECKED_NORM];
+ triStateBoxNode.appendChild(imageNode);
+ if (triStateBoxNode.addEventListener) {
+ triStateBoxNode.addEventListener('mouseover', onMouseOverImage(imageNode.id), false);
+ triStateBoxNode.addEventListener('mouseout', onMouseOutImage(imageNode.id), false);
+ triStateBoxNode.addEventListener('click', onTristateImageClick(imageNode.id, standAloneMode), false);
+ } else if (triStateBoxNode.attachEvent) {
+ triStateBoxNode.attachEvent('onmouseover', onMouseOverImage(imageNode.id));
+ triStateBoxNode.attachEvent('onmouseout', onMouseOutImage(imageNode.id));
+ triStateBoxNode.attachEvent('onclick', onTristateImageClick(imageNode.id, standAloneMode));
+ }
+}
+function createFieldNameHiddenField(triStateBoxNode, fieldNameNodeId, triStateBoxFieldId) {
+ var fieldNode = document.createElement('input');
+ fieldNode.id = fieldNameNodeId;
+ fieldNode.type = 'hidden';
+ fieldNode.value = triStateBoxFieldId;
+ triStateBoxNode.appendChild(fieldNode);
+}
+function createContainerNameHiddenField(triStateBoxNode, containerNameNodeId, triStateBoxContainerId) {
+ var containerNode = document.createElement('input');
+ containerNode.id = containerNameNodeId;
+ containerNode.type = 'hidden';
+ containerNode.value = triStateBoxContainerId;
+ triStateBoxNode.appendChild(containerNode);
+}
+function attachOnclickEventsToDependentBoxes(triStateBoxContainerId, imageNodeId) {
+ var allTheCheckboxes = getAllCheckboxesInContainer(triStateBoxContainerId);
+ for (var x in allTheCheckboxes) {
+ var loopCheckBox = allTheCheckboxes[x];
+ if (loopCheckBox.addEventListener) {
+ loopCheckBox.addEventListener('click', onCheckboxClick(imageNodeId, loopCheckBox.id), false);
+ } else if (loopCheckBox.attachEvent) {
+ loopCheckBox.attachEvent('onclick', onCheckboxClick(imageNodeId, loopCheckBox.id));
+ }
+ }
+ return allTheCheckboxes;
+}
+function initTriStateCheckBox(triStateBoxId, containerOrStateFieldId, standAloneMode) {
+
+ var triStateBoxNode = document.getElementById(triStateBoxId);
+
+ var triStateBoxContainerId = containerOrStateFieldId;
+ var triStateBoxFieldId = triStateBoxId + '.Value';
+ if (standAloneMode) {
+ triStateBoxContainerId = '';
+ triStateBoxFieldId = containerOrStateFieldId;
+ }
+
+ var triStateBoxTextNode = triStateBoxNode.childNodes[0];
+ triStateBoxNode.removeChild(triStateBoxTextNode);
+
+ var triStateBoxField = document.getElementById(triStateBoxFieldId);
+ if (!standAloneMode) {
+ triStateBoxField = createHiddenStateField(triStateBoxNode, triStateBoxFieldId);
+ }
+
+ var imageNodeId = triStateBoxId + '.Img';
+ createTriStateImageNode(triStateBoxNode, imageNodeId, standAloneMode);
+
+ var fieldNameNodeId = triStateBoxId + '.Field';
+ createFieldNameHiddenField(triStateBoxNode, fieldNameNodeId, triStateBoxFieldId);
+
+ if (!standAloneMode) {
+ var containerNameNodeId = triStateBoxId + '.Container';
+ createContainerNameHiddenField(triStateBoxNode, containerNameNodeId, triStateBoxContainerId);
+ }
+
+ triStateBoxNode.appendChild(triStateBoxTextNode);
+
+ var allTheCheckboxes = attachOnclickEventsToDependentBoxes(triStateBoxContainerId, imageNodeId);
+ updateStateAndImage(allTheCheckboxes, triStateBoxField, imageNodeId);
+}
View
63 tristate-test-inline.html
@@ -0,0 +1,63 @@
+<html>
+ <head>
+ <script type="text/javascript" >
+/*
+ --- Tristate Checkbox ---
+v 0.9.2 19th Dec 2008
+By Shams Mahmood
+http://shamsmi.blogspot.com
+*/
+var STATE_NONE=0;var STATE_SOME=1;var STATE_ALL=2;var UNCHECKED_NORM="UNCHECKED_NORM";var UNCHECKED_HILI="UNCHECKED_HILI";var INTERMEDIATE_NORM="INTERMEDIATE_NORM";var INTERMEDIATE_HILI="INTERMEDIATE_HILI";var CHECKED_NORM="CHECKED_NORM";var CHECKED_HILI="CHECKED_HILI";var DEFAULT_CONFIG={UNCHECKED_NORM:"http://lh6.ggpht.com/_c_AszxFWLLs/SUrdffHaeiI/AAAAAAAACkw/uXPxlSq7ZME/s144/unchecked.gif",UNCHECKED_HILI:"http://lh4.ggpht.com/_c_AszxFWLLs/SUrdfZ1ojEI/AAAAAAAACk4/5YVi4rip30A/s144/unchecked_highlighted.gif",INTERMEDIATE_NORM:"http://lh5.ggpht.com/_c_AszxFWLLs/SUrdbwoLc0I/AAAAAAAACkg/SvmbPidI2-o/s144/intermediate.gif",INTERMEDIATE_HILI:"http://lh5.ggpht.com/_c_AszxFWLLs/SUrdbwtXDOI/AAAAAAAACko/82v692p5tno/s144/intermediate_highlighted.gif",CHECKED_NORM:"http://lh3.ggpht.com/_c_AszxFWLLs/SUrdbiLuQCI/AAAAAAAACkQ/faUYorb0WT8/s144/checked.gif",CHECKED_HILI:"http://lh4.ggpht.com/_c_AszxFWLLs/SUrdb6se_WI/AAAAAAAACkY/Khw5XhX0T5Y/s144/checked_highlighted.gif"};function getNextStateFromValue(A){if(A==STATE_SOME){return STATE_ALL}if(A==STATE_ALL){return STATE_NONE}return STATE_SOME}function getStateFromValue(B,A){if(B==STATE_SOME){return(!A)?INTERMEDIATE_NORM:INTERMEDIATE_HILI}if(B==STATE_ALL){return(!A)?CHECKED_NORM:CHECKED_HILI}return(!A)?UNCHECKED_NORM:UNCHECKED_HILI}function getFieldAndContainerIds(D){var E=D.substring(0,D.length-".Img".length);var C=document.getElementById(E+".Field").value;var A=document.getElementById(E+".Container");var B="";if(A){B=A.value}return[C,B]}function getAllCheckboxesInContainer(C){if(C==""){return[]}var B=document.getElementById(C);var G=B.getElementsByTagName("input");var F=new Array();var E=0;for(var A=0;A<G.length;A++){var D=G[A];if(D.type=="checkbox"){F[E++]=D}}return F}function selectOrUnselectBoxes(C,B){for(var A in C){C[A].checked=B}}function areAllBoxesInGivenCheckedState(C,D){var B=true;for(var A=0;A<C.length;A++){if(C[A].checked!=D){B=false;break}}return B}function replaceImage(A,C){var B=document.getElementById(A);if(B.src!=C){B.src=C}}function mouseOverOutOfImage(C,A){var E=getFieldAndContainerIds(C);var B=document.getElementById(E[0]);var D=getStateFromValue(B.value,A);return DEFAULT_CONFIG[D]}function onMouseOverImage(A){return function(){var B=mouseOverOutOfImage(A,true);replaceImage(A,B)}}function onMouseOutImage(A){return function(){var B=mouseOverOutOfImage(A,false);replaceImage(A,B)}}function onTristateImageClick(A,B){return function(){var F=getFieldAndContainerIds(A);var E=document.getElementById(F[0]);var D=getNextStateFromValue(E.value);if(!B&&D==STATE_SOME){D=getNextStateFromValue(D)}E.value=D;if(F[1]!=""){var C=getAllCheckboxesInContainer(F[1]);selectOrUnselectBoxes(C,D==STATE_ALL)}var G=mouseOverOutOfImage(A,true);replaceImage(A,G)}}function onCheckboxClick(A,B){return function(){var E=getFieldAndContainerIds(A);var C=getAllCheckboxesInContainer(E[1]);var D=document.getElementById(E[0]);updateStateAndImage(C,D,A)}}function updateStateAndImage(B,D,C){if(B.length>0){var A=areAllBoxesInGivenCheckedState(B,true);var E=areAllBoxesInGivenCheckedState(B,false);if(A){D.value=STATE_ALL}else{if(E){D.value=STATE_NONE}else{D.value=STATE_SOME}}}var F=mouseOverOutOfImage(C,false);replaceImage(C,F)}function createHiddenStateField(C,A){var B=document.createElement("input");B.id=A;B.type="hidden";B.value=STATE_NONE;C.appendChild(B);return B}function createTriStateImageNode(D,C,A){var B=new Image();B.id=C;B.src=DEFAULT_CONFIG[UNCHECKED_NORM];D.appendChild(B);if(D.addEventListener){D.addEventListener("mouseover",onMouseOverImage(B.id),false);D.addEventListener("mouseout",onMouseOutImage(B.id),false);D.addEventListener("click",onTristateImageClick(B.id,A),false)}else{if(D.attachEvent){D.attachEvent("onmouseover",onMouseOverImage(B.id));D.attachEvent("onmouseout",onMouseOutImage(B.id));D.attachEvent("onclick",onTristateImageClick(B.id,A))}}}function createFieldNameHiddenField(D,C,B){var A=document.createElement("input");A.id=C;A.type="hidden";A.value=B;D.appendChild(A)}function createContainerNameHiddenField(D,B,C){var A=document.createElement("input");A.id=B;A.type="hidden";A.value=C;D.appendChild(A)}function attachOnclickEventsToDependentBoxes(E,D){var B=getAllCheckboxesInContainer(E);for(var A in B){var C=B[A];if(C.addEventListener){C.addEventListener("click",onCheckboxClick(D,C.id),false)}else{if(C.attachEvent){C.attachEvent("onclick",onCheckboxClick(D,C.id))}}}return B}function initTriStateCheckBox(A,G,F){var D=document.getElementById(A);var C=G;var B=A+".Value";if(F){C="";B=G}var I=D.childNodes[0];D.removeChild(I);var J=document.getElementById(B);if(!F){J=createHiddenStateField(D,B)}var K=A+".Img";createTriStateImageNode(D,K,F);var L=A+".Field";createFieldNameHiddenField(D,L,B);if(!F){var H=A+".Container";createContainerNameHiddenField(D,H,C)}D.appendChild(I);var E=attachOnclickEventsToDependentBoxes(C,K);updateStateAndImage(E,J,K)};
+ </script>
+ </head>
+ <body>
+ <h5>Tri-State Checkbox Demo</h5><br />
+ <form onsubmit="return false; " >
+ <span id="tristateBox" style="cursor: default;">&nbsp; Select/Unselect All</span>
+ <input type="hidden" id="tristateBoxInput" name="tristateBoxInput" value="0" />
+ <br />
+ <div id="tristateBoxContainer" >
+ <label id="label_1" for="cb_1" >
+ <input type="checkbox" id="cb_1" name="cb_1" value="1" />
+ Java
+ </label>
+ <br />
+ <label id="label_2" for="cb_2" >
+ <input type="checkbox" id="cb_2" name="cb_2" value="2" checked="checked" />
+ Html
+ </label>
+ <br />
+ <label id="label_3" for="cb_3" >
+ <input type="checkbox" id="cb_3" name="cb_3" value="3" checked="checked" />
+ Css
+ </label>
+ <br />
+ <label id="label_4" for="cb_4" >
+ <input type="checkbox" id="cb_4" name="cb_4" value="4" checked="checked" />
+ Javascript
+ </label>
+ <br />
+ <label id="label_5" for="cb_5" >
+ <input type="checkbox" id="cb_5" name="cb_5" value="5" />
+ Ruby
+ </label>
+ <br />
+ <label id="label_6" for="cb_6" >
+ <input type="checkbox" id="cb_6" name="cb_6" value="6" />
+ Python
+ </label>
+ <br />
+ </div>
+ <br />
+ <span id="tristateBox2" style="cursor: default;">&nbsp; I liked this
+ <input type="hidden" id="tristateBox2State" name="tristateBox2State" value="1"/>
+ </span>
+ <br />(Maybe/Yes/No)
+ <br />
+ </form>
+ <script type="text/javascript">
+ initTriStateCheckBox('tristateBox', 'tristateBoxContainer', false);
+ initTriStateCheckBox('tristateBox2', 'tristateBox2State', true);
+ </script>
+ </body>
+</html>
View
58 tristate-test.html
@@ -0,0 +1,58 @@
+<html>
+ <head>
+ <script type="text/javascript" src="js/tristate-0.9.2.js" ></script>
+ </head>
+ <body>
+ <h3>Tri-State Checkbox Demo</h3>
+ <br />
+ <form onsubmit="return false; " >
+
+ <span id="tristateBox" style="cursor: default;">&nbsp; Select/Unselect All</span>
+ <input type="hidden" id="tristateBoxInput" name="tristateBoxInput" value="0" />
+ <br />
+
+ <div id="tristateBoxContainer" >
+ <label id="label_1" for="cb_1" >
+ <input type="checkbox" id="cb_1" name="cb_1" value="1" />
+ Java
+ </label>
+ <br />
+ <label id="label_2" for="cb_2" >
+ <input type="checkbox" id="cb_2" name="cb_2" value="2" checked="checked" />
+ Html
+ </label>
+ <br />
+ <label id="label_3" for="cb_3" >
+ <input type="checkbox" id="cb_3" name="cb_3" value="3" checked="checked" />
+ Css
+ </label>
+ <br />
+ <label id="label_4" for="cb_4" >
+ <input type="checkbox" id="cb_4" name="cb_4" value="4" checked="checked" />
+ Javascript
+ </label>
+ <br />
+ <label id="label_5" for="cb_5" >
+ <input type="checkbox" id="cb_5" name="cb_5" value="5" />
+ Ruby
+ </label>
+ <br />
+ <label id="label_6" for="cb_6" >
+ <input type="checkbox" id="cb_6" name="cb_6" value="6" />
+ Python
+ </label>
+ <br />
+ </div>
+ <br />
+ <span id="tristateBox2" style="cursor: default;">&nbsp; I liked this
+ <input type="hidden" id="tristateBox2State" name="tristateBox2State" value="1"/>
+ </span>
+ <br />(Maybe/Yes/No)
+ <br />
+ </form>
+ <script type="text/javascript">
+ initTriStateCheckBox('tristateBox', 'tristateBoxContainer', false);
+ initTriStateCheckBox('tristateBox2', 'tristateBox2State', true);
+ </script>
+ </body>
+</html>

0 comments on commit fae66be

Please sign in to comment.
Something went wrong with that request. Please try again.