Skip to content

Instantly share code, notes, and snippets.

@martsie
Created January 25, 2017 11:08
Show Gist options
  • Save martsie/ac005459403304a59e413d3ecfd06fb7 to your computer and use it in GitHub Desktop.
Save martsie/ac005459403304a59e413d3ecfd06fb7 to your computer and use it in GitHub Desktop.
Drupal 7 AJAX commands javascript implementation
(function ($) {
Drupal.behaviors.my_custom_module = {
attach: function(context, settings) {
// Use context to ensure the link is only ever activated if it's regenerated.
var $mySpecialLink = $('#my-special-link', context);
// Only run if the link exists in the current page load or fragment refresh.
if ($mySpecialLink.size() > 0) {
new Drupal.ajax('#my-special-link', $mySpecialLink, {
url: $mySpecialLink.attr('href'),
settings: {},
event: 'click tap'
});
}
}
}
})(jQuery);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment