diff --git a/core/includes/common.inc b/core/includes/common.inc index 19e0d59..983a864 100644 --- a/core/includes/common.inc +++ b/core/includes/common.inc @@ -4725,10 +4725,7 @@ function drupal_process_attached($elements, $group = JS_DEFAULT, $dependency_che */ 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'] = drupal_json_encode($elements['#states']); } /** @@ -5927,6 +5924,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); @@ -5966,11 +5968,6 @@ function drupal_render(&$elements) { } } - // 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'])) { diff --git a/core/misc/states.js b/core/misc/states.js index fa7a101..db3b0b2 100644 --- a/core/misc/states.js +++ b/core/misc/states.js @@ -18,13 +18,18 @@ var states = Drupal.states = { */ Drupal.behaviors.states = { attach: function (context, settings) { - for (var selector in settings.states) { - for (var state in settings.states[selector]) { - new states.Dependent({ - element: $(selector), - state: states.State.sanitize(state), - constraints: settings.states[selector][state] - }); + var $states = $('[data-drupal-states]'); + var i, il, config, state; + for (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] + }); + } } }