I'm the co-maintainer of the Menu MiniPanels module. We're working on 7.x-2.x branch of that module to abandon qTip (#2215425: Menu Minipanels V2 without qtip), and integrate with Superfish. As part of our testing we've discovered that everything is working nicely, our mini-panels are being shown inside superfish menus, ajax reloading of views inside mini-panels works great.

However on mobile / small screens with the smallscreen accordion menu configuration enabled, views ajax links are completely broken, they are treated as regular links and open the page.

My hunch is that this has something to do with the entire DOM structure of the sf-menu being cloned to build the accordion. I wonder what was the motivation for cloning the DOM instead of changing out the necessary classes on the existing structure?

Might it be possible to use the same DOM menu structure for both accordion and full menu? If so, I might start looking into a solution for this. This is truly sad, because I was hoping the integration would be nearly seamless :(

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

jwilson3’s picture

Issue summary: View changes
jwilson3’s picture

Issue summary: View changes
jwilson3’s picture

Issue summary: View changes
jwilson3’s picture

Assigned: Unassigned » jwilson3

acrollet gave me a good idea to try to run Drupal.behaviors() after adding the new Dom elements, which might solve this issue. I'll look into it and see if that does it.

mehrpadin’s picture

Hey there,

Great, I'll update the plugin soon, if Drupal Behaviors didn't fix the problem setup an example and put it online so I can check, thanks! also, regarding these parts:

I wonder what was the motivation for cloning the DOM instead of changing out the necessary classes on the existing structure?

It was basically not possible, because not only it had to be able to create <select> elements the accordion style also needed a wholly different structure to work as expected, things like the button that controls the visibility of the whole accordion, the expand & collapse links of each parent and so on and so forth, in addition to all this, in many many cases dropdowns made for desktop versions have stuff that is impossible to fit in either a <select> or an accordion, so there had to be a way to sanitize the input anyway, on the other hand even if there was a way to use the same object for all the three it could be very much resource-consuming to alter the object and revert and so on (revert as in for example when switching from portrait to landscape on a tablet) so all in all it was not possible nor efficient.

Might it be possible to use the same DOM menu structure for both accordion and full menu?

Yet technically speaking yes it is possible to use the same object for an accordion and a full menu - but not a <select> indeed - however only and only if we somehow can make sure the object does not and will not contain anything that gets in along the way and breaks either the accordion structure or behavior or both and so on and so forth.

I was hoping the integration would be nearly seamless :(

Haven't tried Mini Panels so pardon me if it sounds silly: isn't it better to not to include "columns" in the accordion menu at all? sfSmallscreen uses a class (.sf-smallscreen-remove) to figure out what should be removed while cloning (yes no documentation yet so no one knows this, will update the whole documentation soon) so if you add the class to all the elements in a MiniPanel except for <ul>, <li>, and <a>, and even <span> I guess you can then use the word seamless with a semicolon and the other kind of parentheses :D

jwilson3’s picture

in many many cases dropdowns made for desktop versions have stuff that is impossible to fit in either a
or an accordion, so there had to be a way to sanitize the input anyway, on the other hand even if there was a way to use the same object for all the three it could be very much resource-consuming to alter the object and revert and so on (revert as in for example when switching from portrait to landscape on a tablet) so all in all it was not possible nor efficient.

I feel you about needing to clean up the UL structures for conversion to select lists. However, with the advent of responsive layouts, I felt that stacking of columns and having a mega menu that requires scrolling down the page is not an invalid method for navigation, on the contrary, it is one that works fairly well with the accordion functionality.

Aside from what you've stated above, why couldn't we just add/remove the sf-accordion class from the ul, and do the rest (eg hiding of elements, changing / stacking layouts) in CSS? This doesn't seem that it would be too resource intensive, but of course, I could be missing something.

jwilson3’s picture

if Drupal Behaviors didn't fix the problem setup an example and put it online so I can check, thanks!

Unfortunately, Drupal.attachBehaviors did not fix the problem. There is a fundamental issue with using javascript clone() on a view that has ajax enabled, because of the DOM ID used by views, created based on an md5 hash. Clicking the ajax pager of the cloned object still tries to update the view in the original menu, not the one in the cloned accordion menu.

Also, fwiw, switching to javascript clone(true) doesn't solve this problem either, as it suffers from exactly the same issue -- the original DOM object is updated, not the clone.

I've setup a testing site at https://dev-responsive-minipanels.gotpantheon.com, with the following modules:

 ctools 7.x-1.4        
 menu_minipanels 7.x-2.x-dev                  
 panels  7.x-3.4        
 superfish  7.x-1.9+29-dev 
 views 7.x-3.7        
 responsive_bartik 7.x-1.0-beta2

I've attached the patch of what I've currently written, and is currently being used on https://dev-responsive-minipanels.gotpantheon.com.

jwilson3’s picture

So its clear, here is how to see the error:

  1. Reduce your browser window size down to around 400 pixels wide.
  2. Expand the menu, and click the menu minipanels link, note that you are seeing results 1 through 5 of the view.
  3. Then click the view pager "next" link, and wait for it to finish loading.
  4. Note that the view disappears entirely.
  5. Expand your browser window up to > 900 pixels wide and hover the "Menu MiniPanels" link in the main menu.
  6. Note that you are now on "page two" of the view, showing results 6 through 10.
jwilson3’s picture

I ran with the idea of not cloning the menus, and have forked the Superfish-For-Drupal on github, to see what would happen.

https://github.com/jameswilson/Superfish-for-Drupal/commit/60c2e89e5112d...

Long story short, i got it partially working, and ajax views behave properly (yay!) however (ohnoes!) a couple other issues have popped up as a result of not cloning:

  • On mobile, both the regular sfHover classes and fullscreen superfish menu hover events still trigger IN ADDITION TO the accordion sf-expanded click events. I was thinking maybe to just do a search and replace all instances of sf-expanded with sfHover on the <li> elements ( except for where that class is used to toggle visibility of the entire menu on the <ul>).
  • Sizing up from a small size to a larger size, the *widths* of the superfish menu items need to be recalculated and placed inline). This maybe hints at a larger issue that would be difficult to work around, so maybe I'm thinking I should store the inline styles on the <li> elements in a data object, so that I can swap them out, similar to what I'm doing on the <ul>.
mehrpadin’s picture

James,

Thanks for the demo, and all these :) I'll be back soon with some thoughts, busy cleaning up the issue queue at the moment!

jwilson3’s picture

Thanks for having a look!

Just to be clear the changes i was working on in #9 are NOT what is being used on the demo site, which still contains the clean original github master branch, and the module patch on #7.

mehrpadin’s picture

You're welcome, thank you, I've found a solution! need to do some profiling then testing with a few other modules etc before sharing :) there are two things also that we need, at least only when SF module exists: a) the main <ul> (the one that gets a menu-minipanel-panel class) to have an ID, needless to say it has to be unique, I've no idea how one should be generated, perhaps an md5 of panel name plus block ID? just an idea b) the very same element to also have a sf-smallscreen-move class, well from which you can guess what the solution is!

