ElkArte Community

Extending Elk => Addons => Topic started by: Dynamo on January 11, 2017, 07:50:40 pm

Title: Dynamic load pages [JS Snipet]
Post by: Dynamo on January 11, 2017, 07:50:40 pm
This is not actually an addon but I didn't know where to post it.

This JavaScript code will dynamically load and display the contents when changing pages.
Here is a quick demo: https://i.imgur.com/hj9Oet3.gifv

Code:
Spoiler (click to show/hide)

Just edit your script_elk.js and insert this code.

Changelog:
Spoiler (click to show/hide)
Title: Re: Dynamic load pages [JS Snipet]
Post by: Spuds on January 11, 2017, 08:45:33 pm
Nice!
Title: Re: Dynamic load pages [JS Snipet]
Post by: badmonkey on January 12, 2017, 09:01:14 am
Very cool!  It would be nice if all forum navigation behaved in a similar fashion so ya don't always feel like it's a complete page load.
Title: Re: Dynamic load pages [JS Snipet]
Post by: inter on January 12, 2017, 10:55:06 am
Cool!  8)

More need to add the page load as you scroll.

@ahrasis what do you think?
Title: Re: Dynamic load pages [JS Snipet]
Post by: emanuele on January 12, 2017, 12:42:27 pm
Cool!

One thing: are the scripts in the page still working? (For example the likes and the quick edit.)
Title: Re: Dynamic load pages [JS Snipet]
Post by: Dynamo on January 12, 2017, 01:48:53 pm
Quote from: emanuele – Cool!

One thing: are the scripts in the page still working? (For example the likes and the quick edit.)
Yes they do work, I also made an update, so it also works when browsing board topics.

Probably I will make an update so all forum navigation behaves on a similar manner. (suggestion by @badmonkey)
Title: Re: Dynamic load pages [JS Snipet]
Post by: badmonkey on January 12, 2017, 02:00:45 pm
Super wow!  Thanks for sharing this.  Perhaps this should be part of the stock code?   :D
Title: Re: Dynamic load pages [JS Snipet]
Post by: ahrasis on January 16, 2017, 07:07:41 am
I have just seen its demo. Great stuff I'd say. Thanks for sharing it.
Title: Re: Dynamic load pages [JS Snipet]
Post by: shaitan on February 01, 2017, 05:49:26 am
Hello,

My English is very bad, sorry.

I have tried this great modification. Found a problem with latéral Top and Bottom buttons. Sometimes all work fine, bat I don't no why, sometimes the bottom button don't do anything.
Elkarte 1.09

Edit:
Il will remove this mod at the end of the week.
You can try:
Go https://forum.mpdb.tv/index.php/topic,35559.0.html
then go on page 2
Bottom button don't responde.
Title: Re: Dynamic load pages [JS Snipet]
Post by: Frenzie on February 01, 2017, 06:13:24 am
Quote// jQuery hates parsing body content. Surely there is a better way (eg regex)
Unlikely: https://jsperf.com/regex-vs-split/2

I haven't tried this, but I would assume it's incompatible with the way I call my quick quote script https://github.com/Frenzie/elk-quick-quote/blob/da6090639d63ff1b51f67891723a85a28eab012e/quickQuote.js#L384

Off the top of my head I'm thinking something like
Code: [Select]
var dynamicLoadPagesEvent = document.createEvent('Event');
dynamicLoadPagesEvent.initEvent('dynamic-load-pages:load-next', true, true);

document.body.dispatchEvent(dynamicLoadPagesEvent);

Then we should be able to act on it like this:

Code: [Select]
document.body.addEventListener('dynamic-load-pages:load-next', initializeQuickQuote, false);
Title: Re: Dynamic load pages [JS Snipet]
Post by: ahrasis on February 01, 2017, 08:55:19 am
I can only see its working just fine @shaitan. This addon target page changes by numbers or next button, not up and down arrow / button. I do however think it can be extended with some more modification to the original code. If you ask me, I like all button leading to another page or position to use the same effect. Better still, several options of it. But that's just me.
Title: Re: Dynamic load pages [JS Snipet]
Post by: shaitan on February 01, 2017, 12:31:10 pm
Hello Ahrasis,
I will try to explain better the problem I encounter.
The addon work like a charm. Dynamic effect when changing page, that's nice, all is OK.

