Tagged: javascript, url
-
AuthorPosts
-
November 13, 2014 at 2:26 pm #350651
Hi,
I use the theme as Onesite with sections. But context is an issue.
While I scroll I like to store/add the current section as Hash to the URL.
Than I could reload or share the URL and end-up at the right site position.I found the in the file avia.js the prototype function AviaScrollSpy. But I don’t fully get it … there are no getter and setter for this function to use it like that, right? At the process function, there is this.activeTarget which contains the current section Hash. Is there any way to call this separately? Than it would only be a 5-Liner to add the Hash to the URL and the Language Switch for eg. Than I would only need a simple “scroll to Anker if URL contains #” to make it sexy, done.
If that is not possible jet, I would like to request this feature :)
Greez Jens
November 13, 2014 at 4:53 pm #350721Right now I changed the avia.js file, but this sucks for updates.
At line 205 I’ve added one line “setHash(this.activeTarget);”, process: function () { if(!this.offsets) return; var scrollTop = this.$scrollElement.scrollTop() + this.options.offset , scrollHeight = this.$scrollElement[0].scrollHeight || this.$body[0].scrollHeight , maxScroll = scrollHeight - this.$scrollElement.height() , offsets = this.offsets , targets = this.targets , activeTarget = this.activeTarget , i setHash(this.activeTarget);
And than I’ve put the rest into a new JS file.
var currentHash = ""; var langObjs = jQuery("ul.avia_wpml_language_switch a"); function setHash(hashString) { if (hashString === undefined) return; if (hashString !== currentHash) { window.location.hash = hashString; setLangHash( hashString ); currentHash = hashString; history.pushState(null, null, hashString); } } function setLangHash(hashString) { langObjs.each(function() { var curObj = jQuery(this); var hrefStr = curObj.attr('href'); var hrefWithoutHash = (hrefStr.indexOf('#') < 0) ? hrefStr : hrefStr.substr(0, hrefStr.indexOf('#')); var newHref = hrefWithoutHash + hashString; curObj.attr('href', newHref); }); }
I works ok, code is bit dirty and quick done.
What would you suggest to avoid the call inside of avia.js?- This reply was modified 10 years ago by Jens.
November 13, 2014 at 6:18 pm #350829Sadly it creates massiv performance issues under Safari.
Any suggestions?November 13, 2014 at 7:39 pm #350865Found a simple solution :)
Placed the call into the activate function at line 224., activate: function (target) { var active , selector this.activeTarget = target setHash(this.activeTarget);
November 13, 2014 at 7:44 pm #350868But still, how to avoid the call inside of the avia.js file?
How can I call the thing from outside? Are there any get-/setter? Or is there
any other way to avoid that?November 14, 2014 at 4:45 am #351109Hi!
Thank you for using Enfold.
Glad you figured it out. You can unregister the default avia.js file then enqueue it again from the child theme folder. Add this on functions.php:
/* * Register frontend javascripts: */ if(!is_admin()) { add_action('wp_enqueue_scripts', 'avia_register_child_frontend_scripts', 100); } function avia_register_child_frontend_scripts() { $child_theme_url = get_stylesheet_directory_uri(); //register js wp_register_script( 'avia-default-child', $child_theme_url.'/js/avia.js', array('jquery'), 1, false ); wp_enqueue_script( 'avia-default-child' ); }
Create a js folder inside the child theme.
Best regards,
IsmaelNovember 15, 2014 at 1:26 am #351641First of all, thanks for you quick answer. :)
But, is there no better way, than coping the whole file?
This is a bit radical and somehow not really helpful in
terms of Update-Compatibility. Don’t get me wrong,
please. Now there is not only 1 line that could fail.
now there would be a whole file that could get in-
compatible. :) I guess it’s easier to stick to that 1 line.I seek for a “external” JavaScript solution. There must
be a way to interact with the JS function object. To get
the value or to attach an event handler to it, to get the
changed value, if something changes .. or so.Who wrote those lines inside of “avia.js” ? :)
Greez Jens
November 16, 2014 at 3:47 pm #352022Hi!
Kriesi wrote it. I’m sorry but this modification is beyond the scope of support. You can hire a freelance developer to figure this out. For further modifications, please visit Envato Studio or Werkpress. Anyway, I’ll ask Kriesi to take a look.
Regards,
IsmaelNovember 16, 2014 at 10:51 pm #352188Hi,
thanks. I will find my way through.
Greez Jens
-
AuthorPosts
- The topic ‘I seek for: Get Scroll-Pos, Set URL Hash (maybe feature request)’ is closed to new replies.