Skip to content

Commit

Permalink
gallery-2010.05.26-19-47 jafl gallery-checkboxgroups
Browse files Browse the repository at this point in the history
  • Loading branch information
YUI Builder committed May 26, 2010
1 parent 738a669 commit 0bce192
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 9 deletions.
5 changes: 5 additions & 0 deletions src/gallery-checkboxgroups/js/AtLeastOneCheckboxGroup.js
Expand Up @@ -3,6 +3,11 @@
* the active, adjacent one is turned on. The exact algorithm is explained
* in "Tog on Interface". The checkboxes are assumed to be ordered in the
* order they were added.
*
* @module gallery-checkboxgroups
* @class AtLeastOneCheckboxGroup
* @constructor
* @param cb_list {String|Object|Array} The list of checkboxes to manage
*/

function AtLeastOneCheckboxGroup(
Expand Down
5 changes: 5 additions & 0 deletions src/gallery-checkboxgroups/js/AtMostOneCheckboxGroup.js
@@ -1,6 +1,11 @@
/**********************************************************************
* At most one checkbox can be selected. If one is turned on, the active
* one is turned off.
*
* @module gallery-checkboxgroups
* @class AtMostOneCheckboxGroup
* @constructor
* @param cb_list {String|Object|Array} The list of checkboxes to manage
*/

function AtMostOneCheckboxGroup(
Expand Down
48 changes: 40 additions & 8 deletions src/gallery-checkboxgroups/js/CheckboxGroup.js
@@ -1,15 +1,22 @@
/**********************************************************************
* <p>Base class for enforcing constraints on groups of checkboxes.</p>
*
* <p>Derived classes must override enforceConstraints.</p>
*/
"use strict";

var Direction =
{
SLIDE_UP: 0,
SLIDE_DOWN: 1
};

/**********************************************************************
* <p>Base class for enforcing constraints on groups of checkboxes.</p>
*
* <p>Derived classes must override <code>enforceConstraints()</code>.</p>
*
* @module gallery-checkboxgroups
* @class CheckboxGroup
* @constructor
* @param cb_list {String|Object|Array} The list of checkboxes to manage
*/

function CheckboxGroup(
/* string/object/array */ cb_list)
{
Expand All @@ -35,11 +42,22 @@ function checkboxChanged(

CheckboxGroup.prototype =
{
/**
* @return {Array} List of managed checkboxes
*/
getCheckboxList: function()
{
return this.cb_list;
},

/**
* Same functionality as <code>Array.splice()</code>. Operates on the
* list of managed checkboxes.
*
* @param start {Int} Insertion index
* @param delete_count {Int} Number of items to remove, starting from <code>start</code>
* @param cb_list {String|Object|Array} The list of checkboxes to insert at <code>start</code>
*/
splice: function(
/* int */ start,
/* int */ delete_count,
Expand All @@ -62,8 +80,7 @@ CheckboxGroup.prototype =
cb_list);
}

if (cb_list instanceof Array ||
(cb_list && cb_list.length))
if (cb_list && Y.Lang.isNumber(cb_list.length))
{
for (i=0; i<cb_list.length; i++)
{
Expand Down Expand Up @@ -99,18 +116,27 @@ CheckboxGroup.prototype =
}
},

/**
* Derived classes must override this function to implement the desired behavior.
*
* @param cb_list {String|Object|Array} The list of checkboxes
* @param index {Int} The index of the checkbox that changed
*/
enforceConstraints: function(
/* array */ cb_list,
/* int */ index)
{
},

/**
* @return {boolean} <code>true</code> if all checkboxes are checked
*/
allChecked: function()
{
var count = this.cb_list.length;
for (var i=0; i<count; i++)
{
if (!this.cb_list[i].get('checked'))
if (!this.cb_list[i].get('disabled') && !this.cb_list[i].get('checked'))
{
return false;
}
Expand All @@ -119,6 +145,9 @@ CheckboxGroup.prototype =
return true;
},

/**
* @return {boolean} <code>true</code> if all checkboxes are unchecked
*/
allUnchecked: function()
{
var count = this.cb_list.length;
Expand All @@ -133,6 +162,9 @@ CheckboxGroup.prototype =
return true;
},

/**
* @return {boolean} <code>true</code> if all checkboxes are disabled
*/
allDisabled: function()
{
var count = this.cb_list.length;
Expand Down
11 changes: 10 additions & 1 deletion src/gallery-checkboxgroups/js/SelectAllCheckboxGroup.js
Expand Up @@ -2,6 +2,12 @@
* All checkboxes can be selected and a select-all checkbox is available
* to check all. This check-all box is automatically changed if any other
* checkbox changes state.
*
* @module gallery-checkboxgroups
* @class SelectAllCheckboxGroup
* @constructor
* @param select_all_cb {String|Object} The checkbox that triggers "select all"
* @param cb_list {String|Object|Array} The list of checkboxes to manage
*/

function SelectAllCheckboxGroup(
Expand All @@ -26,7 +32,10 @@ Y.extend(SelectAllCheckboxGroup, CheckboxGroup,
var checked = this.select_all_cb.get('checked');
for (var i=0; i<this.cb_list.length; i++)
{
this.cb_list[i].set('checked', checked);
if (!this.cb_list[i].get('disabled'))
{
this.cb_list[i].set('checked', checked);
}
}
},

Expand Down

0 comments on commit 0bce192

Please sign in to comment.