Issue #1589176 by nod_: Fixed Use data-* to store #states api informations.
parent
c9d22bc492
commit
43a270816d
|
@ -2724,10 +2724,7 @@ function drupal_process_attached($elements, $dependency_check = FALSE) {
|
|||
*/
|
||||
function drupal_process_states(&$elements) {
|
||||
$elements['#attached']['library'][] = array('system', 'drupal.states');
|
||||
$elements['#attached']['js'][] = array(
|
||||
'type' => 'setting',
|
||||
'data' => array('states' => array('#' . $elements['#id'] => $elements['#states'])),
|
||||
);
|
||||
$elements['#attributes']['data-drupal-states'] = JSON::encode($elements['#states']);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -3856,6 +3853,11 @@ function drupal_render(&$elements) {
|
|||
return '';
|
||||
}
|
||||
|
||||
// Add any JavaScript state information associated with the element.
|
||||
if (!empty($elements['#states'])) {
|
||||
drupal_process_states($elements);
|
||||
}
|
||||
|
||||
// Get the children of the element, sorted by weight.
|
||||
$children = element_children($elements, TRUE);
|
||||
|
||||
|
@ -3901,11 +3903,6 @@ function drupal_render(&$elements) {
|
|||
$elements['#children'] = $elements['#markup'] . $elements['#children'];
|
||||
}
|
||||
|
||||
// Add any JavaScript state information associated with the element.
|
||||
if (!empty($elements['#states'])) {
|
||||
drupal_process_states($elements);
|
||||
}
|
||||
|
||||
// Add additional libraries, CSS, JavaScript an other custom
|
||||
// attached data associated with this element.
|
||||
if (!empty($elements['#attached'])) {
|
||||
|
|
|
@ -18,17 +18,17 @@ var states = Drupal.states = {
|
|||
*/
|
||||
Drupal.behaviors.states = {
|
||||
attach: function (context, settings) {
|
||||
var $context = $(context);
|
||||
for (var selector in settings.states) {
|
||||
if (settings.states.hasOwnProperty(selector)) {
|
||||
for (var state in settings.states[selector]) {
|
||||
if (settings.states[selector].hasOwnProperty(state)) {
|
||||
new states.Dependent({
|
||||
element: $context.find(selector),
|
||||
state: states.State.sanitize(state),
|
||||
constraints: settings.states[selector][state]
|
||||
});
|
||||
}
|
||||
var $states = $(context).find('[data-drupal-states]');
|
||||
var config, state;
|
||||
for (var i = 0, il = $states.length; i < il; i += 1) {
|
||||
config = JSON.parse($states[i].getAttribute('data-drupal-states'));
|
||||
for (state in config) {
|
||||
if (config.hasOwnProperty(state)) {
|
||||
new states.Dependent({
|
||||
element: $($states[i]),
|
||||
state: states.State.sanitize(state),
|
||||
constraints: config[state]
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue