Advanced Module Manager

PHP code to disable page scrolling only when the submenu is visible

7 months 6 days ago #78067

Agent ModDM's Avatar Agent ModDM

Beste Peter van Westen,


I purchased the Pro version of Regular Labs Advanced Module Manager. Now I try to add some PHP code to a module.
To make sure I didn't miss something I already checked your PHP Assignment Guide: www.regularlabs.com/component/content/ar...ent-guide?Itemid=101
My purpose is as follows:
I use a navigation menu (Joomla module) at the top of my website. As in many navigation menus, you can hover items on the bar which expands a submenu. In my submenu a scrollable element is placed. And you know how it goes what people do: They scroll and move their mouse by accident. At a certain moment they accidentally scroll the page body instead of the menu (e.g. because their mouse is shortly outside the menu) and as a consequence they scroll the menu out of view - not desired. So my goal: Add a PHP code to disable page scrolling only when the submenu is visible = display:block.

In the Module settings under Toewijzingen (for non-Dutch people it's the second tab) at the bottom option (PHP) I tried to add the following code, without success:

echo "<script type=\"text/javascript\">
 
     if($('.dj-subwrap').is(':visible')) {
      $('body').addClass('fixedPosition');
    } else {
    $('body').removeClass('fixedPosition');
 }
 .fixedPosition
 {
    position: fixed;
 }
</script>";

The submenu is '.dj-subwrap'.

What do I do wrong?

Any tips or help would be greatly appreciated,


Kind regards,

Agent ModDM

7 months 6 days ago #78068

Peter van Westen's Avatar Peter van Westen Admin

The PHP assignment is meant to decide whether or not the module should be placed.
It is not meant for placing code on your page.

Best to just add that script directly in your template. Or use Sourcerer to place it on the page via a 'Custom' module.

7 months 6 days ago #78075

Agent ModDM's Avatar Agent ModDM

The problem is not to add any code on the page. I am able to successfully do that also without your extension, but already with the default functionality of Joomla.
The problem is purely and only that the code is wrong. No other problem.

7 months 6 days ago #78077

Peter van Westen's Avatar Peter van Westen Admin

Again, the PHP assignment field is there to make a return false or true to determine whether the module should be placed on the page.
You can't/should't place echo scripts in there.

If your php/script code is wrong, then I don't see what this has to do with Advanced Module Manager.

7 months 4 days ago #78141

Agent ModDM's Avatar Agent ModDM

Dear Mister Van Westen,

You write "I don't see what this has to do with Advanced Module Manager". Well, I can explain that.

First of all, sorry for wasting your time. I misunderstood the text on this page:
www.regularlabs.com/extensions/advancedm...e-in-the-assignments

saying:

"This gives you the opportunity to assign to just about anything you can think of."

So I thought I will assign the scroll function to anything I can think of. You don't write anything about 'assigning a module', but just 'assigning' (that's why I misunderstood your text).

By the way, the examples and ready-to-use PHP scripts* looked good to me, so I was just (too) enthousiastic.
* www.regularlabs.com/component/content/ar...ent-guide?Itemid=101

Because these examples helped me out seriously in other cases where I applied some ready-to-use PHP scripts from your site. You make good extensions.

With kind regards,

Agent ModDM

7 months 4 days ago #78143

Peter van Westen's Avatar Peter van Westen Admin

Ok, Glad you have it figured out.