Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
project
drupal
Commits
43a27081
Commit
43a27081
authored
Oct 13, 2013
by
catch
Browse files
Issue
#1589176
by nod_: Fixed Use data-* to store #states api informations.
parent
c9d22bc4
Changes
2
Hide whitespace changes
Inline
Side-by-side
core/includes/common.inc
View file @
43a27081
...
@@ -2724,10 +2724,7 @@ function drupal_process_attached($elements, $dependency_check = FALSE) {
...
@@ -2724,10 +2724,7 @@ function drupal_process_attached($elements, $dependency_check = FALSE) {
*/
*/
function
drupal_process_states
(
&
$elements
)
{
function
drupal_process_states
(
&
$elements
)
{
$elements
[
'#attached'
][
'library'
][]
=
array
(
'system'
,
'drupal.states'
);
$elements
[
'#attached'
][
'library'
][]
=
array
(
'system'
,
'drupal.states'
);
$elements
[
'#attached'
][
'js'
][]
=
array
(
$elements
[
'#attributes'
][
'data-drupal-states'
]
=
JSON
::
encode
(
$elements
[
'#states'
]);
'type'
=>
'setting'
,
'data'
=>
array
(
'states'
=>
array
(
'#'
.
$elements
[
'#id'
]
=>
$elements
[
'#states'
])),
);
}
}
/**
/**
...
@@ -3856,6 +3853,11 @@ function drupal_render(&$elements) {
...
@@ -3856,6 +3853,11 @@ function drupal_render(&$elements) {
return
''
;
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.
// Get the children of the element, sorted by weight.
$children
=
element_children
(
$elements
,
TRUE
);
$children
=
element_children
(
$elements
,
TRUE
);
...
@@ -3901,11 +3903,6 @@ function drupal_render(&$elements) {
...
@@ -3901,11 +3903,6 @@ function drupal_render(&$elements) {
$elements
[
'#children'
]
=
$elements
[
'#markup'
]
.
$elements
[
'#children'
];
$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
// Add additional libraries, CSS, JavaScript an other custom
// attached data associated with this element.
// attached data associated with this element.
if
(
!
empty
(
$elements
[
'#attached'
]))
{
if
(
!
empty
(
$elements
[
'#attached'
]))
{
...
...
core/misc/states.js
View file @
43a27081
...
@@ -18,17 +18,17 @@ var states = Drupal.states = {
...
@@ -18,17 +18,17 @@ var states = Drupal.states = {
*/
*/
Drupal
.
behaviors
.
states
=
{
Drupal
.
behaviors
.
states
=
{
attach
:
function
(
context
,
settings
)
{
attach
:
function
(
context
,
settings
)
{
var
$
context
=
$
(
context
);
var
$
states
=
$
(
context
)
.
find
(
'
[data-drupal-states]
'
)
;
for
(
var
selector
in
settings
.
state
s
)
{
var
config
,
state
;
if
(
settings
.
states
.
hasOwnProperty
(
selector
)
)
{
for
(
var
i
=
0
,
il
=
$states
.
length
;
i
<
il
;
i
+=
1
)
{
for
(
var
state
in
settings
.
states
[
selector
])
{
config
=
JSON
.
parse
(
$states
[
i
].
getAttribute
(
'
data-drupal-states
'
));
if
(
settings
.
states
[
selector
].
hasOwnProperty
(
state
)
)
{
for
(
state
in
config
)
{
new
states
.
Dependent
(
{
if
(
config
.
hasOwnProperty
(
state
))
{
element
:
$context
.
find
(
selector
),
new
states
.
Dependent
({
state
:
states
.
State
.
sanitize
(
state
),
element
:
$
(
$
state
s
[
i
]
),
constraints
:
setting
s
.
s
tate
s
[
selector
][
state
]
state
:
state
s
.
S
tate
.
sanitize
(
state
),
});
constraints
:
config
[
state
]
}
}
);
}
}
}
}
}
}
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment