If you use an ajax page from views like seen in the screenshot and you click on page 1 2 3 4 an extra icon-element is added(screenshot

SCREENSHOT: http://screensnapr.com/v/PdSrsE.png

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

marcoka’s picture

FileSize
625 bytes

attached patch should solve that

marcoka’s picture

Status: Active » Needs review
ahwebd’s picture

Thanks e-anima
Patch working for me

jefkin’s picture

I discovered this problem in parallel by having an ajax loading bit on a page with a dhtml menu. in addition to the multiple passes causing bouncy menus, the menus I had the cloned menu item apearing 2, 3, 5 times depending on how many ajax calls happened. D:

So I searched here and found this issue, but I have a serious doubt about this patch. I mean, doesn't this patch avoid using the the drupal 7 behaviors update?

instead of:

 Drupal.behaviors.dhtmlMenu = { 
   attach: function() {
...

why not use:

 Drupal.behaviors.dhtmlMenu = { 
   attach: function(context, settings)
...

and then change your calls like:

    // Sanitize by removing "expanded" on menus already marked "collapsed".
    $('li.dhtml-menu.collapsed.expanded').removeClass('expanded');

    /* Relevant only on "open-only" menus:
     * The links of expanded items should be marked for emphasis.
     */
    if (settings.nav == 'open') {
      $('li.dhtml-menu.expanded').addClass('dhtml-menu-open');
    }
...

with the recommended style:

    // Sanitize by removing "expanded" on menus already marked "collapsed".
  $('li.dhtml-menu.collapsed.expanded', context).once('dhtml', function() { 
    $(this).removeClass('expanded'); 
  });

    /* Relevant only on "open-only" menus:
     * The links of expanded items should be marked for emphasis.
     */
    if (settings.nav == 'open') {
      $('li.dhtml-menu.expanded', context).once('dhtml', function () {
        $(this).addClass('dhtml-menu-open');
      });
    }
... 

Though, I typically don't use in line functions, and instead define new functions (even if relatively simple), as in:

Drupal.dhtmlMenu.removeExpanded = function() {
  // Removing "expanded".
  $(this).removeClass('expanded'); 
}
Drupal.dhtmlMenu.addOpen = function() {
  // Adding "open".
  $(this).addClass('dhtml-menu-open'); 
}
...

So then your attach code is cleaner looking (instead of the above...):

    // Sanitize by removing "expanded" on menus already marked "collapsed".
  $('li.dhtml-menu.collapsed.expanded', context).once('dhtml', Drupal.dhtmlMenu.removeExpanded);

    /* Relevant only on "open-only" menus:
     * The links of expanded items should be marked for emphasis.
     */
    if (settings.nav == 'open') {
      $('li.dhtml-menu.expanded', context).once('dhtml', Drupal.dhtmlMenu.addOpen);
    }
... 

Either with or without defined functions, just using context and .once() in addition to being part of the best practices, will also make sure that you won't re-run your js over the same section ever -- no matter how many ajax calls you load., and you offer the possibility of having ajax added dhtml menus. Although it's perhaps too complicated a system for *that* to work out of the box.

michaelfavia’s picture

@jefkin agree with this method as well. any chance we could squeeze a patch out of you to make it happen? Id be happy to commit it post haste after a review.

jefkin’s picture

@michaelfavia, well quick patch squeezed out. I've tested in all the ways that I use it, (clone). But we should have people checking that use other ways.

jefkin’s picture

without the debugging drivel I left in the top on #6 :-/

michaelfavia’s picture

Assigned: Unassigned » michaelfavia

Quite a patch there ;) I'll do my best to review it tonight or tomorrow and depending on that get it added to the dev branch with proper attribution to you. Thank you!

jefkin’s picture

@michaelfavia

I forgot a last minute change I added two weeks ago.

Uhh :-/ , after a bit of testing my team found a few minor flaws, and one semi-serious one in the patch I last sent.

I'm attaching the specific spot changes based on the #7 patch: "1178226-drupal-standards-behavior-2.patch" to fix it, as well as a full patch from head: "1178226-drupal-standards-behavior-full.patch".

I'm happy to let you know that this newest version is being used in a production site now for 2 weeks without a problem :D

dmegatool’s picture

Thx for the path ! Works here too :)

jonloh’s picture

Status: Needs review » Reviewed & tested by the community

the latest patch in #9 solves the problem. Just that the patch doesn't work quite well due to some issue in the file itself. Hence, you will need to patch it manually.

Apart from that, it works great ;) Thanks!

Dentorat’s picture

As mentioned, it has to be patched manually, but I'm getting pretty confused trying to do this, can anyone provide a copy of the fully patched file?

Thanks

anneeasterling’s picture

Issue summary: View changes

Reporting successfully applying this patch to 7.x-1.0-beta1. Extra cloned items no longer appear after a views ajax filter action.

Would it be possible to get this merged to the next release version?

Many thanks!

vuil’s picture

Status: Reviewed & tested by the community » Needs work

Please the patch needs re-roll... I set the issue to Needs work.

vuil’s picture

Issue tags: +Needs reroll

Add Needs reroll in Issue tags.

vuil’s picture

Assigned: michaelfavia » Unassigned

I also unassigned the issue of @michaelfavia.