Skip to main content
simplified code for clarity
Source Link
Meggy
  • 427
  • 2
  • 15
 Drupal.behaviors.ajaxlinks = function (context) {
    $('.morelink:not(.togg-processed)', context).addClass('togg-processed').each(function () {
      $indexvar myindex = $('.morelink').index($(this));
      var target = $('.newthing').eq($('.morelink').index($(this)))
      var nid = $(".mynid").eq($indexmyindex).val();
    $(this).click(function() {
if (($('.hiddenrows').eq($('.morelink').index($(this))myindex).is(":hidden"))
|| ($('.shownrows').eq($('.morelink').index($(this))myindex).is(":visible")))
{
    $('.hiddenrows').eq($('.morelink').index($(this))myindex).show();
    $('.newthing').eq($('.morelink').index($(this))myindex).show();
      var toLoad = Drupal.settings.basePath + 'replies/' + nid;
      xhr = $.ajax({
        url: toLoad,
        success: function(data) {
        $(target).css( "height","200px" );
        $(target).html($(data));
     Drupal.attachBehaviors(context);
}
});
}
else
{
    $('.hiddenrows').eq($('.morelink').index($(this))myindex).hide();
    $('.newthing').eq($('.morelink').index($(this))myindex).hide();
}
    return false;
    });
  });
};

And here is the php which shows in the content-type.tpl.php for both views:

<div class="newthing" >
<input type="hidden" class="mynid" value=<?php echo $node->nid;?> />
</div> <!-- newthing -->
Drupal.behaviors.ajaxlinks = function (context) {
    $('.morelink:not(.togg-processed)', context).addClass('togg-processed').each(function () {
      $index = $('.morelink').index($(this));
      var target = $('.newthing').eq($('.morelink').index($(this)))
      var nid = $(".mynid").eq($index).val();
    $(this).click(function() {
if (($('.hiddenrows').eq($('.morelink').index($(this))).is(":hidden"))
|| ($('.shownrows').eq($('.morelink').index($(this))).is(":visible")))
{
    $('.hiddenrows').eq($('.morelink').index($(this))).show();
    $('.newthing').eq($('.morelink').index($(this))).show();
      var toLoad = Drupal.settings.basePath + 'replies/' + nid;
      xhr = $.ajax({
        url: toLoad,
        success: function(data) {
        $(target).css( "height","200px" );
        $(target).html($(data));
     Drupal.attachBehaviors(context);
}
});
}
else
{
    $('.hiddenrows').eq($('.morelink').index($(this))).hide();
    $('.newthing').eq($('.morelink').index($(this))).hide();
}
    return false;
    });
  });
};

And here is the php which shows in the content-type.tpl.php for both views:

