Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
D
drupal
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Custom Issue Tracker
Custom Issue Tracker
Labels
Merge Requests
222
Merge Requests
222
Requirements
Requirements
List
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Analytics
Analytics
Code Review
Insights
Issue
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
project
drupal
Commits
4e90d24d
Commit
4e90d24d
authored
Nov 29, 2010
by
webchick
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
#818660
by yched, sun: Provide an AJAX command to invoke simple jQuery methods.
parent
ff119bc0
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
68 additions
and
1 deletion
+68
-1
includes/ajax.inc
includes/ajax.inc
+32
-1
misc/ajax.js
misc/ajax.js
+8
-0
modules/simpletest/tests/ajax.test
modules/simpletest/tests/ajax.test
+9
-0
modules/simpletest/tests/ajax_forms_test.module
modules/simpletest/tests/ajax_forms_test.module
+19
-0
No files found.
includes/ajax.inc
View file @
4e90d24d
...
...
@@ -1002,7 +1002,7 @@ function ajax_command_changed($selector, $asterisk = '') {
* The 'css' command will instruct the client to use the jQuery css() method
* to apply the CSS arguments to elements matched by the given selector.
*
* This command is implemented by Drupal.ajax.prototype.commands.
insert
()
* This command is implemented by Drupal.ajax.prototype.commands.
css
()
* defined in misc/ajax.js.
*
* @param $selector
...
...
@@ -1087,6 +1087,37 @@ function ajax_command_data($selector, $name, $value) {
);
}
/**
* Creates a Drupal AJAX 'invoke' command.
*
* The 'invoke' command will instruct the client to invoke the given jQuery
* method with the supplied arguments on the elements matched by the given
* selector. Intended for simple jQuery commands, such as attr(), addClass(),
* removeClass(), toggleClass(), etc.
*
* This command is implemented by Drupal.ajax.prototype.commands.invoke()
* defined in misc/ajax.js.
*
* @param $selector
* A jQuery selector string. If the command is a response to a request from
* an #ajax form element then this value can be NULL.
* @param $method
* The jQuery method to invoke.
* @param $arguments
* (optional) A list of arguments to the jQuery $method, if any.
*
* @return
* An array suitable for use with the ajax_render() function.
*/
function
ajax_command_invoke
(
$selector
,
$method
,
array
$arguments
=
array
())
{
return
array
(
'command'
=>
'invoke'
,
'selector'
=>
$selector
,
'method'
=>
$method
,
'arguments'
=>
$arguments
,
);
}
/**
* Creates a Drupal AJAX 'restripe' command.
*
...
...
misc/ajax.js
View file @
4e90d24d
...
...
@@ -543,6 +543,14 @@ Drupal.ajax.prototype.commands = {
$
(
response
.
selector
).
data
(
response
.
name
,
response
.
value
);
},
/**
* Command to apply a jQuery method.
*/
invoke
:
function
(
ajax
,
response
,
status
)
{
var
$element
=
$
(
response
.
selector
);
$element
[
response
.
method
].
apply
(
$element
,
response
.
arguments
);
},
/**
* Command to restripe a table.
*/
...
...
modules/simpletest/tests/ajax.test
View file @
4e90d24d
...
...
@@ -211,6 +211,15 @@ class AJAXCommandsTestCase extends AJAXTestCase {
);
$this
->
assertCommand
(
$commands
,
$expected
,
"'data' AJAX command issued with correct key and value"
);
// Tests the 'invoke' command.
$commands
=
$this
->
drupalPostAJAX
(
$form_path
,
$edit
,
array
(
'op'
=>
t
(
"AJAX invoke command: Invoke addClass() method."
)));
$expected
=
array
(
'command'
=>
'invoke'
,
'method'
=>
'addClass'
,
'arguments'
=>
array
(
'error'
),
);
$this
->
assertCommand
(
$commands
,
$expected
,
"'invoke' AJAX command issued with correct method and argument"
);
// Tests the 'html' command.
$commands
=
$this
->
drupalPostAJAX
(
$form_path
,
$edit
,
array
(
'op'
=>
t
(
"AJAX html: Replace the HTML in a selector."
)));
$expected
=
array
(
...
...
modules/simpletest/tests/ajax_forms_test.module
View file @
4e90d24d
...
...
@@ -176,6 +176,16 @@ function ajax_forms_test_ajax_commands_form($form, &$form_state) {
'#suffix'
=>
'<div id="data_div">Data attached to this div.</div>'
,
);
// Shows the AJAX 'invoke' command.
$form
[
'invoke_command_example'
]
=
array
(
'#value'
=>
t
(
"AJAX invoke command: Invoke addClass() method."
),
'#type'
=>
'submit'
,
'#ajax'
=>
array
(
'callback'
=>
'ajax_forms_test_advanced_commands_invoke_callback'
,
),
'#suffix'
=>
'<div id="invoke_div">Original contents</div>'
,
);
// Shows the AJAX 'html' command.
$form
[
'html_command_example'
]
=
array
(
'#value'
=>
t
(
"AJAX html: Replace the HTML in a selector."
),
...
...
@@ -331,6 +341,15 @@ function ajax_forms_test_advanced_commands_data_callback($form, $form_state) {
return
array
(
'#type'
=>
'ajax'
,
'#commands'
=>
$commands
);
}
/**
* AJAX callback for 'invoke'.
*/
function
ajax_forms_test_advanced_commands_invoke_callback
(
$form
,
$form_state
)
{
$commands
=
array
();
$commands
[]
=
ajax_command_invoke
(
'#invoke_div'
,
'addClass'
,
array
(
'error'
));
return
array
(
'#type'
=>
'ajax'
,
'#commands'
=>
$commands
);
}
/**
* AJAX callback for 'html'.
*/
...
...
Write
Preview
Markdown
is supported
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