1

I'm searching for a module that can expand the number of visible fields in a particular view result with a mouse click. I'm probably not searching with the good words because I only thing I found is thing like "infinite scroll" or "view load more" module and that's not what I nead.

Example of what I nead : You have 10 view nodes showing the title and the image of a content type. And when the user pays "Read more..." the node is reloaded with Ajax adding the description to the result of this result.

Did somebody know a module that can do a thing like this?

Thanks a lot and sorry for my bad English, English isn't my first language.

  • I'm afraid it's pretty uncommon and you may need to develop it yourself. Maybe you could create expanding display for your nodes and do it at node display level, without bothering views with it? I guess you'll have better chance to find something like that, than to find views plugin. – Mołot Jan 27 '14 at 15:34
  • My first guess was to load everything and use display:hide css code to hide the text and use Jquery animation to show the field on mouse click. – Marc-André Landreville Jan 27 '14 at 16:04
  • Given that raw amount of data is cheap nowadays (excl. mobile), it sounds like a plan. Connection initiation will usually take more time than actual data transfer, so by loading everything in one call you might actually save user's time. Depends on the amount of data, and how complicated it is - you don't want to overload user's browser, and waste time on DOM parsing on his side. It's all a matter of balance, where it's more art than science. – Mołot Jan 27 '14 at 19:19
0

The screen cast from Sean Buscay : How to use Drupal 7's built-in Ajax framework almost do that. The only difference is that the loaded nobe is always display on the same div base is id.

<?php

function ajax_reader_init() {
  drupal_add_js('misc/jquery.form.js');
  drupal_add_library('system', 'drupal.ajax');
}

/**
 * Implements hook_menu().
 */

function ajax_reader_menu() {
  // A menu callback is required when using ajax outside of the Form API.
  $items['ajax-reader'] = array(
 'page callback' => 'ajax_link_response',
 'access callback' => 'user_access',
 'access arguments' => array('access content'),
 'type' => MENU_CALLBACK,
  );
 return $items;
}

function ajax_link_response($type = 'ajax', $nid = 0) {
  $output = _ajax_reader_load_noder($nid);
  if ($type == 'ajax') {
    $commands = array();
    $commands[] = ajax_command_replace('#block-block-6', '<div id="block-block-6">' . $output . '</div>');
    $page = array(
      '#type' => 'ajax',
      '#commands' => $commands
    );
    ajax_deliver($page);
  }
  else {
    $output = '<div id="content">' . $output . '</div>';
    return $output;
  }
}

function _ajax_reader_load_noder($nid = 0) {
 return views_embed_view ('front','block', $nid);
}

Now the problem is I don't wan to send the result always to the same div. I wan to replace the view row by the new ajax loaded view. But I don't know how to pass the result to the good div.

    $commands[] = ajax_command_replace('#block-block-6', '<div id="block-block-6">' 

Lets say I click the title of the third view row the nid of this third element is process in the module but I nead a way to pass the parent div class (view-row-3) to the function ajax_reader_menu()

Did anybody can guide me on that, thanks I know that I'm not super clear, but all this still vary obscure for the moment, sorry.

  • I find the drupal ajax to be overkill. You could easily load this in the view itself and use jquery to hide/show what you need. – chadpeppers Jan 29 '14 at 22:33
0

Ok passing the variable to the module is easy. I change the line : function ajax_link_response($type = 'ajax', $nid = 0) { by this line : function ajax_link_response($type = 'ajax', $nid = 0, $row_number) { and edit the link to add this variable to adding the row_number:

but now I don't know how to add the_row_number to the link. I'll study view theming and comeback with the result.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.