Skip to content

Instantly share code, notes, and snippets.

@jedgell
Last active December 25, 2015 14:39
Show Gist options
  • Save jedgell/6992704 to your computer and use it in GitHub Desktop.
Save jedgell/6992704 to your computer and use it in GitHub Desktop.
AJAX events on views
/**
* @file
* This JavaScript reacts to certain AJAX events on the view.
*/
jQuery(document).ready(function(){
jQuery('input[type="submit"][name="op"][value="Save"]#edit-submit').hide();
})
/**
* Function built on wireframe from
* https://drupal.org/node/1781988#comment-6835168
*/
Drupal.behaviors.my_view_machine_name = {
attach: function(context, settings) {
if (Drupal.views !== undefined) {
jQuery.each(Drupal.views.instances, function(i, view) {
if (view.settings.view_name == "my_view_machine_name") {
jQuery(document).ajaxComplete(function(event, xhr, settings){
jQuery('input[type="submit"][name="op"][value="Save"]#edit-submit').hide();
var response = JSON.parse(xhr.response);
var resp_keys = Object.keys(response[0].settings.ajax);
if (response[0].settings.ajax[resp_keys[0]].callback == "editablefields_form_update") {
jQuery('#view-auto-refresh').click();
}
});
view.$view.once('view-refresher', function() {
var html = '<a href="' + view.settings.view_path + '" id="view-auto-refresh" class="view-refresher" style="display:none">Refresh</a>';
view.$view.append(jQuery(html).each(jQuery.proxy(view.attachPagerLinkAjax, view)));
});
return false;
}
});
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment