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

nigelcunningham’s picture

Assigned: Unassigned » nigelcunningham
nigelcunningham’s picture

Would you want to get details of what the change was?

jhm’s picture

If that was easily possible, why not

nigelcunningham’s picture

Actually 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

nigelcunningham’s picture

Status: Active » Fixed

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

  • Commit c976d51 on master, 7.x-1.x by NigelCunningham:
    Fix #1865914: Add FastToggle triggers for ajax.
    
    Apply a slight...