Search…

X3 Photo Gallery Support Forums

Search…
 
User avatar
Martin
Experienced
Topic Author
Posts: 641
Joined: 30 Jan 2011, 23:24

Sorting & Limit Amount

21 May 2016, 14:36

I noticed that when the Gallery has these settings:

Sort Images by shuffle
and
Limit Amount set to something other than zero (but less than the total amount of images in that gallery)

the process is that at first a selection of images is made and afterwards the shuffle takes place.

Could this be the other way around?
If so, it will be possible to select a few random images from a larger set.
ImageImage
 
User avatar
mjau-mjau
X3 Wizard
Posts: 12195
Joined: 30 Sep 2006, 03:37

Re: Sorting & Limit Amount

22 May 2016, 01:48

That's an interesting, and correct observation. Let me explain:

Unlike all other sorting methods, the shuffle sort is handled by the javascript in the frontend. Why? Because if we shuffle from the backend (which can easily be done), images would get shuffled, but then that initial output will get stored in your X3 page cache. Thus, consecutive visits to the same page will result in "hey, it's not shuffling the images", and therefore this is handled by javascript.

So ... What is happening here, is that X3 backend is outputting first images within the limit range, caching the page output, and the javascript frontend is shuffling those images. Even if we ALSO shuffled from X3 backend, the specific images picked in the shuffle would persist in the page cache.

To achieve what you ask, we would therefore need to shuffle the images on the server script (instead of javascript), before it limits the output. The reason why we can't really offer 'shuffle' from the server, is because this is not compatible with page-caching. The initial output will get cached, so that consecutive visits that load the cached fragment, aren't truly shuffled.

The solution would be to disable page-cache for this specific page. Although it might just take 1 second more to generate the page, that is much slower than cache, which is likely below 0.1 seconds. Simply a poor compromise. It would have to re-process the entire page for all visitors, on each visit.

There is another option, but it would be considered a dirty hack: We could ask the server/php to output ALL images (unbound by limit), and then javascript would do the shuffle AND remove image elements outside the limit setting (after the shuffle is done).

To be honest, none of these options are favorable, so this topic would likely be tagged "technical logical limitation".
 
User avatar
Martin
Experienced
Topic Author
Posts: 641
Joined: 30 Jan 2011, 23:24

Re: Sorting & Limit Amount

22 May 2016, 04:11

mjau-mjau wrote:There is another option, but it would be considered a dirty hack: We could ask the server/php to output ALL images (unbound by limit), and then javascript would do the shuffle AND remove image elements outside the limit setting (after the shuffle is done).
Ah, that's a pity.
I was already afraid of some technical challenges for this one, although it sounded so simple... 'just the other way around'

For me the option above doesn't sound like a dirty hack, just as an extra option to choose from :-)

What I was trying to achieve is a startpage in Justified Gallery layout that only shows 3 random images from an assets folder.
Like the screenprint below, but that one always shows the first 3 images.

Image
ImageImage
 
User avatar
mjau-mjau
X3 Wizard
Posts: 12195
Joined: 30 Sep 2006, 03:37

Re: Sorting & Limit Amount

22 May 2016, 08:42

I see how that could be useful ...

This will have to wait until next major release, as I am currently busy with new website and forum.

If you want, I could provide a javascript hack for you. I would need panel login to work it out ...
 
User avatar
Martin
Experienced
Topic Author
Posts: 641
Joined: 30 Jan 2011, 23:24

Re: Sorting & Limit Amount

22 May 2016, 08:46

Great!
I'll send you a PM
ImageImage
 
User avatar
mjau-mjau
X3 Wizard
Posts: 12195
Joined: 30 Sep 2006, 03:37

Re: Sorting & Limit Amount

22 May 2016, 16:10

http://emptiness.gallery/

Keep in mind, I disabled LIMIT and SHUFFLE from your index gallery settings. Instead, the shuffle happens from the custom script, which then cuts away all but 3 images after the shuffle.
Code
function x3_load_page(){
  if($('body').hasClass('slug-index')){
    var items = $('div.gallery.images > a');
    items.shuffle();
    var remove_items = $('div.gallery.images > a:gt(2)');
    remove_items.remove();
  }
}
 
User avatar
Martin
Experienced
Topic Author
Posts: 641
Joined: 30 Jan 2011, 23:24

Re: Sorting & Limit Amount

22 May 2016, 23:29

Wonderful! Thanks a lot!
This is a great random image generator :-)
ImageImage
 
User avatar
Martin
Experienced
Topic Author
Posts: 641
Joined: 30 Jan 2011, 23:24

Re: Sorting & Limit Amount

11 Sep 2018, 13:37

mjau-mjau wrote: http://emptiness.gallery/