BUT it broke the latéral button (action=.....#bot). Nothing happpens when I press on it.
If I remove the addon, the button work again well





Title: Re: Dynamic load pages [JS Snipet]
Post by: ahrasis on February 01, 2017, 11:43:07 pm
I did go to the bottom just fine when I clicked bottom arrow button aka #bot. So, that doesn't seem broken to me.
Title: Re: Dynamic load pages [JS Snipet]
Post by: shaitan on February 02, 2017, 03:35:58 am
The bottom arrow button work on some page.

Quote from: shaitan –
You can try:
Go https://forum.mpdb.tv/index.php/topic,35559.0.html
then go on page 2
Bottom arrow button don't work.


Tried with différent Browsers, on Windows, Linux..
Title: Re: Dynamic load pages [JS Snipet]
Post by: Frenzie on February 02, 2017, 04:25:41 am
Where's the bottom arrow button? It works for me if I add #bot to the addressbar manually.
Title: Re: Dynamic load pages [JS Snipet]
Post by: shaitan on February 02, 2017, 04:41:23 am

Here:

(https://static.forum.mpdb.tv/uploadimages/images/1486028423-bot.png)
Title: Re: Dynamic load pages [JS Snipet]
Post by: ahrasis on February 02, 2017, 05:16:28 am
Indeed that was the button I clicked. And it works all over the place. I am using Chrome (Version 55.0.2883.87 m (64-bit)) in Windows 10.
Title: Re: Dynamic load pages [JS Snipet]
Post by: shaitan on February 02, 2017, 05:34:13 am
Do you have tried the two steps ?

1 Going a page, for exemple: https://forum.mpdb.tv/index.php/topic,35424.0.html

The button work fine

2 Clic Page 2

The button is broken (for me and others members who have tried).

That not appairs on every Topics.



It's not important for me. I Tried few mods and I make report.
Title: Re: Dynamic load pages [JS Snipet]
Post by: shaitan on February 02, 2017, 06:02:04 am
Not sure if can help.

(https://static.forum.mpdb.tv/uploadimages/images/1486033261-bottomfail.png)
Title: Re: Dynamic load pages [JS Snipet]
Post by: Frenzie on February 02, 2017, 06:24:57 am
Ah! Unless you hover it looks like it's just a tab thingy. I'd forgotten all about its existence.

Anyway, seems to work for me. I clicked previous and next page a few times, tried up and down arrow a few times, all working. Same if I try clicking a page number specifically. Maybe the key is that I'm not logged in?
Title: Re: Dynamic load pages [JS Snipet]
Post by: shaitan on February 02, 2017, 06:40:13 am
That's right !
I tried juste after read your message. Im disconnect, the bug disappear !

Title: Re: Dynamic load pages [JS Snipet]
Post by: emanuele on February 02, 2017, 05:18:23 pm
The animation is lost probably because of how it is attached to the buttons.
Try changing in theme.js this:
Code: [Select]
	$("a[href=#top]").on("click", function(e) {
e.preventDefault();
$("html,body").animate({scrollTop: 0}, 1200);
});

// Smooth scroll to bottom.
$("a[href=#bot]").on("click", function(e) {
e.preventDefault();

to this:
Code: [Select]
	$(document).on('click', "a[href=#top]", function(e) {
e.preventDefault();
$("html,body").animate({scrollTop: 0}, 1200);
});

// Smooth scroll to bottom.
$(document).on('click', "a[href=#bot]", function(e) {
e.preventDefault();
Title: Re: Dynamic load pages [JS Snipet]
Post by: shaitan on February 02, 2017, 06:45:18 pm
Emanuelle,

In this order:

Code changed, empty cache, empty cache browser, empty my plate nuddle, disconnect, reconnect.

And... IT WORK

Edit, no, Sorry, the problem remain the same.






Title: Re: Dynamic load pages [JS Snipet]
Post by: shaitan on February 03, 2017, 12:07:46 pm
And today all work. Strange !  :o
Solved for me.

Many Thanks Emanuelle and all members who give help for this incredible Forum project.
Elkarte is Fantastic !


Title: Re: Dynamic load pages [JS Snipet]
Post by: emanuele on February 03, 2017, 12:41:04 pm
Probably just the browser cache not refreshed. :)
Title: Re: Dynamic load pages [JS Snipet]
Post by: ahrasis on February 08, 2017, 08:31:10 pm
I pack this in a simple package for easy install and uninstall, put Dynamo as its author and name it as Dynamic Page Load (with hope in the future the author will cover all page load :D ) This package involve adding the code to the end of the mentioned file.[1]
I didn't make as a hook package as I've never successfully load this javacript as a file. As instructed by the author, it is to be added inside elk js file, which may be intended to overwrite default js. I really don't know.
Title: Re: Dynamic load pages [JS Snipet]
Post by: ahrasis on February 08, 2017, 09:06:19 pm
I think I somehow managed to make it work fully hook. I attached the new package. If this working with you too, in the future update, just insert the new code into Dynamo.js in default theme scripts Dynamo folder.
Title: Re: Dynamic load pages [JS Snipet]
Post by: ahrasis on August 27, 2017, 07:53:46 am
I wish all my elkarte pages to load using this style instead of just in message display page. I am not good in js / jquery etc, so can somebody help me on how to implement this?
Title: Re: Dynamic load pages [JS Snipet]
Post by: emanuele on August 27, 2017, 01:10:58 pm
All the pages may be a little tricky because of several reasons (even only because different pages may require different javascript files to be loaded).
Title: Re: Dynamic load pages [JS Snipet]
Post by: ahrasis on August 27, 2017, 10:46:28 pm
I noted that it is tricky.

Should I start looking for each page code and where?

Or can it be done in such a way that all internal url is load with the same loading effect? I mean the code can look for it instead of various ids or classes, right?