Found some bugs

GK User
Thu May 14, 2015 10:41 pm
Hi, first of all, I was trying to get some anchored links in a menu but didn't worked, because I wanted to link that menu to an specifica article, and because a code in file gk.script.js, it prevented the anchor to work only if the article id displayed, so no redirection was made at all.I have added a closure at line 30 to add an else statement and perform the redirect.

Code: Select all
              if(this.hash !== '' && this.href.replace(this.hash, '') == window.location.href.replace(window.location.hash, '')) {
                  var target = jQuery(this.hash);
                  if(target.length && this.hash !== '#') {
                      jQuery('html, body').stop().animate({
                          'scrollTop': target.offset().top
                      }, 1000, 'swing', function () {
                          if(this.hash !== '#') {
                              window.location.hash = target.selector;
                          }
                      });
                  }
                        //Added this to redirect if no smooth scroll needed
              } else {
                 window.location.href = this.href;
              }


Another issue I have found, is that if I get an anchor in a link, the linked tag gets beneath the main menu row!

How can I fix this?

Thanks!
User avatar
Expert Boarder

GK User
Thu May 14, 2015 11:08 pm
Well, I think I have found a temporary workaround, I would really like Gavick devs to check it out and to come to a real fix...

Code: Select all
   page_loaded = true;
    if(jQuery(document.body).attr('data-smoothscroll') == '1') {

//Must duplicate this chunk of code because redirected anchored URL didn' got the offset increased...
if(window.location.hash !== '') {
            var target = jQuery(window.location.hash);
            if(target.length && window.location.hash !== '#') {
                jQuery('html, body').stop().animate({
                    'scrollTop': target.offset().top - 130
                }, 1000, 'swing', function () {
                    /*if(this.hash !== '#') {
                        window.location.hash = target.selector;
                    }*/
                });
            }
        }
       
      // smooth anchor scrolling
      jQuery('a[href*="#"]').on('click', function (e) {
          e.preventDefault();
          if(this.hash !== '') {
              if(this.hash !== '' && this.href.replace(this.hash, '') == window.location.href.replace(window.location.hash, '')) {
                  var target = jQuery(this.hash);
                  if(target.length && this.hash !== '#') {
                      jQuery('html, body').stop().animate({
                          'scrollTop': target.offset().top - 130 //Must get an increased offset because we have a really nice top menu that is allways visible!
                      }, 1000, 'swing', function () {
                                    //If this portion gets executed, then the offset above gets overriden and the issue persists
                          /*if(this.hash !== '#') {
                              window.location.hash = target.selector;
                          }*/
                      });
                  }
                        // Redirect to anchored URL if not already loaded
              } else {
                 window.location.href = this.href;
              }
          }
      });
User avatar
Expert Boarder

teitbite
Sun May 17, 2015 11:56 am
Hi

I'm afraid I do not understand. This function is for smooth scrolling only so can You please explain what problems it makes and how would You like to have it ? This function links to an element by it's ID, such as for example #bottom
User avatar
Moderator

GK User
Sun May 17, 2015 2:26 pm
Hi, pelase read the comments of my proposed cose.

Basically the issue is that cde prevents anchored links to load if the page loaded is other than the anchored article, for example in my site I have a terms of service article which haves all titles anchored to easily access each section of the article. If I create a set of anchored links in a module, they work only if the article is loaded. If you try to get the anchored links to work from another page, they don't, that's because I have added the else statement.

That else solves the redirect issue, but there is still one more issue to solve, when you get redirected to the anchored link, the main menu bar blocks the achroted title. That's because there is no offset to display anchored title above the main menu bar.

You can take a look of how it works after my fix here. http://www.mgscreativa.com check the bottom links of terms of service...
User avatar
Expert Boarder

GK User
Thu May 21, 2015 12:36 am
Hi @teitbite, did you got the idea of my fix?
User avatar
Expert Boarder

teitbite
Sat May 23, 2015 6:18 pm
Hi

Sorry, but I do not see any links. I still having problems to understand, but I think You are using a standard anchors, like for example <a href="#name"></a> and <a name="name"></a>. While our template has one already implemented. You just need to use and id="" instead of name=""

Example:

<a href="#name"></a> and <div id="name"></div>

if You want a link working from a different page use full url like: html://www.domain.com/#name
User avatar
Moderator

GK User
Sun May 24, 2015 11:13 pm
The anchored text is here http://www.mgscreativa.com/en/terms-of-service each h3 tag has an ID. At the very bottom of the page, you will see a menu called "Our policies" which is a set of anchored links pointing to TOS page IE: http://mgscreativa.com/en/terms-of-serv ... -statement.

The issue I'm rising here is that originally the template prevents that link to work if the current page is for example the home page. Originally, if I'm visiting the anchored text page (http://www.mgscreativa.com/en/terms-of-service) the bottom links work and smoothly dive me to the correct anchored h3 tag, but if I'm at the home page http://mgscreativa.com/en/ the bottom links doesn't work.

That's because the code on gk.script.js has to have a little rework, first the else statement to get redirected links from other pages to the anchored page, and second the copy/paste code to have an offset to be able to see the anchored text.

Do you get the idea of the issue now?
User avatar
Expert Boarder

GK User
Wed May 27, 2015 10:04 am
Hi razor7
I had the same issue but your workaround works fine :) But I seem to to have some issues with Firefox still. Did you experience problems with Firefox too? In my case FF goes to top of the page and don't scroll down to the correct anchor.
User avatar
Fresh Boarder

GK User
Wed May 27, 2015 12:41 pm
Hi @krull!, My fix works ok with FF 38, on Ubuntu Linux, just in case, I have attached my version of gk.scripts.js

This script fix anchored links issues and scroll to be able to see anchored referred tags if the referring page is other than the anchored tags one.

gk.scripts.js.zip
User avatar
Expert Boarder

GK User
Wed May 27, 2015 12:45 pm
Great thanks :cheer:
User avatar
Fresh Boarder

teitbite
Sat May 30, 2015 1:24 pm
Hi

@razor7 thank You very much for help in this matter.

I think we can close this thread now.
User avatar
Moderator


cron