Inserting 3rd party scripts into RSD...

User 371172 Photo


Registered User
35 posts

Firstly - I'm no code guru. I generally keep fiddling with stuff until it works and I've learnt by trial and a lot of error. But I have a problem that is defeating me at the moment:

I have an RSD site that has a long index page navigated by jumping to Ids. I would like to incorporate a floating 'back to top' icon. I have a script (normally inserted in the header), a CSS file and 2 js files. I know they work because I've had it all working in a non RSD site but I can't figure how to get it to work on RSD. I've tried:

Adding a hidden HTML section with the script added as a header. And alternatively I've added the script to the header section on the settings page. I've then loaded the other files via the root directory of the resources, and by uploading them directly to the website. And every combination of the above. But no joy.

I suspect I'm doing something fundamentally wrong but have run out of ideas apart from maybe a floating icon is not compatible with a responsive site.

Any ideas. Cheers JP
JP
Cat herder and Fog platter.
User 187934 Photo


Senior Advisor
20,266 posts
Online Now

Hi Jonathan,
Can you share a link to you page?
I can't hear what I'm looking at.
It's easy to overlook something you're not looking for.

This is a site I built for my work.(RSD)
http://esmansgreenhouse.com
This is a site I built for use in my job.(HTML Editor)
https://pestlogbook.com
This is my personal site used for testing and as an easy way to share photos.(RLM imported to RSD)
https://ericrohloff.com
User 283347 Photo


Registered User
388 posts

I have used this with success...and it is easy to do. You can change the pic and also you can change the .js file so it scrolls to where you want it and/or becomes visible when you want.

http://www.dynamicdrive.com/dynamicindex3/scrolltop.htm
User 271657 Photo


Ambassador
3,816 posts

I suspect I'm doing something fundamentally wrong but have run out of ideas apart from maybe a floating icon is not compatible with a responsive site.

Responsive or not doesn't matter.
But we're just playing a guessing game if we can't see a live page with your link code in place. :(
I love deadlines. I like the whooshing sound they make as they fly by. (Douglas Adams)
https://www.callendales.com
User 2484360 Photo


Registered User
3,293 posts

Hey Jonathan,

Is there a reason you want to use the Javascript? This can easily be done using just a simple Font Icon Link in RSD. I have attached a project that provides a basic example of a "floating" back to top arrow. :)
Attachments:
User 371172 Photo


Registered User
35 posts

Adam

That works ok and I had already done something similar but the javascript allows smooth scrolling (as my nav to ID down the page is smooth scrolling) and it also allows it to become visible after a certain scroll distance distance. With your version it's not quite as slick.

regards JP
JP
Cat herder and Fog platter.
User 2273654 Photo


Registered User
772 posts

Hey Adam, I have been working on my blog; making it responsive, has been difficult, as a diversion I decided to try and implement your suggestion for the arrow link. It installed quickly and easily. Your instructions were excellent. I think that it is slick.
www.workhorsepainting.com
arrow link lower rt side. I added a mouse over color change to identify that it is active.
My CC S-drive site https://workhorsepainting.com
User 473158 Photo


Registered User
17 posts

Hi Jonathan
Put this script in your footer:

<script type="text/javascript">

$(window).load(function() {
function filterPath(string) {
return string
.replace(/^\//,'')
.replace(/(index|default).[a-zA-Z]{3,4}$/,'')
.replace(/\/$/,'');
}
var locationPath = filterPath(location.pathname);
var scrollElem = scrollableElement('html', 'body');

$('a[href*=#]').each(function() {
var thisPath = filterPath(this.pathname) || locationPath;
if ( locationPath == thisPath
&& (location.hostname == this.hostname || !this.hostname)
&& this.hash.replace(/#/,'') ) {
var $target = $(this.hash), target = this.hash;
if (target) {
var targetOffset = $target.offset().top -60;
$(this).click(function(event) {
event.preventDefault();
$(scrollElem).animate({scrollTop: targetOffset}, 700, function() {

});
});
}
}
});

// use the first element that is "scrollable"
function scrollableElement(els) {
for (var i = 0, argLength = arguments.length; i <argLength; i++) {
var el = arguments[i],
$scrollElement = $(el);
if ($scrollElement.scrollTop()> 0) {
return el;
} else {
$scrollElement.scrollTop(1);
var isScrollable = $scrollElement.scrollTop()> 0;
$scrollElement.scrollTop(0);
if (isScrollable) {
return el;
}
}
}
return [];
}

});

</script>

Attachments:
User 473158 Photo


Registered User
17 posts

Please note that the script I just posted has an offset of -60
If you don't want it set it to
$target.offset().top -0;
User 2484360 Photo


Registered User
3,293 posts

GregB wrote:
Hey Adam, I have been working on my blog; making it responsive, has been difficult, as a diversion I decided to try and implement your suggestion for the arrow link. It installed quickly and easily. Your instructions were excellent. I think that it is slick.
www.workhorsepainting.com
arrow link lower rt side. I added a mouse over color change to identify that it is active.


Looks pretty good! :) I would recommend moving it to the left just a little, as the scroll bar sits on top of it in Safari.

Have something to add? We’d love to hear it!
You must have an account to participate. Please Sign In Here, then join the conversation.