« Return

/* --------------------------------------------------------------
    
    BCDC.US :: Stack jQuery Plugin
    http://bcdc.us

    This Version: 2.0 ( Feb-14-2012 )
    [ history - Version: 1.0 ( Aug-02-2010 ) ]

    Demo :: http://bcdc.us/jquery.plugins/jquery.stack/demo.php
    
-------------------------------------------------------------- */

(function($) {
    $.fn.stack = function(customOptions) {
      
        return this.each(function() {                 
            var options = $.extend({},$.fn.stack.defaultOptions, customOptions);  
            var _this = $(this);

            var jqxhr = $.getJSON("fetch.php", function(data) {
                if ( options.shuffle == true ) {                                     
                    data.sort(function() { return 0.5 - Math.random(); });
                }
                _this.bind('click', function(event) {
                    event.preventDefault();             
                    for (var i = 0; i < options.set; i += 1) {
                        if ( data.length >= 1 ) $('').appendTo('.' + options.element);
                        else _this.text('no more images to load');
                    }
                });
            });
            jqxhr.complete(function(){ _this.click(); });
        });
        
    };

$.fn.stack.defaultOptions = {
    set: 2,               // number of images to append ( load ) per click
    shuffle: false,       // shuffle array ( true :: false )
    element: 'gallery'    // class attribute of the element to which the images are appended
};

})(jQuery);


/* --------------------------------------------------------------    
    The PHP file ( output json )    
-------------------------------------------------------------- */ 
   
<?php
header("Content-type: application/json");

define('_PATH', './images/');
$response  = array_values(array_diff(scandir(_PATH), array('.', '..', '.DS_Store')));

echo json_encode($response);
?>