Keep in mind, I disabled LIMIT and SHUFFLE from your index gallery settings. Instead, the shuffle happens from the custom script, which then cuts away all but 3 images after the shuffle.
Code
function x3_load_page(){
  if($('body').hasClass('slug-index')){
    var items = $('div.gallery.images > a');
    items.shuffle();
    var remove_items = $('div.gallery.images > a:gt(2)');
    remove_items.remove();
  }
}
Hi Karl,

Two years ago you helped me with this java-code (website emptiness.gallery).

This code made it possible to show on the index-page only three images from a set of more than twenty images.
So the first time when this site is shown, there are only three random images.
And everytime someone clicks on the logo (from a non-index-page) the index-page is shown with a new site of three images.

But this last event does not work anymore. 
I do not know since when...

Now, when someone clicks on the logo (from a non-index-page), all the images are shown instead of only the random selection of three.
Any idea what the issue could be?

Martin
ImageImage
 
User avatar
mjau-mjau
X3 Wizard
Posts: 12195
Joined: 30 Sep 2006, 03:37

Re: Sorting & Limit Amount

12 Sep 2018, 00:51

Hi George. I can't see that this is not working.
emptiness.gallery

When I visit your home page, it displays THREE random images, out of 22 actually available in the source. This is not how it's supposed to work?
 
User avatar
Martin
Experienced
Topic Author
Posts: 641
Joined: 30 Jan 2011, 23:24

Re: Sorting & Limit Amount

12 Sep 2018, 02:54

mjau-mjau wrote: Hi George. I can't see that this is not working.
emptiness.gallery

When I visit your home page, it displays THREE random images, out of 22 actually available in the source. This is not how it's supposed to work?
Hi Karl,

Yes, it is correct when you visit my home page to see three random images.
However if you are on another page than my home page and click on the logo the home page is shown but not with three random images but with 22 images.

Martin
ImageImage
 
User avatar
mjau-mjau
X3 Wizard
Posts: 12195
Joined: 30 Sep 2006, 03:37

Re: Sorting & Limit Amount

12 Sep 2018, 05:18

There seems to be a bug in assigned body classes, possibly related to siteDB preload. Anyway, the fix is easy. Go to Settings > Custom > Custom Javascript, and edit the custom code from:
Code
if($('body').hasClass('slug-index')){
to:
Code
if($('body').hasClass('page-index')){
 
User avatar
Martin
Experienced
Topic Author
Posts: 641
Joined: 30 Jan 2011, 23:24

Re: Sorting & Limit Amount

12 Sep 2018, 06:25

Yes, that did it!
Thnx!
ImageImage
 
User avatar
Martin
Experienced
Topic Author
Posts: 641
Joined: 30 Jan 2011, 23:24

Re: Sorting & Limit Amount

29 Mar 2019, 05:42

mjau-mjau wrote: http://emptiness.gallery/
Code
function x3_load_page(){
 if($('body').hasClass('page-index')){
   var items = $('div.gallery.images > a');
   items.shuffle();
   var remove_items = $('div.gallery.images > a:gt(2)');
   remove_items.remove();
 }
}
Hi Karl,

This thread involves an adaptation you specially made for my site http://emptiness.gallery/
When the above function is added to the custom java scripts, the Home Page shows only three random images from a selection of more.

Some six month ago after an upgrade, the function didn't work anymore as expected.
You made a change in the script:
Code
hasClass('slug-index')
became:
Code
hasClass('page-index')
Yesterday I upgraded from X3.26.0 to X3.27.6 
After this upgrade the function mentioned above also doesn't work anymore.
You can see what is wrong when you open the site below, which is an exact copy of http://emptiness.gallery
=>  http://mind.voyage
ImageImage
 
User avatar
mjau-mjau
X3 Wizard
Posts: 12195
Joined: 30 Sep 2006, 03:37

Re: Sorting & Limit Amount

30 Mar 2019, 01:28

In X3.27, we replaced a lot of jQuery and prototype functions (which you were using), in favor of more effective native Javascript. This means the previous shuffle function is no longer accessible from external javascript. Here is the replacement:
Code
function x3_load_page(){
  if($('body').hasClass('slug-index')){
    var items = document.getElementsByClassName('item-link');
   if(items.length < 2) return;
  
    // vars
   var copy = Array.from ? Array.from(items) : [].slice.call(items);
  
   // loop create shuffled
   for (var i = 0, l = copy.length; i < l; i++) {
   var random = Math.floor(Math.random() * copy.length);
      $(items[i]).replaceWith($(copy[random]).clone(true));
      copy.splice(random, 1);
    }
  
    // remove leftovers
    var remove_items = $('.item-link:gt(2)');
    remove_items.remove();
  }
}
 
User avatar
Martin
Experienced
Topic Author
Posts: 641
Joined: 30 Jan 2011, 23:24

Re: Sorting & Limit Amount

30 Mar 2019, 03:33

Great!
Thanx a lot... again!
:)
ImageImage