jwilson3’s picture

a) the main <ul> (the one that gets a menu-minipanel-panel class) to have an ID,

Easy, we can use the mini_panel's machine name and run it through drupal_html_id in our module (patch in next comment).

b) the very same element to also have a sf-smallscreen-move class, well from which you can guess what the solution is!

Actually, can you spell it out? what does this do? I'm not familiar with what this class does, and am tied up in other things right now.

You can implement a preprocess function in superfish module to add the needed class like this:

function superfish_preprocess_menu_minipanel(&$vars) {
  $vars['classes_array'][] = drupal_html_class('sf-smallscreen-move');
}
mehrpadin’s picture

Great, that class would help the sfSmallscreen plugin find out which element(s) must be moved to the small-screen version rather than cloned, moved there and then returned also and so on.

jwilson3’s picture

Patch for comment #13 item A to add unique ID (Note this is a patch for menu_minipanels module, not superfish). I updated the comment #13 with some more info, please re-read if you already have.

jwilson3’s picture

Can you let me know how this goes?

I can expedite getting this patch into menu minipanels 7.x-2.x-dev asap, it almost makes sense to do anyway.

jwilson3’s picture

Assigned: jwilson3 » Unassigned
mehrpadin’s picture

FileSize
4.52 KB

James,

Try the attached, bear in mind much of this will be definitely changed, also regarding your update, the class should be added through the Menu MiniPanel not SF.

lklimek’s picture

Status: Active » Needs review
FileSize
611 bytes

I've encountered a similar issue. It was caused by invalid order of behaviors. Can be simply fixed with the help of behavior_weights module; please see attached patch (don't forget to download and enable behavior_weights).

fox_01’s picture

Status: Needs review » Reviewed & tested by the community

#19 works without updateing sfsmallscreen..js from #18

jwilson3’s picture

Not sure we should be adding a new dependency to the module just to solve this sufficiently "edge" case. Damien?

What if we add the weight part of the patch in #19, and then add a note to Readme and Project in "Known Issues" section (or the like) referencing this issue and how to resolve it using behavior weights module?

fox_01’s picture

i think this should do the thing if you add the weight to the module and describe when the dependency is needed and that this has to be installed manually.

lklimek’s picture

> Not sure we should be adding a new dependency to the module just to solve this sufficiently "edge" case.

In my opinion, this is not a matter of "edge" case. Current implementation breaks many jQuery-based mechanisms, not only Ajax.

Core problem here is that Superfish copies some parts of DOM. If called too late (that is, if not called as the first behavior on the page), it copies code already processed by other behaviors (and having, for example, "ajax-processed" class set) but it DOES NOT copy attached jQuery handlers (like click() handler).

Well-designed third-party JS code shall use .once() or similar mechanism to ensure it doesn't process a given DOM node twice. Unfortunately, as the DOM has been copied with "-processed" class already set, the copy will be skipped and not processed at all - and handlers will never be attached.

Bad news is that this is "not deterministic", as it does depend on order of behavior execution, which can be different in different setups. So it's likely that module author will do some testing and assume that everything works well, while users might encounter hard-to-debug issues.

jwilson3’s picture

Thanks for #23, but I don't understand your position entirely. In your opinion, is this something that would demand the extra module dependency? or could we try this as a partial patch + documentation issue as I suggest?

lklimek’s picture

In my opinion, the issue should be fixed in code and work out-of-box. If we go with my patch, we should add the dependency (it's only 2kB of JS code).

In current state, it is hard to spot during testing & debug potential issues. And people don't read the docs ;-).

  • mehrpadin committed 3dd4c82 on 7.x-1.x authored by lklimek
    Issue #2225001 by jwilson3, lklimek, mehrpadin: Smallscreen accordion...
mehrpadin’s picture

Hey there,

Thanks, don't we need this for D8? just wondering.

ivnish’s picture

Status: Reviewed & tested by the community » Fixed

Status: Fixed » Closed (fixed)

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