pinry/static/js/pinry.js
/**
     * Load our pins using the pins template into our UI, be sure to define a
     * offset outside the function to keep a running tally of your location.
     */
Load our pins using the pins template into our UI, be sure to define a
offset outside the function to keep a running tally of your location.
Load our pins using the pins template into our UI be sure to define a offset outside the function to keep a running tally of your location .
function loadPins() {
        $(window).off('scroll');
        $('.spinner').css('display', 'block');
        var apiUrl = '/api/v1/pin/?format=json&order_by=-id&offset='+String(offset);
        if (tagFilter) apiUrl = apiUrl + '&tag=' + tagFilter;
        if (userFilter) apiUrl = apiUrl + '&submitter__username=' + userFilter;
        $.get(apiUrl, function(pins) {
            for (var i=0; i < pins.objects.length; i++) {
                pins.objects[i].editable = (pins.objects[i].submitter.username == currentUser.username);
                pins.objects[i].tags.sort(function (a, b) {
                    return a.toLowerCase().localeCompare(b.toLowerCase());
                });
            }
            var template = Handlebars.compile($('#pins-template').html());
            var html = template({pins: pins.objects});
            $('#pins').append(html);
            tileLayout();
            lightbox();
            $('#pins').ajaxStop(function() {
                $('img').load(function() {
                    $(this).fadeIn(300);
                });
            });
            if (pins.objects.length < apiLimitPerPage) {
                $('.spinner').css('display', 'none');
                if ($('#pins').length !== 0) {
                    var theEnd = document.createElement('div');
                    theEnd.id = 'the-end';
                    $(theEnd).html('<span class="glyphicon glyphicon-heart" aria-hidden="true"></span>');
                    $(theEnd).css('padding', 50);
                    $('body').append(theEnd);
                }
            } else {
                $(window).scroll(scrollHandler);
            }
        });
        offset += apiLimitPerPage;
    }
function loadPins ( ) { $ ( window ) . off ( 'scroll' ) ; $ ( '.spinner' ) . css ( 'display' , 'block' ) ; var apiUrl = '/api/v1/pin/?format=json&order_by=-id&offset=' + String ( offset ) ; if ( tagFilter ) apiUrl = apiUrl + '&tag=' + tagFilter ; if ( userFilter ) apiUrl = apiUrl + '&submitter__username=' + userFilter ; $ . get ( apiUrl , function ( pins ) { for ( var i = 0 ; i < pins . objects . length ; i ++ ) { pins . objects [ i ] . editable = ( pins . objects [ i ] . submitter . username == currentUser . username ) ; pins . objects [ i ] . tags . sort ( function ( a , b ) { return a . toLowerCase ( ) . localeCompare ( b . toLowerCase ( ) ) ; } ) ; } var template = Handlebars . compile ( $ ( '#pins-template' ) . html ( ) ) ; var html = template ( { pins : pins . objects } ) ; $ ( '#pins' ) . append ( html ) ; tileLayout ( ) ; lightbox ( ) ; $ ( '#pins' ) . ajaxStop ( function ( ) { $ ( 'img' ) . load ( function ( ) { $ ( this ) . fadeIn ( 300 ) ; } ) ; } ) ; if ( pins . objects . length < apiLimitPerPage ) { $ ( '.spinner' ) . css ( 'display' , 'none' ) ; if ( $ ( '#pins' ) . length !== 0 ) { var theEnd = document . createElement ( 'div' ) ; theEnd . id = 'the-end' ; $ ( theEnd ) . html ( '<span class="glyphicon glyphicon-heart" aria-hidden="true"></span>' ) ; $ ( theEnd ) . css ( 'padding' , 50 ) ; $ ( 'body' ) . append ( theEnd ) ; } } else { $ ( window ) . scroll ( scrollHandler ) ; } } ) ; offset += apiLimitPerPage ; }
Load our pins using the pins template into our UI, be sure to define a
 offset outside the function to keep a running tally of your location.
Load our pins using the pins template into our UI be sure to define a offset outside the function to keep a running tally of your location .
// Disable scroll // Show our loading symbol // Fetch our pins from the api using our current offset // Set which items are editable by the current user // Use the fetched pins as our context for our pins template // Append the newly compiled data to our container // We need to then wait for images to load in and then tile // Up our offset, it's currently defined as 50 in our settings