Skip to content
  • Recent
  • Tags
  • Popular
  • Users
  • Search
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse

Lay Theme Forum

  1. Home
  2. General Discussion
  3. Site-specific Javascript

Site-specific Javascript

Scheduled Pinned Locked Moved General Discussion
15 Posts 4 Posters 397 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • L Offline
    L Offline
    lars
    wrote on Jun 29, 2020, 11:46 AM last edited by
    #1

    Hello,

    I have a question regarding javascript that I only want to run on a specific page.

    I have a one-pager and a separate legal notice and privacy page.

    For the one-pager I added the following script to make the mobile site title a scroll-to-top button

    <script>
    window.laytheme.on("newpageshown", function(layoutObj, type, obj){
    	if(type == "page" && obj.id == 86){
    	    jQuery('.mobile-title').addClass('scrolltotop');
    	}
    });
    </script>
    

    This works fine. However I need the site title on legal notice and privacy to act as usual and redirect me to the home page.

    Unfortunately the included if statement with the corresponding page id of the home page doesn’t work as I hoped. The scroll-to-top javascript still works on all pages.

    A second script to remove the scrolltotop class again only fires if you go to the legal notice and privacy pages via the direct url.

    1 Reply Last reply
    0
    • M Offline
      M Offline
      mariusjopen
      Global Moderator
      wrote on Jun 30, 2020, 12:37 PM last edited by
      #2

      Dear @lars
      Can you post a link to your website?
      We will then have a look and inspect that!
      Many wishes!
      Marius

      www.mariusjopen.world

      1 Reply Last reply
      0
      • L Offline
        L Offline
        lars
        wrote on Jul 9, 2020, 9:30 AM last edited by
        #3

        Hi @mariusjopen

        Here is the website:
        https://strategis.de

        And as I mentioned it only applies to the mobile version.

        The pages „legal notice/Impressum“ and „privacy/Datenschutz“ can be found inside the burger menu.

        Best
        Lars

        1 Reply Last reply
        0
        • M Offline
          M Offline
          mariusjopen
          Global Moderator
          wrote on Jul 10, 2020, 10:05 AM last edited by
          #4

          Dear @lars

          does this simple example work?

          <script>
          window.laytheme.on("newpageshown", function(layoutObj, type, obj){
          	if(type == "project" && obj.id == 1){
          		console.log("fantastic!");
          	}
          });
          </script>
          

          Do you get a console log?

          Best!
          Marius

          www.mariusjopen.world

          1 Reply Last reply
          0
          • L Offline
            L Offline
            lars
            wrote on Jul 18, 2020, 1:03 PM last edited by
            #5

            Dear @mariusjopen

            I added the script in the custom head section.

            When I visit the project site by entering the URL or coming from the WP backend I get the console log.

            However if I set a link to this project on another page of my website and click on it, the log is not showing up.

            It seems as if the site needs to be reloaded entirely before the script fires.

            1 Reply Last reply
            0
            • R Offline
              R Offline
              Richard
              Global Moderator
              wrote on Jul 23, 2020, 5:35 PM last edited by
              #6

              Dear @lars

              Thank you for your patience, forgive me for the late reply

              I will forward this To Armin so we can take a better look

              Thank you for using Lay Theme

              Sincerely
              Rich

              1 Reply Last reply
              0
              • arminunruhA Offline
                arminunruhA Offline
                arminunruh
                Global Moderator
                wrote on Jul 24, 2020, 3:54 PM last edited by arminunruh Jul 24, 2020, 11:54 AM
                #7

                Ok lol
                I re-read ur text and I think there's probably nothing wrong with the detection of the correct page.
                However, of course u need to remove your functionality on the other pages so I think ur code/ur logic is wrong.

                U should do:

                <script>
                window.laytheme.on("newpageshown", function(layoutObj, type, obj){
                	if(type == "page" && obj.id == 86){
                	    jQuery('.mobile-title').addClass('scrolltotop');
                	}else{
                           jQuery('.mobile-title').removeClass('scrolltotop');
                        }
                });
                </script>
                
                1 Reply Last reply
                0
                • L Offline
                  L Offline
                  lars
                  wrote on Jul 28, 2020, 11:33 AM last edited by
                  #8

                  Dear @arminunruh

                  thanks that totally makes sense! I replaced the script on the site and it works.

                  I checked it with the web inspector and the class .scrolltotop is getting added and removed accordingly.

                  However the same behaviour as stated in the first post still exists.

                  If you go to https://strategis.de/impressum/ directly, or reload the page, the logo links back to home. If you however go from the home page to the site (via the burger menu) the logo still acts as a scroll to top button.

                  1 Reply Last reply
                  0
                  • L Offline
                    L Offline
                    lars
                    wrote on Jul 29, 2020, 2:10 PM last edited by
                    #9

                    Okay another observation:

                    Today I added a new page „Kontakt“ and put it in the mobile menu like Impressum and Datenschutz beforehand.

                    For whatever reason the script works as intended when going from the main page to the „Kontakt“ page through the burger menu and vice versa. On „kontakt“ the logo is linking back to the main page.

                    Also see the difference in the transition between clicking on „Impressum“, „Datenschutz“ or „Kontakt“. The click on „Kontakt“ seems to trigger a reload whereas the other two just chance the displayed content.

                    Any chance to replicate this behaviour to the other menu points?

                    1 Reply Last reply
                    0
                    • R Offline
                      R Offline
                      Richard
                      Global Moderator
                      wrote on Aug 6, 2020, 3:03 PM last edited by
                      #10

                      Dear @lars

                      Checking in :)

                      Did you find a solution to your problem or does the issue still persist!

                      Best wishes and have a great day

                      Sicnerely
                      Richard

                      1 Reply Last reply
                      0
                      • L Offline
                        L Offline
                        lars
                        wrote on Aug 10, 2020, 9:02 AM last edited by
                        #11

                        Dear @Richard-Keith

                        thanks for checking in.
                        Unfortunately I haven’t found a solution yet.

                        Like I stated in my post 12 days ago about the „Kontakt“ the script works fine as long as the page is properly (re)loaded in the browser. But it is not working when a transition from one page to another is invoked.

                        Any way to tell the Laytheme Single Page JavaScript application to not transition but instead to reload a new page?

                        1 Reply Last reply
                        0
                        • R Offline
                          R Offline
                          Richard
                          Global Moderator
                          wrote on Aug 19, 2020, 3:41 PM last edited by Richard Aug 19, 2020, 12:14 PM
                          #12

                          Dear @lars

                          Apologies that you haven't found a solution,
                          I will forward this straight away so we can find one faster :)

                          In the meantime if you could please send your website address, /wp-admin/ username and password and a link to this topic to info@laytheme.com? to speed up the process.

                          Hope you have a wonderful day and thank you for being a part of the Community.

                          Best wishes
                          Richard

                          1 Reply Last reply
                          0
                          • arminunruhA Offline
                            arminunruhA Offline
                            arminunruh
                            Global Moderator
                            wrote on Aug 19, 2020, 4:58 PM last edited by
                            #13

                            Any way to tell the Laytheme Single Page JavaScript application to not transition but instead to reload a new page?

                            Hey @lars apologies for not getting back to you earlier. My support coworker is new and just started out.
                            Yes you can make lay theme reload on every page load.
                            Go to Lay Options and at the bottom activate "Disable Ajax / Compatibility Mode"

                            1 Reply Last reply
                            0
                            • L Offline
                              L Offline
                              lars
                              wrote on Sep 1, 2020, 3:42 PM last edited by
                              #14

                              Hey @arminunruh no problem!

                              Your suggestions finally did the trick.
                              The script is working as intended.

                              Thank you very much.

                              Best
                              Lars

                              1 Reply Last reply
                              0
                              • RichardR Offline
                                RichardR Offline
                                Richard
                                Global Moderator
                                wrote on Sep 3, 2020, 4:12 PM last edited by
                                #15

                                Dear @lars

                                Thanks for Getting back and confirming your success,

                                Best Wishes & Thank you for using Lay Theme!
                                Richard

                                1 Reply Last reply
                                0
                                Reply
                                • Reply as topic
                                Log in to reply
                                • Oldest to Newest
                                • Newest to Oldest
                                • Most Votes


                                I also code custom websites or custom Lay features.
                                💿 Email me here: 💿
                                info@laytheme.com

                                Before you post:
                                1. When using a WordPress Cache plugin, disable it or clear your cache.
                                2. Update Lay Theme and all Lay Theme Addons
                                3. Disable all Plugins
                                4. Go to Lay Options → Custom CSS & HTML, click "Turn Off All Custom Code", click "Save Changes"

                                This often solves issues you might run into

                                When you post:
                                1. Post a link to where the problem is
                                2. Does the problem happen on Chrome, Firefox, Safari or iPhone or Android?
                                3. If the problem is difficult to explain, post screenshots / link to a video to explain it
                                Online Users
                                K
                                kernlose
                                23 minutes ago
                                Forgot your key, lost your files, need a previous Lay Theme or Addon version? Go to www.laykeymanager.com
                                laytheme.com
                                • Login

                                • Don't have an account? Register

                                • Login or register to search.
                                • First post
                                  Last post
                                0
                                • Recent
                                • Tags
                                • Popular
                                • Users
                                • Search