<
Neerav Mehta
Founder & CEO
/**
* An AJAX-enabled form.
*/
function mymodule_form($form, &$form_state) {
$form = array();
// A textfield for the user to input his name.
$form['name'] = array(
'#title' => t('Your Name'),
'#type' => 'textfield',
);
// Blank output field which we will fill using AJAX.
$form['output'] = array(
'#prefix' => '<div id="output">',
'#suffix' => '</div>',
'#markup' => '',
);
// AJAX-enabled submit button.
$form['submit'] = array(
'#type' => 'submit',
'#value' => t('Submit'),
'#ajax' => array(
'callback' => 'mymodule_form_ajax_callback',
),
'#attached' => array(
'js' => array(
drupal_get_path('module', 'mymodule')
. '/js/mymodule.special_effects.js' => array(
'scope' => 'footer',
),
),
),
);
return $form;
}
/**
* AJAX callback function for mymodule_form().
*/
function mymodule_form_ajax_callback($form, $form_state) {
// Grab the name input by the user.
$name = check_plain($form_state['values']['name']);
// Invoke out Special Effects ajax command for the
// special effect we want to create.
$commands = array();
$commands[] = array(
'command' => 'special_effects',
'elementId' => 'output',
'name' => $name,
'duration' => 4000,
'amplify' => 3,
);
// Send the command to the page.
$page = array(
'#type' => 'ajax',
'#commands' => $commands,
);
return $page;
}
Now we need to create the AJAX framework command "special_effect". Create a file "js/mymodule.special_effects.js" in your module and write the following:
/**
* Special Effects AJAX framework command.
*/
Drupal.ajax.commands.special_effects = function(ajax, response, status) {
jQuery('#' + response.elementId)
.hide()
.text(response.name)
.fadeIn(response.duration, function() {
var fontSize = parseInt($(this).css('font-size'));
jQuery(this)
.animate({'font-size': (response.amplify * fontSize) + "px"}, 5000,
function() {
jQuery(this).animate({'font-size': fontSize + "px"}, 5000);
});
});
}
That's it. Here is how it looks:
Neerav Mehta
Neerav Mehta is the Founder & CEO of Red Crackle. With sterling qualities, Neerav’s technological acumen is firing a generation of progressive companies on the digital path. With an undergraduate degree in Electrical Engineering from India's most prestigious institution IIT Bombay and having spent seven years developing and contributing to the launch of AMD's innovative line of computer products, Neerav founded Red Crackle where he is lauded for his dynamic and innovative genius.
Let’s get you started!