Closed (fixed)
Project:
Fasttoggle
Version:
7.x-1.0
Component:
Code
Priority:
Normal
Category:
Feature request
Assigned:
Reporter:
Created:
13 Dec 2012 at 16:42 UTC
Updated:
26 Mar 2014 at 06:16 UTC
Jump to comment: Most recent
When clicking on a fastToggle that has the javascript update method, it would be nice if it was possible to trigger other actions. For example, when toggling the node status un/published many themes display unpublished nodes with different background colors, etc.
The easiest way to accomplish this is to add ajax_command_invoke to the already existing ajax_request. For example in fasttoggle.toggle.inc in the function fasttoggle_node_option just add ajax_command_invoke after the replace and trigger a custom event on the DOM for body so other actions can fire
if (isset($_POST['js']) && $_POST['js']) {
drupal_add_http_header('Content-Type', 'text/javascript; charset=utf-8');
$path = request_path();
echo ajax_render(array(
ajax_command_replace('.' . $oldClass, fasttoggle($options[$option][intval($node->$option)], $path, FASTTOGGLE_FORMAT_HTML, $option . '_' . $node->nid, $newClass)),
ajax_command_invoke('body','trigger', array('fastToggleNodeOption',$newClass))
));
exit;
}
A simple javascript jQuery function can then take care of the rest
jQuery('body').bind('fastToggleNodeOption', function(event, value){
console.log(value);
}
Comments
Comment #1
nigelcunningham commentedComment #2
nigelcunningham commentedWould you want to get details of what the change was?
Comment #3
jhm commentedIf that was easily possible, why not
Comment #4
nigelcunningham commentedActually I'll leave it at what you initially suggested because the new class already has all the info. I'll just rename the trigger to FasttoggleTrigger to reflect that fact that it could be a user or comment value that is toggled.
The new class is fasttoggle-status-{OBJECT TYPE}-{SETTING GROUP}-{SETTING}-{NEW VALUE}. Examples are:
fasttoggle-status-user-role-administrator-1
fasttoggle-status-node-status-sticky-0
Comment #5
nigelcunningham commented