summaryrefslogtreecommitdiff
path: root/includes
diff options
context:
space:
mode:
Diffstat (limited to 'includes')
-rw-r--r--includes/common.inc53
-rw-r--r--includes/form.inc33
2 files changed, 86 insertions, 0 deletions
diff --git a/includes/common.inc b/includes/common.inc
index a1c47c3da..b0cfd053f 100644
--- a/includes/common.inc
+++ b/includes/common.inc
@@ -3770,6 +3770,53 @@ function drupal_process_attached($elements, $weight = JS_DEFAULT, $dependency_ch
}
/**
+ * Adds JavaScript to the element to allow it to have different active states.
+ *
+ * @param $elements
+ * The structured array that may contain an array item named states. This
+ * array describes the different JavaScript states that can be applied to the
+ * element when certain contitions are met. The #states array is first keyed
+ * by one of the following states:
+ * - enabled
+ * - invisible
+ * - invalid
+ * - untouched
+ * - optional
+ * - filled
+ * - unchecked
+ * - irrelevant
+ * - expanded
+ * - readwrite
+ *
+ * Each of these states is an array containing conditions that must be met in
+ * order for this state to be active. The key to this conditioning array is
+ * a jQuery selector for the element that is checked. The value of the
+ * conditioning array are the states that are checked on the element (empty,
+ * checked, value, collapsed, etc) and the expected value of that condition.
+ *
+ * @code
+ * $form['email_canceled']['settings'] = array(
+ * '#type' => 'container',
+ * '#states' => array(
+ * // Hide the settings when the cancel notify checkbox is disabled.
+ * 'invisible' => array(
+ * 'input[name="email_canceled_toggle"]' => array('checked' => FALSE),
+ * ),
+ * ),
+ * );
+ * @endcode
+ */
+function drupal_process_states(&$elements) {
+ if (!empty($elements['#states'])) {
+ $elements['#attached']['js']['misc/states.js'] = array('weight' => JS_LIBRARY + 1);
+ $elements['#attached']['js'][] = array(
+ 'type' => 'setting',
+ 'data' => array('states' => array('#' . $elements['#id'] => $elements['#states'])),
+ );
+ }
+}
+
+/**
* Adds multiple JavaScript or CSS files at the same time.
*
* A library defines a set of JavaScript and/or CSS files, optionally using
@@ -4646,6 +4693,9 @@ function drupal_render(&$elements) {
}
}
+ // Add any JavaScript state information associated with the element.
+ drupal_process_states($elements);
+
// Add additional libraries, CSS, JavaScript an other custom
// attached data associated with this element.
drupal_process_attached($elements);
@@ -5171,6 +5221,9 @@ function drupal_common_theme() {
'vertical_tabs' => array(
'arguments' => array('element' => NULL),
),
+ 'container' => array(
+ 'arguments' => array('element' => NULL),
+ ),
);
}
diff --git a/includes/form.inc b/includes/form.inc
index 207a48c0a..e2d281384 100644
--- a/includes/form.inc
+++ b/includes/form.inc
@@ -2182,6 +2182,39 @@ function form_process_checkboxes($element) {
}
/**
+ * Processes a container element.
+ *
+ * @param $element
+ * An associative array containing the properties and children of the
+ * container.
+ * @param $form_state
+ * The $form_state array for the form this element belongs to.
+ * @return
+ * The processed element.
+ */
+function form_process_container($element, &$form_state) {
+ $element['#id'] = drupal_html_id(implode('-', $element['#parents']) . '-wrapper');
+ return $element;
+}
+
+/**
+ * Adds a container for grouped items
+ *
+ * @param $element
+ * An associative array containing the properties and children of the
+ * group.
+ * Properties used: #children.
+ * @return
+ * A themed HTML string representing the form element.
+ *
+ * @ingroup themeable
+ */
+function theme_container($variables) {
+ $element = $variables['element'];
+ return '<div class="form-wrapper" id="' . $element['#id'] . '">' . $element['#children'] . '</div>';
+}
+
+/**
* Format a table with radio buttons or checkboxes.
*
* @param $variables