• Hello.
    In the wpadverts plugin on the categories page I wanted to make a drop-down menu in javascript, put the classes, but the code didn’t work. Maybe I put the classes wrong or the code was written with errors? I found the code on the Internet. Can you help me?

    Classes used such !

    adverts-categories-all
    adverts-flexbox-wrap
    adverts-flexbox-list

    document.getElementById('adverts-categories-all').onclick = function(event) {
        var target = event.target;
    	if (target.className == 'adverts-flexbox-wrap') {
    	    var s = target.getElementsByClassName('adverts-flexbox-list');
    		closeMenu();
    		s[0].style.display='block';
          }
    }
    document.onclick=function(event) {
        var target = event.target;
    	console.log(event.target);
    	if (target.className!='adverts-flexbox-wrap' && target.className!='adverts-flexbox-list'){
    	    closeMenu();
    	}
    }
    function closeMenu() {
        var menu = document.getElementById('adverts-categories-all');
    	var subm=document.getElementsByClassName('adverts-flexbox-list');
    	for (var i=0; i <subm.length; i++) {
    	    subm[i].style.display="none";
    	}
    }

    Thanks you !

Viewing 12 replies - 1 through 12 (of 12 total)
  • Moderator James Huff

    (@macmanx)

    Hi there @zonepluss I see you reported this thread to the moderators. Please note that we are just the folks who enforce the rules around all of www.ads-software.com.

    Reporting to moderators doesn’t get any faster support, instead it just kind of attracts attention from folks whose radar you probably don’t want to be on. ??

    If you really do need a moderator, please add a reply letting us know why before you hit the report button.

    Otherwise, please hang in there for the plugin’s support to reply when they can.

    Thread Starter zonepluss

    (@zonepluss)

    I clicked on the report link by accident, sorry!

    Plugin Author Greg Winiarski

    (@gwin)

    Hi,
    hmm can you paste a link to a page where you are using this code so i can take a look at it on-line?

    Thread Starter zonepluss

    (@zonepluss)

    https://nedia.eu/katalog-obyavleniy/
    Now i’m using CSS to hide subcategories, it works well, but i want to try to display subcategories by clicking, not by hover.

    Plugin Author Greg Winiarski

    (@gwin)

    With JavaScript and jQuery you should be able to show the sub-items on click by adding the below code in your theme functions.php file

    
    add_action( "wp_footer", function() {
        ?>
        <script type="text/javascript">
        jQuery(function($) {
            $(".adverts-flexbox-wrap").on("click", function(e) {
                e.preventDefault();
                var x = this;
                $(this).find(".adverts-flexbox-list").toggle();
            });
            $(".adverts-flexbox-list").hide();
        });
        </script>
        <?php
    });
    
    Thread Starter zonepluss

    (@zonepluss)

    Thanks a lot, Greg!
    If i want to add some link or simple text like “show all” to the flexbox, below the main category, that users can click on this text and then subcategories dropdown, i need create this with js or theme html before?
    Regards

    Plugin Author Greg Winiarski

    (@gwin)

    I would recommend creating it with JavaScript since there is already a part of the code available above, plus the changes in the templates could be overwritten on WPAdverts update.

    Thread Starter zonepluss

    (@zonepluss)

    Sorry,but could you help us?

    It’s currently not possible to select a category and subcategory, that is, they are not active.
    With this code, we can only open and close a category.

    Thanks you !

    Plugin Author Greg Winiarski

    (@gwin)

    Please try replacing the code from previous message with the one below

    
    add_action( "wp_footer", function() {
        ?>
        <script type="text/javascript">
        jQuery(function($) {
            $(".adverts-flexbox-wrap").on("click", function(e) {
                e.preventDefault();
                var x = this;
                $(this).find(".adverts-flexbox-list").toggle();
            });
            $(".adverts-flexbox-list a").on("click", function(e) {
                $(".adverts-flexbox-wrap").unbind("click");
            });
            $(".adverts-flexbox-list").hide();
        });
        </script>
        <?php
    });
    
    Thread Starter zonepluss

    (@zonepluss)

    Thank You so much Greg, work perfectly!!!
    Last question, how can i add small buttons or text like SHOW and HIDE, that user could press SHOW button to see subcategories and then press HIDE to close subcategories.
    Regards!

    Plugin Author Greg Winiarski

    (@gwin)

    This would require even more custom programming, this is beyond the support offered here, sorry.

    Thread Starter zonepluss

    (@zonepluss)

    Ok, thanks, Greg!

Viewing 12 replies - 1 through 12 (of 12 total)
  • The topic ‘Dropdown menu’ is closed to new replies.