<div class="newthing" >
<input type="hidden" class="mynid" value=<?php echo $node->nid;?> />
</div> <!-- newthing -->
 Drupal.behaviors.ajaxlinks = function (context) {
    $('.morelink:not(.togg-processed)', context).addClass('togg-processed').each(function () {
      var myindex = $('.morelink').index($(this));
      var target = $('.newthing').eq($('.morelink').index($(this)))
      var nid = $(".mynid").eq(myindex).val();
    $(this).click(function() {
if (($('.hiddenrows').eq(myindex).is(":hidden"))
|| ($('.shownrows').eq(myindex).is(":visible")))
{
    $('.hiddenrows').eq(myindex).show();
    $('.newthing').eq(myindex).show();
      var toLoad = Drupal.settings.basePath + 'replies/' + nid;
      xhr = $.ajax({
        url: toLoad,
        success: function(data) {
        $(target).css( "height","200px" );
        $(target).html($(data));
     Drupal.attachBehaviors(context);
}
});
}
else
{
    $('.hiddenrows').eq(myindex).hide();
    $('.newthing').eq(myindex).hide();
}
    return false;
punctuation
Source Link
Meggy
  • 427
  • 2
  • 15

Jquery in ajaxed loaded content referencing incorrect elementnode id

I have a list of nodes each with a click. The click sends a node reference argument which loads a new view using ajax. Jquery collects the node reference number via a hidden input value on the content-type-tpl.php. Likewise the nodes in the new view each have a click which sends a node reference argument which loads a new view using ajax. However while the clicks in the original view work correctly, the clicks in the newly called view do not reference the correct node. Instead of referencing the node id for the node which is clicked, the node id of the next node in the view is collected instead. Oddly when placing <?php echo $node->nid;?> on the content-type-tpl.php, the correct node id is echoed on the page but. But sadly this is not the one sent to the view argument. So clicking any node in the the newly loaded ajaxed view, sends the id for the next node. Here's the javacript:

It's the same code so I can't see why it works differently in the newly loaded view. Can anyone spot what I am doing wrong?

Jquery in ajaxed loaded content referencing incorrect element

I have a list of nodes each with a click. The click sends a node reference argument which loads a new view using ajax. Jquery collects the node reference number via a hidden input value on the content-type-tpl.php. Likewise the nodes in the new view each have a click which sends a node reference argument which loads a new view using ajax. However while the clicks in the original view work correctly the clicks in the newly called view do not reference the correct node. Instead of referencing the node id for the node which is clicked, the node id of the next node in the view is collected instead. Oddly when placing <?php echo $node->nid;?> on the content-type-tpl.php the correct node id is echoed on the page but sadly this is not the one sent to the view argument. So clicking any node in the the newly loaded ajaxed view sends the id for the next node. Here's the javacript:

Can anyone spot what I am doing wrong?

Jquery in ajaxed loaded content referencing incorrect node id

I have a list of nodes each with a click. The click sends a node reference argument which loads a new view using ajax. Jquery collects the node reference number via a hidden input value on the content-type-tpl.php. Likewise the nodes in the new view each have a click which sends a node reference argument which loads a new view using ajax. However while the clicks in the original view work correctly, the clicks in the newly called view do not reference the correct node. Instead of referencing the node id for the node which is clicked, the node id of the next node in the view is collected instead. Oddly when placing <?php echo $node->nid;?> on the content-type-tpl.php, the correct node id is echoed on the page. But sadly this is not the one sent to the view argument. So clicking any node in the the newly loaded ajaxed view, sends the id for the next node. Here's the javacript:

It's the same code so I can't see why it works differently in the newly loaded view. Can anyone spot what I am doing wrong?

Source Link
Meggy
  • 427
  • 2
  • 15

Jquery in ajaxed loaded content referencing incorrect element

I have a list of nodes each with a click. The click sends a node reference argument which loads a new view using ajax. Jquery collects the node reference number via a hidden input value on the content-type-tpl.php. Likewise the nodes in the new view each have a click which sends a node reference argument which loads a new view using ajax. However while the clicks in the original view work correctly the clicks in the newly called view do not reference the correct node. Instead of referencing the node id for the node which is clicked, the node id of the next node in the view is collected instead. Oddly when placing <?php echo $node->nid;?> on the content-type-tpl.php the correct node id is echoed on the page but sadly this is not the one sent to the view argument. So clicking any node in the the newly loaded ajaxed view sends the id for the next node. Here's the javacript:

Drupal.behaviors.ajaxlinks = function (context) {
    $('.morelink:not(.togg-processed)', context).addClass('togg-processed').each(function () {
      $index = $('.morelink').index($(this));
      var target = $('.newthing').eq($('.morelink').index($(this)))
      var nid = $(".mynid").eq($index).val();
    $(this).click(function() {
if (($('.hiddenrows').eq($('.morelink').index($(this))).is(":hidden"))
|| ($('.shownrows').eq($('.morelink').index($(this))).is(":visible")))
{
    $('.hiddenrows').eq($('.morelink').index($(this))).show();
    $('.newthing').eq($('.morelink').index($(this))).show();
      var toLoad = Drupal.settings.basePath + 'replies/' + nid;
      xhr = $.ajax({
        url: toLoad,
        success: function(data) {
        $(target).css( "height","200px" );
        $(target).html($(data));
     Drupal.attachBehaviors(context);
}
});
}
else
{
    $('.hiddenrows').eq($('.morelink').index($(this))).hide();
    $('.newthing').eq($('.morelink').index($(this))).hide();
}
    return false;
    });
  });
};

And here is the php which shows in the content-type.tpl.php for both views:

<div class="newthing" >
<input type="hidden" class="mynid" value=<?php echo $node->nid;?> />
</div> <!-- newthing -->

Can anyone spot what I am doing wrong?