Is it possible to set first menu item (with mega menu dropdown) be selected on page load

Permalink Browser Info Environment
Is it possible to set the first menu item (with mega menu dropdown) be selected on page load? I would like the dropdown mega-menu items connected to the first menu item to be displayed, as a default, when the page loads. Can this be done easily?

Type: Discussion
Status: Resolved
Pixelfixer
View Replies:
jb1 replied on at Permalink Reply
jb1
Ok, if I understand you correctly, you want to activate the drop-down menu on a specific item at the time the page loads.

Every menu item (including submenus) have a unique class so they can be easily styled. What you're trying to do could be done with a small line of custom CSS or JS (depending on your preferred approach). The only tricky bit to consider from a usability perspective is how to remove the submenu if the user doesn't want to see it. Since the default method is to show menu items on mouse hover, this could be problematic as the mouse likely starts off the actual menu - and as soon as the user moves their mouse, the default action of hiding the menu (on mouseout) will fire. Instead of you choose to active the menu on a click this will be much easier to create (my recommendation).

In this case, just trigger a "click" even using Javascript.

Here's a screenshot of the demo on my website:http://c5extras.com/add-ons/mega-menu/...
http://snpy.in/BHPUQg
In this case the list item has a CSS class of "pl-219", so it's easy to target the top-level link within it.
li.pl-219 a.top-level-nav


If using jQuery, the code would be:

[code]
$("li.pl-219 a.top-level-nav").click();
[code]

Simply add that HTML code (wrapped by "script" tags) anywhere on the page, and it will trigger the menu on load.

Hope this helps.

JB
Pixelfixer replied on at Permalink Reply
Pixelfixer
JB,
Thanks for the quick reply.
Would it work to put this code in an HTML block on the page?
And, if so, could you reply with a full example of the code using pl-609 as the target class?
I've been experimenting with the options you gave me with no effect, so I must be leaving something out - or it doesn't work within an HTML block?

Thanks!
Steve
jb1 replied on at Permalink Reply
jb1
Sure Steve.
Yes, a HTML block will do the job, just add something like this:

<script>
$("li.pl-609 a.top-level-nav").click();
</script>


This is assuming that jQuery is already part of your theme. If you're not sure, just view the source code of the page and look for anything named jquery.js (or similar) to double check it's being loaded. If it is not, then the above code will produce an error. In that case there is a workaround to use vanilla Javascript, but it's just a bit more verbose.

Hope this helps.

JB
Pixelfixer replied on at Permalink Reply
Pixelfixer
JB,
Thank for your efforts to help me, but this is not yet working for me. This code example is exactly what I tried. I have placed the html block with this code on the page above the stack block that contains the mega-menu with drop-down and alternatively tried it within the stack, at the top.
The first option didn't show any results. The second option did seem to trigger the drop-down, but all the image links were broken, producing 404 errors. I checked the source code for use of *.js files and found them, so I'm guessing this means jquery is loaded and in use, correct?

I also tried installing the css code within style tags in an html block, but that shows no effect. Can you tell me what I might be doing wrong? I'm thinking the css option might be my best option if I can get it to work, just to avoid jquery conflicts. So, could you teach me how to make that work?

Thanks!
Steve
jb1 replied on at Permalink Reply
jb1
Hi Steve,
The code I provided should be placed after the mega menu - otherwise, if it placed before it, then the browser doesn't know about the elements which it is being applied to (since they haven't loaded yet). It also needs to go after the jQuery initialization (because they won't exist yet if the custom code is placed too early).

I can't see how that line of code would affect image links - that seems like it would be something else. Or perhaps if there is a Javascript error and the images are using a JS-based lazy-loading plugin, that could be the cause.

The only issue with a CSS solution is that it would be hard to effectively hide the menu without interfering with "normal" mega menu behaviour.

If you can provide a link where you've added your code I can take 1 more closer look. However, since what you're trying to do is a customisation (outside normal behaviour for the add-on), typically this would fall into my custom programming service which is US$90/hr (min 15 minutes). If I can give you a quick fix, I will, but I do have to draw the line somewhere as I'm sure you can understand.
Pixelfixer replied on at Permalink Reply
Pixelfixer
Hi JB,
Sorry for my late reply to your last reply. My main computer went down over a week ago and I'm just getting back to normal with a replacement.

Anyway, thanks for all the advice, and I understand this situation is worthy of payment for your services. I'm not having much luck and I'm happy to compensate you for your help. I'll PM you my login info. Please take a look at it and see if you can find a quick fix.

Thanks!!

concrete5 Environment Information

# concrete5 Version
Core Version - 8.5.2
Version Installed - 8.5.2
Database Version - 20190925072210

# Database Information
Version: 10.2.32-MariaDB-log
SQL Mode: NO_ENGINE_SUBSTITUTION

# concrete5 Packages
Community Store (2.2.7), Formidable (Full Version) (2.1.3), Grand Gallery (1.3.2), Mega Menu (1.6.5), Seren (1.0.6)

# concrete5 Overrides
blocks/express_entry_detail/templates/mini_truck_group_list.php, blocks/express_entry_detail/templates, blocks/express_entry_detail

# concrete5 Cache Settings
Block Cache - Off
Overrides Cache - Off
Full Page Caching - Off
Full Page Cache Lifetime - Every 6 hours (default setting).

# Server Software
Apache

# Server API
cgi-fcgi

# PHP Version
7.2.32

# PHP Extensions
bcmath, bz2, calendar, cgi-fcgi, Core, ctype, curl, date, dba, dom, enchant, exif, fileinfo, filter, ftp, gd, gettext, gmp, hash, iconv, imap, intl, ionCube Loader, json, ldap, libxml, mbstring, monarxprotect, mysqli, mysqlnd, odbc, openssl, pcntl, pcre, PDO, pdo_mysql, PDO_ODBC, pdo_pgsql, pdo_sqlite, pgsql, Phar, posix, pspell, readline, Reflection, session, SimpleXML, snmp, soap, sockets, SPL, sqlite3, standard, tidy, tokenizer, wddx, xml, xmlreader, xmlrpc, xmlwriter, xsl, zip, zlib

# PHP Settings
max_execution_time - 30
log_errors_max_len - 1024
max_file_uploads - 20
max_input_nesting_level - 64
max_input_time - 60
max_input_vars - 6200
memory_limit - 768M
post_max_size - 512M
upload_max_filesize - 512M
ic24.api.max_timeout - 7
ldap.max_links - Unlimited
mysqli.max_links - Unlimited
mysqli.max_persistent - Unlimited
odbc.max_links - Unlimited
odbc.max_persistent - Unlimited
pcre.backtrack_limit - 1000000
pcre.recursion_limit - 100000
pgsql.max_links - Unlimited
pgsql.max_persistent - Unlimited
session.cache_limiter - <i>no value</i>
session.gc_maxlifetime - 7200
soap.wsdl_cache_limit - 5

Browser User-Agent String

Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/85.0.4183.83 Safari/537.36

Hide Post Content

This will replace the post content with the message: "Content has been removed by an Administrator"

Hide Content

Request Refund

You may not request a refund that is not currently owned by you.