ResponsiveSlides with JSON as DataSource

1

After much searching for a very simple image gallery I ended up finding ResponsiveSlides.js which is not only simple enough, but also works ( smartphones even though it does not recognize gestures for slideshows - but that's another story).

However, like many gallery / slide plugins, ResponsiveSlides works with existing and / or pre-defined HTML markup, and it's just in that I am looking for adaptation or, suddenly, an alternative suggestion because, at least initially, the images used will be hosted in IMGur and consumed through your API.

I've even found an issue in the Github repository of the project of someone with similar intent to mine that was in addition to an initial implementation , but that was not successful either.

And this limitation is poor in terms of performance because it requires that the images that will be part of the gallery are preloaded, making it difficult or even preventing the Lazy Load .

As requested , the part that matters of the current code:

<article id="uCSg1">

    <h3 role="heading"></h3>

    <figure class="cover">
        <img src="http://i.imgur.com/Ik3yGs8.jpg"></figure><sectionclass="permalink">

        <div class="separator"></div>

        <p>Posted on Sunday, 9 December with 1 note.</p>
        <p>Reblog This Post.</p>

    </section>

</article>

This block repeats as many times as many articles as exist on the page. The <article> element has the same ID as the album ID. In this example, the album is this .

The image in the <figure> element is the album cover image, defined in the settings of the album by the IMGUr interface. As this album in question is not mine, I used the very first image.

In JavaScript:

$( document ).ready(function() {

    $( 'article' ).each( function() {

        buildGallery( $( this ) );
    });
});

function buildGallery( article ) {

    $.ajax({

        url: 'https://api.imgur.com/3/album/' + article.attr( 'id' ),
        type: 'get',

        headers: {
            Authorization: 'Client-ID 123456'
        },

        dataType: 'json',

        success: function( response ) {

            if( response.success ) {

                // Monta a galeria/slides
            }
        }
    });
}

The data model used is Album and in that case it produces a response this JSON

  

The IMGUr API requires authentication with an access key that was intentionally forged here. However the registration for new keys is free .

    
asked by anonymous 24.05.2014 / 16:08

1 answer

1

As no one else manifested, I will give my opinion (not an answer, but it does not fit into a comment), if you want I can delete it.

From the repository Github , the author does not support more than 1 year in the library (it seems like it has been abandoned) and has many% open% and% blank%. I do not know if I would use a gallery like this (my opinion,: D).

I found another one, it is much more complete (and complex), there are few open issues (90% of them already closed) and with active development, but it accepts JSON as issues , pull requests support and still works on mobile : link . I do not know if you like it, since a requirement of choice is that it is simple.

As far as I know, it was designed at the beginning of plugins, that is, you do not have to import all DataSource files, it only matters what you want (see: link ).

I have other suggestions:

  • Make lazyload of the library and include this functionality. From what I saw of Gallery , it's pretty simple so just make js to preserve the original code and just add features.
  • If you use a framework (MVVM, MVC, MVW ...), just make fork of your JSON / Template in html (generating source elements), and see a way to update control of gallery by the plugin, something like decorator . In this case you would need to implement bind / reuse at your own expense. Whenever I get an idea of recycling in mind, I think of the algorithm of <figure> of android% ( link ).
  • 27.05.2014 / 14:12