Community @ The Turning Gate

Support community for TTG plugins and products.

NOTICE

The Turning Gate's Community has moved to a new home, at https://discourse.theturninggate.net.

This forum is now closed, and exists here as a read-only archive.

  • New user registrations are disabled.
  • Users cannot create new topics.
  • Users cannot reply to existing topics.

You are not logged in.

#1 2019-03-12 02:17:07

mad
Member
From: Arkansas
Registered: 2014-01-03
Posts: 154
Website

Help with Menu Highlighting

Hi the code I am using is below in the scripts plugin file but I keep getting an error when I implement; I think it is correct but my eyes could be deceiving me. I need a second pair of eyes to see what I am not seeing. 

    echo '
            <style type="text/css">
                .selected
                {
                    background-color: red !important;
                    color: black !important;
                }
            </style>
           <script>
                $(function()
                {
                    $("ul.menu a[href='" + window.location.pathname + "']")
                        .parentsUntil(".menu", "li")
                        .addClass("selected");
                });       
            </script>
        ';   
Here is the error I am getting when I run this:
Something went wrong

Unexpected error: syntax error, unexpected '" + window.location.pathname +' (T_CONSTANT_ENCAPSED_STRING), expecting ',' or ';' in kp-plugins.php on line 371

Please report error at http://community.theturninggate.net

Also, I would like to add the effect to also be on the both the parent & children and I think this should work but let me know this as well.
                    $("ul.menu a[href='" + window.location.pathname + "']")
                        .parentsUntil(".menu", "li")
                        .addClass("selected").parents("li").children("a").addClass("selected");

Offline

#2 2019-03-12 02:35:22

rod barbee
Moderator
From: Port Ludlow, WA USA
Registered: 2012-09-24
Posts: 17,830
Website

Re: Help with Menu Highlighting

it's the single quotes in that line.
If you use the sample script in the phplugins-pangolin-sample.php file you won't need to escape those single quotes.

It's this one:

function scripts() { 
echo <<<SCRIPT
	<script>
	$("ul.menu a[href='" + window.location.pathname + "']")
		.parentsUntil('.menu', 'li')
		.addClass("current_page_item")
		;
	</script>
SCRIPT;
	return false;
} // END /**/

otherwise, escape the single quotes:

<script>
           $(function() {
                 $("ul.menu a[href=\'" + window.location.pathname + "\']")
                  .parentsUntil(".menu", "li")
                  .addClass("selected");
             });       
</script>

Rod 
Just a user with way too much time on his hands.
www.rodbarbee.com
ttg-tips.com, Backlight 2/3 test site

Offline

#3 2019-03-12 02:43:27

mad
Member
From: Arkansas
Registered: 2014-01-03
Posts: 154
Website

Re: Help with Menu Highlighting

I tried the one in the sample script but it also gives me the same error. I will try the escape char.  What about the item I have for the children and parent to both be highlighted?  Will it work as well or did I miss something?

Offline

#4 2019-03-12 02:44:55

rod barbee
Moderator
From: Port Ludlow, WA USA
Registered: 2012-09-24
Posts: 17,830
Website

Re: Help with Menu Highlighting

I don't know about the second item. I've not played around with that.


Rod 
Just a user with way too much time on his hands.
www.rodbarbee.com
ttg-tips.com, Backlight 2/3 test site

Offline

#5 2019-03-12 02:45:47

mad
Member
From: Arkansas
Registered: 2014-01-03
Posts: 154
Website

Re: Help with Menu Highlighting

ok thanks, I will play around with it.

Offline

#6 2019-03-12 02:57:21

rod barbee
Moderator
From: Port Ludlow, WA USA
Registered: 2012-09-24
Posts: 17,830
Website

Re: Help with Menu Highlighting

I just tested the sample script provided. It worked for me without error.


Rod 
Just a user with way too much time on his hands.
www.rodbarbee.com
ttg-tips.com, Backlight 2/3 test site

Offline

#7 2019-03-12 03:00:01

mad
Member
From: Arkansas
Registered: 2014-01-03
Posts: 154
Website

Re: Help with Menu Highlighting

Well it did not work for me until I used it on the sample script with the escape.  Also, the children code that I posted I had works as well.  But, it did not highlight everything I am looking at why some menu items did not get highlighted when selected.  I think it is because of the window location pathname.

Last edited by mad (2019-03-12 03:01:56)

Offline

Board footer

Powered by FluxBB